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

Add jitter to constant backoff #47

Merged
merged 1 commit into from
Feb 25, 2023
Merged

Add jitter to constant backoff #47

merged 1 commit into from
Feb 25, 2023

Conversation

balroggg
Copy link
Contributor

@balroggg balroggg commented Feb 24, 2023

  • add jitter to ConstantBackoff
  • change rand to fastrand
  • change futures to futures-core

Fix #37

@balroggg
Copy link
Contributor Author

Change dependencies to reduce compilation time a little. Fell free to ask revert some changes.


let dur = it.next().unwrap();
fastrand::seed(7);
assert!(dur > Duration::from_secs(1));
Copy link
Contributor Author

Choose a reason for hiding this comment

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

It's hard to test random things, this should be something like delay <= dur < delay + rng

Copy link
Owner

Choose a reason for hiding this comment

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

Are you willing to start a new PR for this?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Maybe for unit test is enough. I will try to find a better solution, but I'm not sure.

@@ -96,14 +107,18 @@ impl Iterator for ConstantBackoff {
type Item = Duration;

fn next(&mut self) -> Option<Self::Item> {
let delay = || match self.jitter {
true => self.delay + self.delay.mul_f32(fastrand::f32()),
Copy link
Contributor Author

Choose a reason for hiding this comment

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

In default case it's a little strange to set delay(1s) + jitter(1s in some cases), so double the main delay. But maybe it's ok.

Copy link
Owner

Choose a reason for hiding this comment

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

We can add jitter range for user in the future, let's merge first.

Copy link
Owner

@Xuanwo Xuanwo left a comment

Choose a reason for hiding this comment

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

Great!

@Xuanwo
Copy link
Owner

Xuanwo commented Feb 25, 2023

Thanks a lot!

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.

Add jitter support for constant back off
2 participants