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
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
Factor
The exponential multiplier, when applicable.
public virtual double? Factor { get; }
Property Value
Jitter
The jitter mode for built-in backoffs, when applicable.
public virtual Jitter? Jitter { get; }
Property Value
Kind
The stable category of this backoff.
public abstract BackoffKind Kind { get; }
Property Value
MaxDelay
The linear or exponential delay cap, when configured.
public virtual TimeSpan? MaxDelay { get; }
Property Value
None
No delay between attempts.
public static Backoff None { get; }
Property Value
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
Returns
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
Returns
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
Returns
GetDelay(int)
Returns the delay before the given 1-based retry attempt.
public abstract TimeSpan GetDelay(int attempt)
Parameters
attemptint
Returns
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
Returns
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)