Skip to content

Commit

Permalink
chore: remove jitter
Browse files Browse the repository at this point in the history
Signed-off-by: iGxnon <[email protected]>
  • Loading branch information
iGxnon committed Jan 2, 2024
1 parent 8875121 commit e79270d
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,
}
}

/// 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,
}
}

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)
}
}
Expand Down

0 comments on commit e79270d

Please sign in to comment.