fix(backend): correct EMA formula in EmaHealthTracker - #26
Open
Sertug17 wants to merge 1 commit into
Open
Conversation
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.
Closes refcell#25
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Fixes #25
EmaHealthTrackerwas computing latency with a simple moving averageinstead of a true exponential moving average.
Changes
alpha: f64field toHealthConfig(default0.1)(old + sample) / 2withalpha * sample + (1 - alpha) * oldBefore / After
(old + sample) / 2alpha * sample + (1-alpha) * oldTesting
All existing tests pass with updated expected values.