Documentation ¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func CalculateDuration ¶
func CalculateDuration(min, max time.Duration, factor float64, jitter bool, failures int) time.Duration
CalculateDuration calculates the backoff duration based on minimum base interval, exponential factor, jitter and number of failures.
func ClusterSizeDependantInterval ¶ added in v1.14.0
ClusterSizeDependantInterval returns a time.Duration that is dependent on the cluster size, i.e. the number of nodes that have been discovered. This can be used to control sync intervals of shared or centralized resources to avoid overloading these resources as the cluster grows.
Example sync interval with baseInterval = 1 * time.Minute
nodes | sync interval ------+----------------- 1 | 41.588830833s 2 | 1m05.916737320s 4 | 1m36.566274746s 8 | 2m11.833474640s 16 | 2m49.992800643s 32 | 3m29.790453687s 64 | 4m10.463236193s 128 | 4m51.588744261s 256 | 5m32.944565093s 512 | 6m14.416550710s 1024 | 6m55.946873494s 2048 | 7m37.506428894s 4096 | 8m19.080616652s 8192 | 9m00.662124608s 16384 | 9m42.247293667s
Types ¶
type Exponential ¶
type Exponential struct { // Min is the minimal backoff time, if unspecified, 1 second will be // used Min time.Duration // Max is the maximum backoff time, if unspecified, no maximum time is // applied Max time.Duration // Factor is the factor the backoff time grows exponentially, if // unspecified, a factor of 2.0 will be used Factor float64 // Jitter, when enabled, adds random jitter to the interval Jitter bool // NodeManager enables the use of cluster size dependent backoff // intervals, i.e. the larger the cluster, the longer the backoff // interval NodeManager NodeManager // Name is a free form string describing the operation subject to the // backoff, if unspecified, a UUID is generated. This string is used // for logging purposes. Name string // ResetAfter will reset the exponential back-off if no attempt is made for the amount of time specified here. // Needs to be larger than the Max duration, otherwise it will be ignored to avoid accidental resets. // If unspecified, no reset is performed. ResetAfter time.Duration // contains filtered or unexported fields }
Exponential implements an exponential backoff
func (*Exponential) Duration ¶
func (b *Exponential) Duration(attempt int) time.Duration
Duration returns the wait duration for the nth attempt
func (*Exponential) Reset ¶ added in v1.14.0
func (b *Exponential) Reset()
Reset backoff attempt counter
type NodeManager ¶
type NodeManager interface {
ClusterSizeDependantInterval(baseInterval time.Duration) time.Duration
}
NodeManager is the interface required to implement cluster size dependent intervals
func NewNodeManager ¶ added in v1.14.0
func NewNodeManager(clusterSizeDependantInterval func(baseInterval time.Duration) time.Duration) NodeManager
NewNodeManager returns a new NodeManager implementing cluster size dependent intervals based on the given function. If the function is nil, then no tuning is performed.