Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

pingora-limits - Rate Estimator hashes & slots configuration #76

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
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
Loading