DecayingSumStat
Exponentially decaying sum driven by wall-clock elapsed time.
S(t) = Sum v_i * w_i * exp(-alpha*(t - t_i)) with alpha = ln(2)/halfLife.
Internally uses landmark rotation to keep the stored accumulator in a bounded numerical range even after many half-lives of activity.
Use cases: time-windowed event totals (requests in the last 30s), recency-weighted aggregation for monitoring dashboards, and recent throughput through DecayingSumResult.rate (request rate over the last 30 s, recent error rate). The core time-decay primitive; pair with another DecayingSumStat for ratios via DecayingMeanStat.
Memory: O(1); a landmark, a sum, and a lock.
Update: O(1) per observation, including landmark rotation.
Concurrency: Body locked under any concurrent level. Updates, landmark rotation, reads, merges, and resets share one lock so a contribution cannot land in retired storage. Concurrency.None runs without synchronisation.
Constructors
DecayingSumStat
Properties
concurrency
Thread-safety mode fixed at construction. See Concurrency for the shared contract and the implementation's KDoc for its cell and lock strategy.
halfLife
weighting
Time-decay schedule applied to past contributions.
Functions
create
Create an independent accumulator at the configured baseline. A null concurrency preserves this accumulator's mode; a non-null value overrides it. Modality subtypes narrow the return type to preserve the input shape.
merge
Fold a compatible snapshot values into this accumulator at timestampNanos. Implementations document whether the combine is exact or approximate and which state the snapshot omits. The source accumulator is unaffected.
Time-dependent statistics, such as windows, place the snapshot at timestampNanos, which must share the clock the caller uses for updates and reads. Time-independent statistics ignore it.
read
Return the current result evaluated at timestampNanos. Time-independent statistics ignore the timestamp. Reading does not add an observation.
Snapshot consistency depends on the implementation's synchronisation. Locks protect coupled state under Concurrency.Strict and Concurrency.HighWrite; independently updated cells and JVM striped adders can still yield a best-effort snapshot. Concurrency.Relaxed permits drift across coupled cells.
reset
Restore the configured baseline, including any prior seed. Preserves the configuration and concurrency.