PlugAMQP v0.5.0 Backoff 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
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.
Link to this type
option()
View Sourceoption() :: {: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.
A list of option/0
.
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
.