pub struct Rate { /* private fields */ }Expand description
A stable rate estimator that reports the rate of events per period of interval time.
It counts events for periods of interval and returns the average rate of the latest completed
period while counting events for the current (partial) period.
Implementations§
Source§impl Rate
impl Rate
Sourcepub fn new_with_estimator_config(
interval: Duration,
hashes: usize,
slots: usize,
) -> Rate
pub fn new_with_estimator_config( interval: Duration, hashes: usize, slots: usize, ) -> Rate
Create a new Rate with the given interval and Estimator config with the given amount of hashes and columns (slots).
Sourcepub fn rate<T>(&self, key: &T) -> f64where
T: Hash,
pub fn rate<T>(&self, key: &T) -> f64where
T: Hash,
Return the per second rate estimation.
This is the average rate of the latest completed period of length interval.
Sourcepub fn observe<T>(&self, key: &T, events: isize) -> isizewhere
T: Hash,
pub fn observe<T>(&self, key: &T, events: isize) -> isizewhere
T: Hash,
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)