#histogram #exponential #recent #statistics #metrics #values #weight

exponential-decay-histogram

A histogram which exponentially weights in favor of recent values

12 releases

0.1.11 Sep 25, 2023
0.1.10 May 2, 2022
0.1.9 Feb 12, 2021
0.1.7 Nov 29, 2020
0.1.0 May 30, 2017

#410 in Data structures

Download history 1390/week @ 2024-08-18 1412/week @ 2024-08-25 1557/week @ 2024-09-01 1257/week @ 2024-09-08 1664/week @ 2024-09-15 1543/week @ 2024-09-22 1502/week @ 2024-09-29 1125/week @ 2024-10-06 148/week @ 2024-10-13 44/week @ 2024-10-20 56/week @ 2024-10-27 139/week @ 2024-11-03 36/week @ 2024-11-10 51/week @ 2024-11-17 137/week @ 2024-11-24 44/week @ 2024-12-01

269 downloads per month
Used in 10 crates (2 directly)

MIT/Apache

21KB
385 lines

exponential-decay-histogram

Documentation

A histogram which exponentially weights in favor of recent values.

License

Licensed under either of

at your option.

Contribution

Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.


lib.rs:

A histogram which exponentially weights in favor of recent values.

Histograms compute statistics about the distribution of values in a data set. This histogram exponentially favors recent values over older ones, making it suitable for use cases such as monitoring the state of long running processes.

The histogram does not store all values simultaneously, but rather a randomized subset. This allows us to put bounds on overall memory use regardless of the rate of events.

This implementation is based on the ExponentiallyDecayingReservoir class in the Java Metrics library, which is itself based on the forward decay model described in Cormode et al. 2009.

Examples

use exponential_decay_histogram::ExponentialDecayHistogram;

let mut histogram = ExponentialDecayHistogram::new();

// Do some work for a while and fill the histogram with some information.
// Even though we're putting 10000 values into the histogram, it will only
// retain a subset of them.
for _ in 0..10000 {
    let size = do_work();
    histogram.update(size);
}

// Take a snapshot to inspect the current state of the histogram.
let snapshot = histogram.snapshot();
println!("count: {}", snapshot.count());
println!("min: {}", snapshot.min());
println!("max: {}", snapshot.max());
println!("mean: {}", snapshot.mean());
println!("standard deviation: {}", snapshot.stddev());
println!("median: {}", snapshot.value(0.5));
println!("99th percentile: {}", snapshot.value(0.99));

Dependencies

~565KB
~10K SLoC