Backoff (PlugAMQP v0.6.0) View Source
Functions to decrease the rate of some process.
A Backoff algorithm is commonly used to space out repeated retransmissions of the same block of data, avoiding congestion.
This module provides a data structure, Backoff, that holds the state
and the configuration of the backoff algorithm. Then, we can use function
step/1
to get the time to wait for repeating a process and a new state of
the backoff algorithm.
Example
iex> backoff = Backoff.new(kind: :exp)
#Backoff<kind: exp, min: 200, max: 15000>
iex> {200, next_backoff} = Backoff.step(backoff)
iex> {400, _next_backoff} = Backoff.step(next_backoff)
Link to this section Summary
Types
A Backoff state.
Link to this section Types
Specs
kind() :: :rand | :exp | :rand_exp
The implementation used to provide the Backoff behaviour.
There are different ways to provide Backoff behaviour:
rand
: on every step, the delay time is computed randomly between two values, min and max.exp
: every step the delay is increased exponentially.rand_exp
: a combination of the previous two.
Specs
option() :: {:kind, kind()} | {:min, non_neg_integer()} | {:max, non_neg_integer()}
Available options to configure a Backoff.
kind
: the implementation to be used. Can be any of the availablekind/0
s. Defaults torand_exp
.min
: the minimum value that can return a Backoff. Defaults to 200.max
: the maximum value that can return a Backoff. Defaults to 15000.
Specs
options() :: [option()]
A list of option/0
.
Specs
t()
A Backoff state.
An opaque data structure that holds the state and the configuration of a
Backoff algorithm. Can be created with new/0
or new/1
.
Link to this section Functions
Specs
Creates a new Backoff.
Specs
Sets a Backoff to the initial state.
Given a Backoff, sets its state back to the initial value. Note that for
rand
implementation this functions has no effect.
Specs
step(t()) :: {non_neg_integer(), t()}
Computes the current delay.
Given a Backoff, returns the current delay time a next state of the current Backoff.