public class EwmaLatencyTracker implements LatencyTrackerImplementation of LatencyTracker using Exponentially Weighted Moving Average (EWMA).
By default, this tracker uses a time-decayed EWMA: $S_{i+1} = alpha(Delta t) * new_latency
(1 - alpha(Delta t)) * S_i$, where $alpha(Delta t) = 1 - e^{-Delta t / au}$.
A fixed-alpha constructor is retained for focused tests.
Implements
LatencyTrackerStatic Fields
DEFAULT_ALPHA
public static final double DEFAULT_ALPHA| Field Value | |
|---|---|
| Type | Description |
double |
|
DEFAULT_DECAY_TIME
public static final Duration DEFAULT_DECAY_TIME| Field Value | |
|---|---|
| Type | Description |
Duration |
|
Constructors
EwmaLatencyTracker()
public EwmaLatencyTracker()Creates a new tracker with Envoy-style time-based decay and a 10-second decay window.
EwmaLatencyTracker(double alpha)
public EwmaLatencyTracker(double alpha)Creates a new tracker with the specified alpha value.
| Parameter | |
|---|---|
| Name | Description |
alpha |
doublethe smoothing factor, must be in the range (0, 1] |
Methods
getScore()
public double getScore()Returns the current latency score.
| Returns | |
|---|---|
| Type | Description |
double |
|
recordError(Duration penalty)
public void recordError(Duration penalty)Records an error and applies a latency penalty.
| Parameter | |
|---|---|
| Name | Description |
penalty |
Duration |
update(Duration latency)
public void update(Duration latency)Updates the latency score with a new observation.
| Parameter | |
|---|---|
| Name | Description |
latency |
Duration |