[][src]Crate backoff

ExponentialBackoff is a backoff implementation that increases the backoff period for each retry attempt using a randomization function that grows exponentially.

next_backoff is calculated using the following formula:

This example is not tested
  randomized interval =
      retry_interval * (random value in range [1 - randomization_factor, 1 + randomization_factor])

In other words next_backoff will range between the randomization factor percentage below and above the retry interval.

For example, given the following parameters:

This example is not tested
retry_interval = 2
randomization_factor = 0.5
multiplier = 2

the actual backoff period used in the next retry attempt will range between 1 and 3 seconds, multiplied by the exponential, that is, between 2 and 6 seconds.

Note: max_interval caps the retry_interval and not the randomized interval.

If the time elapsed since an ExponentialBackoff instance is created goes past the max_elapsed_time, then the method next_backoff starts returning None.

The elapsed time can be reset by calling reset.

Example: Given the following default arguments, for 10 tries the sequence will be, and assuming we go over the max_elapsed_time on the 10th try:

Request # retry_interval (seconds) Randomized Interval (seconds)
1 0.5 [0.25, 0.75]
2 0.75 [0.375, 1.125]
3 1.125 [0.562, 1.687]
4 1.687 [0.8435, 2.53]
5 2.53 [1.265, 3.795]
6 3.795 [1.897, 5.692]
7 5.692 [2.846, 8.538]
8 8.538 [4.269, 12.807]
9 12.807 [6.403, 19.210]
10 19.210 None

Modules

backoff
default

Constants for the exponential backoff policy.

exponential

Structs

SystemClock

SystemClock uses the system's clock to get the current time. This Clock should be used for real use-cases.

Enums

Error

Error is the error value in an operation's result.

Traits

Clock

Clock returns the current time.

Notify

Notify is called in retry_notify in case of errors.

Operation

Operation is an operation that can be retried if it fails.

Type Definitions

ExponentialBackoff

Exponential backoff policy with system's clock.