Package com.google.cloud.spanner.spi.v1
Class EwmaLatencyTracker
java.lang.Object
com.google.cloud.spanner.spi.v1.EwmaLatencyTracker
- All Implemented Interfaces:
LatencyTracker
Implementation 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 / \tau}$.
A fixed-alpha constructor is retained for focused tests.
-
Field Summary
Fields -
Constructor Summary
ConstructorsConstructorDescriptionCreates a new tracker with Envoy-style time-based decay and a 10-second decay window.EwmaLatencyTracker(double alpha) Creates a new tracker with the specified alpha value. -
Method Summary
Modifier and TypeMethodDescriptiondoublegetScore()Returns the current latency score.voidrecordError(Duration penalty) Records an error and applies a latency penalty.voidUpdates the latency score with a new observation.
-
Field Details
-
DEFAULT_ALPHA
public static final double DEFAULT_ALPHA- See Also:
-
DEFAULT_DECAY_TIME
-
-
Constructor Details
-
EwmaLatencyTracker
public EwmaLatencyTracker()Creates a new tracker with Envoy-style time-based decay and a 10-second decay window. -
EwmaLatencyTracker
public EwmaLatencyTracker(double alpha) Creates a new tracker with the specified alpha value.- Parameters:
alpha- the smoothing factor, must be in the range (0, 1]
-
-
Method Details
-
getScore
public double getScore()Description copied from interface:LatencyTrackerReturns the current latency score.- Specified by:
getScorein interfaceLatencyTracker- Returns:
- the latency score, where lower is better.
-
update
Description copied from interface:LatencyTrackerUpdates the latency score with a new observation.- Specified by:
updatein interfaceLatencyTracker- Parameters:
latency- the observed latency.
-
recordError
Description copied from interface:LatencyTrackerRecords an error and applies a latency penalty.- Specified by:
recordErrorin interfaceLatencyTracker- Parameters:
penalty- the penalty to apply.
-