Skip to content
This repository has been archived by the owner on Nov 17, 2023. It is now read-only.

Add a Jitter strategy to the Retry policy #188

Closed
CESARDELATORRE opened this issue May 5, 2017 · 2 comments
Closed

Add a Jitter strategy to the Retry policy #188

CESARDELATORRE opened this issue May 5, 2017 · 2 comments

Comments

@CESARDELATORRE
Copy link
Collaborator

We might want to add a Jitter strategy to the Retry policy.
Related to this issue I opened into Polly's repo, although it could be implemented easily, too:
App-vNext/Polly#245

Basically, a regular Retry policy can impact your system in cases of high concurrency and scalability and under high contention.
Would be great to have it Polly and not very complicated to add Jitter to the retry algorithm/poilicy.
It'd improve the overall performance to the end-to-end system by adding randomness to the exponential backoff. It'd spread out the spikes when issues arise.

The problem is explained here:
https://brooker.co.za/blog/2015/03/21/backoff.html
https://www.awsarchitectureblog.com/2015/03/backoff.html

As suggested by @reisenberger, it could already be achieved with Polly, by using one of the .WaitAndRetry(...) configuration overloads which allow you to specify a Func<..., TimeSpan> for the amount of wait. (Similar overloads exist for async.)

We could implement something like:

Random jitterer = new Random(); 
Policy
  .Handle<HttpResponseException>() // etc
  .WaitAndRetry(5,  
      retryAttempt => TimeSpan.FromSeconds(Math.Pow(2, retryAttempt))  // exponential back-off
                    + TimeSpan.FromMilliseconds(jitterer.Next(0, 100)) // plus some jitter
  );

The principle of how to do this with Polly is the same: using the Func<..., Timespan> overloads, you have complete control to adopt whatever randomness/jitter algorithm you like.
It might get improved further in future versions of Polly, according to reisenberger.

@reisenberger
Copy link

Added sketch for the 'Decorrelated Jitter' suggested by the referenced article.

@mvelosop
Copy link
Collaborator

Closed as it was included in the Roadmap (vNext).

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

No branches or pull requests

4 participants