Conversation
get() applies time-based decay but never writes it back, while update() used
the raw, undecayed prev.ema as its base. After an idle period the two methods
therefore disagreed: get() reported congestion had subsided, yet the next
update() revived the stale value at 0.9x its old magnitude and re-armed the
decay delay - which can pin the batcher in permanent back-pressure
("release a few batches, drop for tens of seconds" loop).
Extract the decay computation into a shared helper and use it in both get()
and update(), so a fresh sample is blended onto the decayed value.
Control experiment: updateAfterIdleUsesDecayedBase fails on the old code
(18s instead of ~32ms revived) and passes with the fix; existing EMALong
expectations unchanged (8/8).
Fixes apache#301
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
EMALong.get()applies time-based decay but never writes the decayed value back;EMALong.update()uses the raw, undecayedprev.emaas its base. The two methods therefore disagree about the current EMA value: after an idle periodget()reports that congestion has subsided, yet the very nextupdate()revives the stale value at 0.9× its old magnitude — and becauseupdate()refresheslastTs, the revived value will not decay again for anotherdecayDelay.Failure scenario
With
alpha=0.1,decay=0.9,decayDelay = maxBurstLatency = 5s(matchingBatcher's defaults):Batcher.submit()gates onemaQueueingTime.get() > maxBurstLatency, so after congestion has genuinely subsided the revived 18s value exceeds the 5s threshold and the batcher rejects requests withBackPressureException— whose callers drop messages outright. Every batch that does get admitted pushes the value back to0.9×, producing an "admit one small batch, then drop for ~18s" cycle.Fix
Extract the decay computation and use it in both
get()andupdate(), so a fresh sample is blended onto the decayed value. (An alternative semantic — writing the decayed value back insideget()— would make a read modify the hot path's state; the extraction keeps reads side-effect free. Happy to switch if maintainers prefer the other variant.)Test evidence
New regression test
updateAfterIdleUsesDecayedBase: congestion spike (ema=20s), 60s idle, thenupdate(0).Production validation
Deployed in a rolling 6-node cluster (wholesale
lib/replacement, one node at a time, zero rollbacks); cluster mesh, all 13 live client connections and cross-node delivery verified post-deploy. No back-pressure rejection storms observed in the rollout window.Fixes #301