kumulant

RateStat

class RateStat(val concurrency: Concurrency = Concurrency.None) : SeriesStat<RateResult> (source)

Cumulative rate: total accumulated value divided by elapsed time since the first update.

For time-decaying rates that weight recent observations more heavily, read DecayingSumResult.rate. Use withValue on the Rate spec to count each update as 1.

Use cases: lifetime throughput (requests/sec since start, total bytes divided by uptime). Pair with withValue(1.0) for an event-rate counter.

Memory: O(1); total value cell + start timestamp.

Update: O(1) per observation; one atomic add plus a CAS-loop-min on the start timestamp (loop terminates immediately on the common path).

Concurrency: Single atomic add for the total + CAS-loop-min for the start timestamp. Lock-free and exact under every Concurrency level. Concurrency.HighWrite switches the total cell to a striped adder; the start timestamp stays an AtomicLong (the striped adder doesn't support CAS).

Constructors

RateStat

constructor(concurrency: Concurrency = Concurrency.None)(source)

Properties

concurrency

open override val concurrency: Concurrency(source)

Thread-safety mode fixed at construction. See Concurrency for the shared contract and the implementation's KDoc for its cell and lock strategy.

Functions

create

open override fun create(concurrency: Concurrency? = null): RateStat(source)

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

open override fun merge(values: RateResult, timestampNanos: Long = currentTimeNanos())(source)

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

open override fun read(timestampNanos: Long = currentTimeNanos()): RateResult(source)

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

open override fun reset()(source)

Restore the configured baseline, including any prior seed. Preserves the configuration and concurrency.

Link copied to clipboard
open fun update(value: Double, weight: Double = 1.0)

Record value with weight at the current monotonic time.

open override fun update(value: Double, timestampNanos: Long, weight: Double = 1.0)

Record value with weight at timestampNanos.

Link copied to clipboard
open fun validateMerge(values: RateResult)

Validate values for merge without changing accumulator state. Containers validate every child before merging any of them. Successful validation checks compatibility; it does not make a concurrent merge transactional.

update

open override fun update(value: Double, timestampNanos: Long, weight: Double = 1.0)(source)

Record value with weight at timestampNanos.