pub struct Rate { /* private fields */ }
Expand description
A stable rate estimator that reports the rate of events in the past interval
time.
It returns the average rate between interval
* 2 and interval
while collecting the events
happening between interval
and now.
This estimator ignores events that happen less than once per interval
time.
Implementations§
Source§impl Rate
impl Rate
Sourcepub fn new_with_estimator_config(
interval: Duration,
hashes: usize,
slots: usize,
) -> Self
pub fn new_with_estimator_config( interval: Duration, hashes: usize, slots: usize, ) -> Self
Create a new Rate
with the given interval and Estimator config with the given amount of hashes and columns (slots).
Sourcepub fn observe<T: Hash>(&self, key: &T, events: isize) -> isize
pub fn observe<T: Hash>(&self, key: &T, events: isize) -> isize
Report new events and return number of events seen so far in the current interval.
Sourcepub fn rate_with<F, T, K>(&self, key: &K, rate_calc_fn: F) -> T
pub fn rate_with<F, T, K>(&self, key: &K, rate_calc_fn: F) -> T
Get the current rate as calculated with the given closure. This closure will take an argument containing all the accessible information about the rate from this object and allow the caller to make their own estimation of rate based on:
- The accumulated samples in the current interval (in progress)
- The accumulated samples in the previous interval (completed)
- The size of the interval
- Elapsed fraction of current interval for this sample (0..1)
Auto Trait Implementations§
impl !Freeze for Rate
impl RefUnwindSafe for Rate
impl Send for Rate
impl Sync for Rate
impl Unpin for Rate
impl UnwindSafe for Rate
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more