Class EwmaLatencyTracker

java.lang.Object
com.google.cloud.spanner.spi.v1.EwmaLatencyTracker
All Implemented Interfaces:
LatencyTracker

@InternalApi @BetaApi public class EwmaLatencyTracker extends Object implements 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 Details

    • DEFAULT_ALPHA

      public static final double DEFAULT_ALPHA
      See Also:
    • DEFAULT_DECAY_TIME

      public static final Duration 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: LatencyTracker
      Returns the current latency score.
      Specified by:
      getScore in interface LatencyTracker
      Returns:
      the latency score, where lower is better.
    • update

      public void update(Duration latency)
      Description copied from interface: LatencyTracker
      Updates the latency score with a new observation.
      Specified by:
      update in interface LatencyTracker
      Parameters:
      latency - the observed latency.
    • recordError

      public void recordError(Duration penalty)
      Description copied from interface: LatencyTracker
      Records an error and applies a latency penalty.
      Specified by:
      recordError in interface LatencyTracker
      Parameters:
      penalty - the penalty to apply.