Skip to content

Commit

Permalink
pingora-limits - Rate Estimator hashes & slots configuration
Browse files Browse the repository at this point in the history
  • Loading branch information
PawelJastrzebski committed Sep 13, 2024
1 parent e288bfe commit 4198702
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions pingora-limits/src/rate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 4198702

Please sign in to comment.