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

feat(async): add jitter to retry exponential backoff #3379

Merged
merged 3 commits into from
May 20, 2023

Conversation

lionel-rowe
Copy link
Contributor

Fixes #3378

@lino-levan
Copy link
Contributor

I'm pretty strongly -1 against complicating the API to allow for arbitrary backoff functions. When I made the PR to introduce async/retry, I made a conscious decision to not do that (because outside of exponential backoff, what algorithm would you need?). I chose not to add jitter at the time because I didn't understand what the use case was but I think you did a good job in #3378 explaining why it might be useful.

TLDR; I think adding an option for jitter would be fine, but please don't overcomplicate the API with backoff functions.

@lino-levan
Copy link
Contributor

I never thought about making jitter enabled by default but honestly that makes sense (plus it removes an option which is always nice). Thoughts @iuioiua?

@lionel-rowe
Copy link
Contributor Author

I never thought about making jitter enabled by default but honestly that makes sense (plus it removes an option which is always nice). Thoughts @iuioiua?

Ah I thought that was what you meant, but re-reading your post I see I misunderstood.

Pros of always using jitter:

  1. Likely to significantly decrease number of failed API calls (especially those due to 429 Too Many Requests) in real-world scenarios
  2. Likely to significantly decrease time-to-completion in real-world scenarios, mainly as a result of 1, but also because the average time between calls is spaced closer together
  3. API remains completely unchanged

Pros of having an option for jitter, disabled by default:

  1. Default behavior remains completely unchanged
  2. More deterministic... sort of? I'm not sure whether an unknown power of m between x and y is meaningfully more deterministic than a completely random number between x and y here. Is there any reason a consumer would specifically want the number of seconds between each retry to be a power of 2?

Pros of having an option for jitter, enabled by default:

  1. Gives the most-likely preferred behavior as default but allows opt-in to the old behavior

async/retry.ts Outdated Show resolved Hide resolved
async/retry_test.ts Outdated Show resolved Hide resolved
Copy link
Member

@kt3k kt3k left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. Nice!

@kt3k kt3k merged commit 9daac32 into denoland:main May 20, 2023
@bodograumann bodograumann mentioned this pull request Jun 6, 2023
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

Successfully merging this pull request may close these issues.

async/retry.ts doesn't allow applying jitter to exponential backoff
3 participants