From f43bb5f050bb04794ee0b1cc0fdb1432ff727dcd Mon Sep 17 00:00:00 2001 From: iGxnon Date: Fri, 29 Dec 2023 14:28:53 +0800 Subject: [PATCH] chore: remove jitter Signed-off-by: iGxnon --- curp/src/client_new/retry.rs | 15 ++------------- 1 file changed, 2 insertions(+), 13 deletions(-) diff --git a/curp/src/client_new/retry.rs b/curp/src/client_new/retry.rs index 9895081966..a33ac316bb 100644 --- a/curp/src/client_new/retry.rs +++ b/curp/src/client_new/retry.rs @@ -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 @@ -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, } } @@ -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) } }