Skip to content

Commit

Permalink
pingora-limits - Rate Estimator hashes & slots configuration
Browse files Browse the repository at this point in the history
---
fix cargo fmt check

Includes-commit: 19eeddc
Includes-commit: 4198702
Replicated-from: #380
  • Loading branch information
PawelJastrzebski authored and johnhurt committed Sep 13, 2024
1 parent 0df7b0d commit 3d42cf0
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 3 deletions.
2 changes: 1 addition & 1 deletion .bleep
Original file line number Diff line number Diff line change
@@ -1 +1 @@
6923a7f31ed6fff1ddaf00ffb8dd56311042c395
9b92c0fed7b703c61415414c69ff196e9deb11eb
14 changes: 12 additions & 2 deletions pingora-limits/src/rate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 3d42cf0

Please sign in to comment.