Documentation ¶
Overview ¶
Package backoff implements exponential backoff mechanism based on gRPC's backoff algorithm https://github.com/grpc/grpc/blob/master/doc/connection-backoff.md
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Exponential ¶
type Exponential struct { // BaseDelay is the minimum delay for the first attempt. BaseDelay time.Duration // MaxDelay is the upper limit for exponential backoff. MaxDelay time.Duration // Multiplier is the factor determining "how fast" the delay increases after each retry. Multiplier float64 // Jitter defines the maximum of randomized duration added to the delay of each step. This // randomization prevents all actors retry at the same time. Jitter time.Duration }
Exponential defines an exponential backoff strategy. It multiplicatively decreases the rate of retrial by increasing the wait time. The wait time is calculated to following: Backoff(retries) = BaseDelay * (Multiplier ^ retries) + rand(0, Jitter) The backoff time can never exceed the MaxDelay.
func NewDefaultExponential ¶
func NewDefaultExponential() *Exponential
NewDefaultExponential returns an exponential backoff strategy using a set of configurations good enough for network connection retry.
func (*Exponential) Backoff ¶
func (e *Exponential) Backoff(retries uint) time.Duration
Backoff returns the duration to wait before retry again. The caller is fully responsible for retry controlling retry attempts and timers. Typically, the caller increases the retry attempt and creates a timer from the result of this method. Typically, this method is called before increasing the attempt of the caller, which is Backoff(0). It means the backoff time after the first failure.