Class RetrySettings
Settings for retrying RPCs.
Inheritance
Inherited Members
Namespace: Google.Api.Gax.Grpc
Assembly: Google.Api.Gax.Grpc.dll
Syntax
public sealed class RetrySettings
Properties
BackoffJitter
The delay jitter to apply for delays, defaulting to RandomJitter. This is never null.
Declaration
public RetrySettings.IJitter BackoffJitter { get; }
Property Value
Type | Description |
---|---|
RetrySettings.IJitter |
Remarks
"Jitter" is used to introduce randomness into the pattern of delays. This is to avoid multiple clients performing the same delay pattern starting at the same point in time, leading to higher-than-necessary contention. The default jitter simply takes each maximum delay and returns an actual delay which is a uniformly random value between 0 and the maximum. This is good enough for most applications, but makes precise testing difficult.
BackoffMultiplier
The multiplier to apply to the backoff on each iteration; always greater than or equal to 1.0.
Declaration
public double BackoffMultiplier { get; }
Property Value
Type | Description |
---|---|
System.Double |
Remarks
As an example, a multiplier of 2.0 with an initial backoff of 0.1s on an RPC would then apply a backoff of 0.2s, then 0.4s until it is capped by MaxBackoff.
InitialBackoff
The backoff time between the first attempt and the first retry. Always non-negative.
Declaration
public TimeSpan InitialBackoff { get; }
Property Value
Type | Description |
---|---|
System.TimeSpan |
MaxAttempts
The maximum number of attempts to make. Always greater than or equal to 1.
Declaration
public int MaxAttempts { get; }
Property Value
Type | Description |
---|---|
System.Int32 |
MaxBackoff
The maximum backoff time between retries. Always non-negative.
Declaration
public TimeSpan MaxBackoff { get; }
Property Value
Type | Description |
---|---|
System.TimeSpan |
NoJitter
A jitter which simply returns the specified maximum delay.
Declaration
public static RetrySettings.IJitter NoJitter { get; }
Property Value
Type | Description |
---|---|
RetrySettings.IJitter |
RandomJitter
The default jitter which returns a uniformly distributed random delay between 0 and the specified maximum.
Declaration
public static RetrySettings.IJitter RandomJitter { get; }
Property Value
Type | Description |
---|---|
RetrySettings.IJitter |
RetryFilter
A predicate to determine whether or not a particular exception should cause the operation to be retried. Usually this is simply a matter of checking the status codes. This is never null.
Declaration
public Predicate<Exception> RetryFilter { get; }
Property Value
Type | Description |
---|---|
System.Predicate<System.Exception> |
Methods
FilterForStatusCodes(StatusCode[])
Creates a retry filter based on status codes.
Declaration
public static Predicate<Exception> FilterForStatusCodes(params StatusCode[] statusCodes)
Parameters
Type | Name | Description |
---|---|---|
StatusCode[] | statusCodes | The status codes to retry. Must not be null. |
Returns
Type | Description |
---|---|
System.Predicate<System.Exception> | A retry filter based on status codes. |
FilterForStatusCodes(IEnumerable<StatusCode>)
Creates a retry filter based on status codes.
Declaration
public static Predicate<Exception> FilterForStatusCodes(IEnumerable<StatusCode> statusCodes)
Parameters
Type | Name | Description |
---|---|---|
System.Collections.Generic.IEnumerable<StatusCode> | statusCodes | The status codes to retry. Must not be null. |
Returns
Type | Description |
---|---|
System.Predicate<System.Exception> | A retry filter based on status codes. |
FromConstantBackoff(Int32, TimeSpan, Predicate<Exception>, RetrySettings.IJitter)
Returns a RetrySettings using the specified maximum number of attempts and a constant backoff.
Jitter is still applied to each backoff, but the "base" value of the backoff is always backoff
.
Declaration
public static RetrySettings FromConstantBackoff(int maxAttempts, TimeSpan backoff, Predicate<Exception> retryFilter, RetrySettings.IJitter backoffJitter = null)
Parameters
Type | Name | Description |
---|---|---|
System.Int32 | maxAttempts | The maximum number of attempts to make. Must be positive. |
System.TimeSpan | backoff | The backoff after each failure. Must be non-negative. |
System.Predicate<System.Exception> | retryFilter | The predicate to use to check whether an error should be retried. Must not be null. |
RetrySettings.IJitter | backoffJitter | The jitter to use on each backoff. May be null, in which case RandomJitter is used. |
Returns
Type | Description |
---|---|
RetrySettings | A retry with constant backoff. |
FromExponentialBackoff(Int32, TimeSpan, TimeSpan, Double, Predicate<Exception>, RetrySettings.IJitter)
Returns a RetrySettings using the specified maximum number of attempts and an exponential backoff.
Declaration
public static RetrySettings FromExponentialBackoff(int maxAttempts, TimeSpan initialBackoff, TimeSpan maxBackoff, double backoffMultiplier, Predicate<Exception> retryFilter, RetrySettings.IJitter backoffJitter = null)
Parameters
Type | Name | Description |
---|---|---|
System.Int32 | maxAttempts | The maximum number of attempts to make. Must be positive. |
System.TimeSpan | initialBackoff | The backoff after the initial failure. Must be non-negative. |
System.TimeSpan | maxBackoff | The maximum backoff. Must be at least |
System.Double | backoffMultiplier | The multiplier to apply to backoff times. Must be at least 1.0. |
System.Predicate<System.Exception> | retryFilter | The predicate to use to check whether an error should be retried. Must not be null. |
RetrySettings.IJitter | backoffJitter | The jitter to use on each backoff. May be null, in which case RandomJitter is used. |
Returns
Type | Description |
---|---|
RetrySettings | A retry with exponential backoff. |
NextBackoff(TimeSpan)
Works out the next backoff from the current one, based on the multiplier and maximum.
Declaration
public TimeSpan NextBackoff(TimeSpan currentBackoff)
Parameters
Type | Name | Description |
---|---|---|
System.TimeSpan | currentBackoff | The current backoff to use as a basis for the next one. |
Returns
Type | Description |
---|---|
System.TimeSpan | The next backoff to use, which is always at least InitialBackoff and at most MaxBackoff. |