backoff

package module
v0.0.0-...-1e0ab68 Latest Latest
Warning

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

Go to latest
Published: Mar 12, 2020 License: MIT Imports: 3 Imported by: 0

README

backoff

Build Status Go Report Card GoDoc GitHub license gocover.io

License

Pouch is licensed under the MIT License. See LICENSE for the full license text.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Constant

type Constant struct {
	// Delay is the amount of time to backoff after.
	Delay time.Duration
}

Constant implements the defined constant compensation algorithm.

func (*Constant) BackOff

func (c *Constant) BackOff(retries uint) time.Duration

BackOff returns the amount of time to wait before the next retry given the number of retries.

type Exponential

type Exponential struct {
	// BaseDelay is the amount of time to backoff after the first failure.
	BaseDelay time.Duration
	// Multiplier is the factor that exponentially multiplies the backoff after a retry failure.
	Multiplier float64
	// MaxDelay is the upper bound of backoff delay.
	MaxDelay time.Duration
}

Exponential implements the defined exponential compensation algorithm.

func (*Exponential) BackOff

func (e *Exponential) BackOff(retries uint) time.Duration

BackOff returns the amount of time to wait before the next retry given the number of retries.

type Jitter

type Jitter struct {
	// Jitter is the randomized backoff of jitter
	Jitter time.Duration
	// Rand is make random numbers for jitter
	Rand RandFloat64
}

Jitter implements the randomize backoff delays so that if a cluster of requests start at the same time, they won't operate in lockstep.

func (*Jitter) BackOff

func (j *Jitter) BackOff(retries uint) time.Duration

BackOff returns the amount of time to wait before the next retry given the number of retries.

type Linear

type Linear struct {
	// BaseDelay is the amount of time to backoff after.
	BaseDelay time.Duration
	// Multiplier is the factor with which to multiply backoffs after a failed retry.
	Multiplier float64
	// MaxDelay is the upper bound of backoff delay.
	MaxDelay time.Duration
}

Linear implements the defined linear compensation algorithm.

func (*Linear) BackOff

func (l *Linear) BackOff(retries uint) time.Duration

BackOff returns the amount of time to wait before the next retry given the number of retries.

type RandFloat64

type RandFloat64 interface {
	// Float64 returns, as a float64, a pseudo-random number in [0.0,1.0).
	Float64() float64
}

RandFloat64 defines the methodology for jitter.

type Strategy

type Strategy interface {
	// BackOff returns the amount of time to wait before the next retry given the number of consecutive failures.
	BackOff(retries uint) time.Duration
}

Strategy defines the methodology for backing off after.

var DefaultConstant Strategy = &Superposition{
	defaultJitter,
	&Constant{
		Delay: 1 * time.Second,
	},
}
var DefaultExponential Strategy = &Superposition{
	defaultJitter,
	&Exponential{
		BaseDelay:  1 * time.Second,
		Multiplier: 1.6,
		MaxDelay:   120 * time.Second,
	},
}
var DefaultLinear Strategy = &Superposition{
	defaultJitter,
	&Linear{
		BaseDelay:  1 * time.Second,
		Multiplier: 2,
		MaxDelay:   120 * time.Second,
	},
}

type Superposition

type Superposition []Strategy

func (*Superposition) BackOff

func (s *Superposition) BackOff(retries uint) time.Duration

BackOff returns the amount of time to wait before the next retry given the number of retries.

Jump to

Keyboard shortcuts

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