-
-
Notifications
You must be signed in to change notification settings - Fork 33
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
Conversation
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)); |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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()), |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great!
Thanks a lot! |
ConstantBackoff
rand
tofastrand
futures
tofutures-core
Fix #37