Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DecorrelatedJitterBackoffV2 without exponential side #35

Open
andremantaswow opened this issue Jul 3, 2024 · 0 comments
Open

DecorrelatedJitterBackoffV2 without exponential side #35

andremantaswow opened this issue Jul 3, 2024 · 0 comments

Comments

@andremantaswow
Copy link

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant