RaftEx.LeakyIntegrator
(raft_ex v0.1.0)
View Source
Exponential-decay leaky integrator for rate estimation.
Useful for computing a smoothed throughput figure (e.g. commands/second)
without keeping a full sliding window. The integrator decays toward zero
over decay_time_ms milliseconds.
Usage
iex> li = RaftEx.LeakyIntegrator.new(1_000) # 1-second half-life
iex> li = RaftEx.LeakyIntegrator.update(10, li)
iex> RaftEx.LeakyIntegrator.rate(li)
# → ~10 commands/second immediately after the update
Summary
Functions
Create a new integrator with the given decay time in milliseconds.
Estimated rate in units/second using the current clock.
Estimated rate in units/second at timestamp ts.
Read the current decayed value using the current monotonic clock.
Read the current decayed value at timestamp ts.
Reset the integrator to zero.
Add amount to the integrator using the current monotonic clock.
Add amount to the integrator at the given timestamp ts.
Types
@type t() :: %RaftEx.LeakyIntegrator{ decay_time_ms: pos_integer(), last_update: integer() | nil, value: float() }
Functions
@spec new(pos_integer()) :: t()
Create a new integrator with the given decay time in milliseconds.
Estimated rate in units/second using the current clock.
Estimated rate in units/second at timestamp ts.
Read the current decayed value using the current monotonic clock.
Read the current decayed value at timestamp ts.
Reset the integrator to zero.
Add amount to the integrator using the current monotonic clock.
Add amount to the integrator at the given timestamp ts.