diff options
author | Paweł Jastrzebski <[email protected]> | 2024-09-13 14:27:36 +0000 |
---|---|---|
committer | Yuchen Wu <[email protected]> | 2024-09-23 10:43:26 -0700 |
commit | 760dda4fa881157e4ef930c2288412126afc320f (patch) | |
tree | 67e1c5fc4ae91899f4a3906fe6f56b5aecb1006f | |
parent | 6d917b424ad3f62d9116091097b60bde02f38152 (diff) | |
download | pingora-760dda4fa881157e4ef930c2288412126afc320f.tar.gz pingora-760dda4fa881157e4ef930c2288412126afc320f.zip |
pingora-limits - Rate Estimator hashes & slots configuration
---
fix cargo fmt check
Includes-commit: 19eeddcfbf0f4a7e4dc96cf4782143e96f54b371
Includes-commit: 41987023f175942be8f47ede18ada85b20993cca
Replicated-from: https://github.com/cloudflare/pingora/pull/380
-rw-r--r-- | .bleep | 2 | ||||
-rw-r--r-- | pingora-limits/src/rate.rs | 14 |
2 files changed, 13 insertions, 3 deletions
@@ -1 +1 @@ -6923a7f31ed6fff1ddaf00ffb8dd56311042c395
\ No newline at end of file +9b92c0fed7b703c61415414c69ff196e9deb11eb
\ No newline at end of file diff --git a/pingora-limits/src/rate.rs b/pingora-limits/src/rate.rs index f72cf20..33b0700 100644 --- a/pingora-limits/src/rate.rs +++ b/pingora-limits/src/rate.rs @@ -43,9 +43,19 @@ 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 |