From 41987023f175942be8f47ede18ada85b20993cca Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pawe=C5=82=20Jastrzebski?= Date: Fri, 13 Sep 2024 11:44:15 +0200 Subject: [PATCH 1/2] pingora-limits - Rate Estimator hashes & slots configuration --- pingora-limits/src/rate.rs | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/pingora-limits/src/rate.rs b/pingora-limits/src/rate.rs index f72cf20a..1e308fac 100644 --- a/pingora-limits/src/rate.rs +++ b/pingora-limits/src/rate.rs @@ -43,9 +43,15 @@ const SLOTS: usize = 1024; // This value can be lower if interval is short (key impl Rate { /// Create a new `Rate` with the given interval. pub fn new(interval: std::time::Duration) -> Self { + Rate::new_with_estimator_config(interval, HASHES, SLOTS) + } + + /// Create a new `Rate` with the given interval and Estimator config with the given amount of hashes and columns (slots). + #[inline] + pub fn new_with_estimator_config(interval: std::time::Duration, hashes: usize, slots: usize) -> Self { Rate { - red_slot: Estimator::new(HASHES, SLOTS), - blue_slot: Estimator::new(HASHES, SLOTS), + red_slot: Estimator::new(hashes, slots), + blue_slot: Estimator::new(hashes, slots), red_or_blue: AtomicBool::new(true), start: Instant::now(), reset_interval_ms: interval.as_millis() as u64, // should be small not to overflow From 19eeddcfbf0f4a7e4dc96cf4782143e96f54b371 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pawe=C5=82=20Jastrzebski?= Date: Fri, 13 Sep 2024 16:27:36 +0200 Subject: [PATCH 2/2] fix cargo fmt check --- pingora-limits/src/rate.rs | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/pingora-limits/src/rate.rs b/pingora-limits/src/rate.rs index 1e308fac..33b07002 100644 --- a/pingora-limits/src/rate.rs +++ b/pingora-limits/src/rate.rs @@ -48,7 +48,11 @@ impl Rate { /// Create a new `Rate` with the given interval and Estimator config with the given amount of hashes and columns (slots). #[inline] - pub fn new_with_estimator_config(interval: std::time::Duration, hashes: usize, slots: usize) -> Self { + pub fn new_with_estimator_config( + interval: std::time::Duration, + hashes: usize, + slots: usize, + ) -> Self { Rate { red_slot: Estimator::new(hashes, slots), blue_slot: Estimator::new(hashes, slots),