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,
) -> 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 rate<T: Hash>(&self, key: &T) -> f64
pub fn rate<T: Hash>(&self, key: &T) -> f64
Return the per second rate estimation.
This is the average rate of the latest completed period of length interval.
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)