Skip to content

DecorrelatedJitterBackoffV2 without exponential side #35

@andremantaswow

Description

@andremantaswow

Is your feature request related to a specific problem? Or an existing feature? Please describe.

Similar to existing feature.

Describe your proposed or preferred solution:

Expose a new backoff strategy, in this package, similar to Backoff.DecorrelatedJitterV2.cs but that does not include the exponential aspect in the returned sleep durations.

Describe any alternative options you've considered:

A naive implementation:

public static IEnumerable<TimeSpan> ConstantJitterBackoff(TimeSpan averageDelay, int retryCount, double jitterFactor = 0.5)
{
    for (var i = 0; i < retryCount; i++)
    {
        // Calculate random jitter
        var jitter = ((Random.Shared.NextDouble() * 2) - 1) * jitterFactor;

        // Apply jitter factor to the averageDelay
        var delayWithJitter = TimeSpan.FromTicks((long)(averageDelay.Ticks * (1 + jitter)));

        yield return delayWithJitter;
    }
}

Any additional info?

This would be useful for scenarios where we want to retry with some randomness but always around a specific interval.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions