Skip to content

Commit

Permalink
chore: remove jitter
Browse files Browse the repository at this point in the history
Signed-off-by: iGxnon <igxnon@gmail.com>
  • Loading branch information
iGxnon committed Dec 29, 2023
1 parent 0360b59 commit f43bb5f
Showing 1 changed file with 2 additions and 13 deletions.
15 changes: 2 additions & 13 deletions curp/src/client_new/retry.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,6 @@ pub(super) struct RetryConfig {
delay: Duration,
/// Retry count
count: usize,
/// Enable jitter to randomize the delay to avoid thundering herd
jitter: bool,
}

/// Backoff tool
Expand All @@ -55,24 +53,22 @@ struct Backoff {

impl RetryConfig {
/// Create a fixed retry config
fn new_fixed(delay: Duration, count: usize, jitter: bool) -> Self {
fn new_fixed(delay: Duration, count: usize) -> Self {
assert!(count > 0, "retry count should be larger than 0");
Self {
backoff: BackoffConfig::Fixed,
delay,
count,
jitter,
}
}

Check warning on line 63 in curp/src/client_new/retry.rs

View check run for this annotation

Codecov / codecov/patch

curp/src/client_new/retry.rs#L56-L63

Added lines #L56 - L63 were not covered by tests

/// Create a exponential retry config
fn new_exponential(delay: Duration, max_delay: Duration, count: usize, jitter: bool) -> Self {
fn new_exponential(delay: Duration, max_delay: Duration, count: usize) -> Self {
assert!(count > 0, "retry count should be larger than 0");
Self {
backoff: BackoffConfig::Exponential { max_delay },
delay,
count,
jitter,
}
}

Check warning on line 73 in curp/src/client_new/retry.rs

View check run for this annotation

Codecov / codecov/patch

curp/src/client_new/retry.rs#L66-L73

Added lines #L66 - L73 were not covered by tests

Expand Down Expand Up @@ -101,13 +97,6 @@ impl Backoff {
.unwrap_or(self.cur_delay)
.min(max_delay);
}
#[allow(clippy::float_arithmetic)] // It is always correct.
if self.config.jitter {
// jitter algorithm will randomly pick a delay between [0.5 * delay, 1.5 * delay)
let per: f32 = rand::random();
let cur_sec = cur.as_secs_f32() * (0.5 + per);
cur = Duration::from_secs_f32(cur_sec);
}
Some(cur)
}

Check warning on line 101 in curp/src/client_new/retry.rs

View check run for this annotation

Codecov / codecov/patch

curp/src/client_new/retry.rs#L87-L101

Added lines #L87 - L101 were not covered by tests
}
Expand Down

0 comments on commit f43bb5f

Please sign in to comment.