Skip to content

fix(backend): correct EMA formula in EmaHealthTracker - #26

Open
Sertug17 wants to merge 1 commit into
refcell:mainfrom
Sertug17:fix/ema-latency-formula
Open

fix(backend): correct EMA formula in EmaHealthTracker#26
Sertug17 wants to merge 1 commit into
refcell:mainfrom
Sertug17:fix/ema-latency-formula

Conversation

@Sertug17

Copy link
Copy Markdown

Summary

Fixes#25

EmaHealthTracker was computing latency with a simple moving average
instead of a true exponential moving average.

Changes

  • Add alpha: f64 field to HealthConfig (default 0.1)
  • Replace (old + sample) / 2 with alpha * sample + (1 - alpha) * old
  • Update tests to reflect corrected behavior

Before / After

BeforeAfter
Formula(old + sample) / 2alpha * sample + (1-alpha) * old
Weight on latest samplealways 50%configurable (default 10%)
Spike sensitivityhighlow — smooths transient spikes

Testing

All existing tests pass with updated expected values.

The previous implementation used a simple moving average:
new = (old + sample) / 2
This is not a true EMA - it always assigns 50% weight to the most
recent sample regardless of history, causing excessive sensitivity
to latency spikes.
Replace with the standard EMA formula:
new = alpha * sample + (1 - alpha) * old
Add alpha field to HealthConfig (default: 0.1) so callers can tune
the smoothing factor. A lower alpha retains more historical data and
is less sensitive to transient spikes, which is desirable for backend
health tracking in a production RPC proxy.
Update tests to reflect the corrected formula.
Closesrefcell#25
Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

fix(backend): EmaHealthTracker uses simple moving average instead of true EMA

1 participant

@Sertug17