Class Backoff

Namespace
Kevlar
Assembly
Kevlar.dll

Computes the delay before each retry attempt. Create instances through the static factories.

public abstract class Backoff
Inheritance
Backoff
Inherited Members

Properties

BaseDelay

The constant delay, linear step, or exponential base delay, when applicable.

public virtual TimeSpan? BaseDelay { get; }

Property Value

TimeSpan?

Default

Kevlar's default: exponential backoff starting at 250ms with a factor of 2, equal jitter, capped at 30 seconds.

public static Backoff Default { get; }

Property Value

Backoff

Factor

The exponential multiplier, when applicable.

public virtual double? Factor { get; }

Property Value

double?

Jitter

The jitter mode for built-in backoffs, when applicable.

public virtual Jitter? Jitter { get; }

Property Value

Jitter?

Kind

The stable category of this backoff.

public abstract BackoffKind Kind { get; }

Property Value

BackoffKind

MaxDelay

The linear or exponential delay cap, when configured.

public virtual TimeSpan? MaxDelay { get; }

Property Value

TimeSpan?

None

No delay between attempts.

public static Backoff None { get; }

Property Value

Backoff

Methods

Constant(TimeSpan, Jitter)

The same base delay before every attempt, with optional jitter.

public static Backoff Constant(TimeSpan delay, Jitter jitter = Jitter.None)

Parameters

delay TimeSpan
jitter Jitter

Returns

Backoff

Custom(Func<int, TimeSpan>)

A caller-supplied delay function receiving the 1-based retry attempt number.

public static Backoff Custom(Func<int, TimeSpan> delayFactory)

Parameters

delayFactory Func<int, TimeSpan>

Returns

Backoff

Remarks

The returned delay is clamped rather than trusted: a negative delay becomes Zero and anything above the runtime timer limit (uint.MaxValue - 1 milliseconds, roughly 49 days) becomes that limit. A retry's own MaxDelay then caps what is left, so an arithmetic slip in delayFactory cannot wedge a pipeline on a delay it can never wait out.

Exponential(TimeSpan, double, TimeSpan?, Jitter)

Exponentially increasing delay: baseDelay, then multiplied by factor after each attempt. The default equal jitter scales each delay by a random factor in [0.5, 1.5) to avoid synchronized retry storms. Decorrelated jitter instead selects each delay between the base delay and three times the preceding delay.

public static Backoff Exponential(TimeSpan baseDelay, double factor = 2, TimeSpan? maxDelay = null, Jitter jitter = Jitter.Equal)

Parameters

baseDelay TimeSpan
factor double
maxDelay TimeSpan?
jitter Jitter

Returns

Backoff

GetDelay(int)

Returns the delay before the given 1-based retry attempt.

public abstract TimeSpan GetDelay(int attempt)

Parameters

attempt int

Returns

TimeSpan

GetDelay(int, TimeSpan)

Returns the delay before the given retry attempt, using the preceding effective delay for stateful jitter modes. Pass Zero for the first decorrelated draw.

public virtual TimeSpan GetDelay(int attempt, TimeSpan previousDelay)

Parameters

attempt int
previousDelay TimeSpan

Returns

TimeSpan

Linear(TimeSpan, TimeSpan?, Jitter)

Linearly increasing base delay: step, 2×step, 3×step…, with optional jitter.

public static Backoff Linear(TimeSpan step, TimeSpan? maxDelay = null, Jitter jitter = Jitter.None)

Parameters

step TimeSpan
maxDelay TimeSpan?
jitter Jitter

Returns

Backoff