backoff

package
v16.10.6 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 21, 2024 License: MIT Imports: 3 Imported by: 0

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
	// contains filtered or unexported fields
}

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(r *rand.Rand) *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.

type Strategy

type Strategy interface {
	Backoff(retries uint) time.Duration
}

Strategy implements a backoff strategy. This strategy has a single Backoff method that returns a time duration corresponding to the input retries.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL