Skip to main content

Module decaying_counter

Module decaying_counter 

Source
Expand description

§Exponentially-decaying event counter

A tiny book-keeping helper for “how busy has this been lately” metrics. Each DecayingCounter holds a single f64 accumulator that decays continuously toward zero with a configurable time constant τ. Recording an event adds to the accumulator; reading it decays the stored value forward to the current instant first.

For a steady arrival rate r (events per millisecond) the accumulator settles at r · τ. So a counter with τ = 1 hour reads directly as “estimated events in the last hour”, τ = 1 day as “events in the last day”, and so on — the same exponentially-weighted idea behind Unix’s load_1m/5m/15m.

Like crate::tools::pow_required_estimator this takes TimeMillis as a plain parameter rather than depending on a TimeProvider, which keeps it trivially testable with explicit timestamps.

Structs§

DecayingCounter
A single exponentially-weighted decaying accumulator. See the module docs for the r · τ steady-state interpretation.