Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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