Class ExponentialBackOff (1.69.0)

public class ExponentialBackOff : IBackOff

Implementation of IBackOff that increases the back-off period for each retry attempt using a randomization function that grows exponentially. In addition, it also adds a randomize number of milliseconds for each attempt.

Inheritance

object > ExponentialBackOff

Implements

IBackOff

Namespace

Google.Apis.Util

Assembly

Google.Apis.Core.dll

Constructors

ExponentialBackOff()

public ExponentialBackOff()

Constructs a new exponential back-off with DeltaBackOff set to 250ms and MaxNumOfRetries set to 10.

ExponentialBackOff(TimeSpan, int)

public ExponentialBackOff(TimeSpan deltaBackOff, int maximumNumOfRetries = 10)

Constructs a new exponential back-off with the given delta and maximum retries. If unspecified, maximumNumOfRetries is set to 10.

Parameters
Name Description
deltaBackOff TimeSpan
maximumNumOfRetries int

Properties

DeltaBackOff

public TimeSpan DeltaBackOff { get; }

Time span used to bound the back-off jitter. If the value is Zero then the generated back-off will be exactly 1, 2, 4, 8, 16, etc. seconds. A valid value is between zero and one second. The default value is 250ms, which means that the generated back-off will be between 0.75sec and 1.25sec, 1.75sec and 2.25sec, 3.75sec and 4.25sec, and so on. Only one of DeltaBackOff and DeltaBackOffPercent may be specified. Both may be zero, in which case no jitter will be applied.

Property Value
Type Description
TimeSpan

DeltaBackOffPercent

public short DeltaBackOffPercent { get; }

Percent of the current unjittered back-off used to bound the jitter. If the value is set to 10, and the current back-off is 1000ms, then the jitter will be generated from -100ms to 100ms and the jittered back-off will be from 900ms to 1100ms. Only one of DeltaBackOff and DeltaBackOffPercent may be specified. Both may be zero, in which case no jitter will be applied.

Property Value
Type Description
short

MaxNumOfRetries

public int MaxNumOfRetries { get; }

The maximum number of retries. Default value is 10.

Property Value
Type Description
int

Methods

FromDeltaBackOffPercent(short, int)

public static ExponentialBackOff FromDeltaBackOffPercent(short deltaBackOffPercent, int maximumNumOfRetries = 10)

Constructs a new exponential back-off with the given delta percent and maximum retries. If unspecified, maximumNumOfRetries is set to 10.

Parameters
Name Description
deltaBackOffPercent short
maximumNumOfRetries int
Returns
Type Description
ExponentialBackOff

GetNextBackOff(int)

public TimeSpan GetNextBackOff(int currentRetry)

Gets the a time span to wait before next retry. If the current retry reached the maximum number of retries, the returned value is MinValue.

Parameter
Name Description
currentRetry int
Returns
Type Description
TimeSpan

Extension Method