backoff

package
v0.0.0-...-64decf6 Latest Latest
Warning

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

Go to latest
Published: Nov 7, 2024 License: Apache-2.0 Imports: 4 Imported by: 1

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Backoff

type Backoff struct {

	// Factor is the multiplying factor for each increment step
	Factor float64

	// Jitter eases contention by randomizing backoff steps
	Jitter bool

	// Min and Max are the minimum and maximum values of the counter
	Min, Max time.Duration
	// contains filtered or unexported fields
}

Backoff is an exponential counter, it starts from `Min` duration, and after every call to `Duration` method the duration will be multiplied by `Factor`, but it never exceeds `Max`. Backoff is not thread-safe.

func NewBackoff

func NewBackoff(factor float64, jitter bool, minTime, maxTime time.Duration) (*Backoff, error)

NewBackoff creates a new backoff instance.

func (*Backoff) BoundaryForward

func (b *Backoff) BoundaryForward()

BoundaryForward checks whether `Current` reaches `Max` duration, if not then increases the cwnd counter, else does nothing.

func (*Backoff) Current

func (b *Backoff) Current() time.Duration

Current returns the duration for the current cwnd, but doesn't increase the cwnd counter.

func (*Backoff) Duration

func (b *Backoff) Duration() time.Duration

Duration returns the duration for the current cwnd and increases the cwnd counter.

func (*Backoff) Forward

func (b *Backoff) Forward()

Forward increases the cwnd counter.

func (*Backoff) Reset

func (b *Backoff) Reset()

Reset restarts the current cwnd counter to zero.

func (*Backoff) Rollback

func (b *Backoff) Rollback()

Rollback try to decrease cwnd by one if it is greater or equal than one. This is used for we have a long enough duration without backoff try.

Jump to

Keyboard shortcuts

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