Repository navigation
Conversation
…ervals The adaptive strategy truncated every smoothed update to whole millis, so sub-millisecond increments at short feedback intervals were discarded and a previously fast upstream could stay pinned at its old estimate forever. - keep the EWMA as a double in millis inside Stats; round only where a long leaves the record (ewmaLatencyMillis accessor and the score ceiling) - define same-timestamp behavior: blend with a minimum 1 ms decay interval instead of giving the new sample zero weight - add deterministic regressions for sustained latency convergence, same timestamps, decreasing latency and the failure penalty floor
wy471x
left a comment
There was a problem hiding this comment.
Two-axis review — standards & spec
Keeping the EWMA as a double and rounding only at the edge is the right shape for #8382, and the new tests are deterministic and sleep-free. Findings below are ordered by severity; the first one is the only one I would ask you to settle before merge.
Service / behaviour
-
score()now ceils an unroundeddouble— an unrequested scoring change.AdaptiveUpstreamStats.score()uses(current.ewmaLatency() + 1) * …and then(long) Math.ceil(score). Previously the estimate was an exactlong, so the ceiling was exact. Now sub-unit float residue flips the result: an estimate of1.0000001scores 3 while0.9999999scores 2, i.e. two nodes whose latency is indistinguishable get different routing scores, and any score whose fractional part crosses an integer shifts by 1 (e.g.ewma=1.4, inflight=0, weight=1: 2 before, 3 after).score()is asserted nowhere in the diff. If identical routing to before is intended, score the rounded value (ewmaLatencyMillis()); if the shift is intended, please state it in the class javadoc and cover it with a test. -
The minimum decay interval makes the 600 ms window rate-dependent.
smooth()appliesMath.max(sinceLastMillis, MIN_DECAY_INTERVAL_MILLIS)per sample, so N completions stamped in the same millisecond contribute N ms of decay. 600 same-millisecond completions after a 1 ms baseline move the estimateexp(-1)≈ 63 % of the way to the burst latency within one wall-clock millisecond, while the same 600 samples spread over 600 ms behave completely differently. The clamp also converts negative gaps (out-of-order feedback, clock regression) into 1 ms of evidence; the old code gave them zero weight, and the javadoc only justifies the zero-gap case. Suggest handlingsinceLastMillis <= 0explicitly and documenting the intended rate-dependence. -
MIN_DECAY_INTERVAL_MILLISispublicon a public class but only used internally; a package-private constant keeps the SPI surface unchanged.
Tests
decreasingLatencyPullsTheEstimateDownAtShortIntervalsalso passes onmaster— integer truncation converges downward at 1 ms intervals too — so it is a guard, not a regression test for this defect.sameTimestampObservationsStillMoveTheEstimateis the only test proving the behavioural change and asserts just> 1L; a per-sample weighting of 1e-6 would still pass. Please assert a real bound.- The four new tests repeat the same three-line arrange block; a small helper would keep them readable.
Spec (#8382)
- Convergence and short-interval/same-timestamp coverage: met.
- "Keep statistics finite and non-negative" is documented in the javadoc but not asserted anywhere; it holds by construction via
latencyOf, so one assertion in the existing tests would close the criterion. - No scope creep — the change touches only
Statsand its tests.
…#8399) * fix(loadbalancer): keep neutral 4xx feedback out of the sample timing CLIENT_ERROR feedback replaced lastFeedbackMillis, and the next latency-bearing sample computed its decay from that timestamp, so an unrelated 4xx could greatly change recovery from an earlier slow or failed attempt. - split activity bookkeeping (lastFeedbackMillis, retention/pruning only) from the effective-sample timestamp (lastSampleMillis) that drives the decay - a 4xx refreshes activity only; EWMA, sample count and sample timing stay intact - an identity first seen through a 4xx stays cold and takes its first real sample as-is - add deterministic regressions: issue fixture equivalence, many interleaved 4xx, cold-target neutrality, retention via 4xx activity, concurrent accounting * fix(loadbalancer): bound adaptive feedback cleanup and cover singleton pools (#8400) Cleanup only ran from doSelect, so the singleton fast path never reclaimed removed addresses, and pruneIfNeeded swept the whole map on every multi-node selection once the size exceeded 256. - move maintenance to select() so singleton traffic drives cleanup too; the inflight reservation pairing is untouched - gate maintenance by a 10 s interval and a 64-entry scan budget with a resume cursor; once armed it drains across windows until a full cycle prunes nothing, so expired entries are reclaimed even below the threshold - hard capacity of 4096 identities: full idle sweep plus oldest-activity eviction beyond it; eviction only drops scoring cache, never in-flight reservations - conditional remove(key, value) keeps concurrently refreshed records safe - update the prune test to the bounded semantics and add regressions for singleton cleanup, the per-run work bound, capacity eviction and concurrent feedback during maintenance
Address review on #8398: - score() ceils ewmaLatencyMillis() so sub-millisecond residue cannot shift routing; the double estimate stays internal to the smoothing - smooth() handles zero and negative gaps explicitly with the minimum decay interval instead of Math.max, and the constant documents the intended per-sample rate dependence; MIN_DECAY_INTERVAL_MILLIS is package-private - strengthen the same-timestamp test to the analytic ~96 ms blend bound, turn the decreasing-latency test into a real regression (a 10-sample burst must follow the 600 ms time constant instead of collapsing by truncation), assert finite/non-negative statistics, and extract the shared arrange helper - add score rounding and backward-clock coverage
compare() scored each candidate through getWeight(), which read the wall clock separately per candidate. When the millisecond ticked between the two reads and both upstreams were created in the previous millisecond, one score used the full weight (uptime 0) while the other used the warm-up weight (uptime 1), inverting the comparison and flaking fastServerErrorsArePenalizedByTheFailureFloor. Add a protected getWeight(upstream, nowMillis) overload and pass the single selection instant already sampled in doSelect through compare/score, so both candidates are always weighed on the same scale. Other selectors keep the existing clock-reading entry point unchanged. Cover the sampled-instant weight contract and the single-instant comparison with deterministic tests.
|
@wy471x Thanks for the two-axis review — every item is addressed in ffbedd7, plus 0faf723 for a pre-existing flake that the verification surfaced (details at the end). Service / behaviour1. 2. Rate-dependent minimum decay / negative gaps — 3. Tests4. Decreasing-latency test was a guard — restructured into a real regression: from a 100 ms baseline, a 10-sample burst at 1 ms intervals must follow the 600 ms time constant (~98 ms, asserted within [95, 100]); master's per-update truncation collapses the estimate to 90 and fails the assertion (verified against 5. 6. Repeated arrange block — extracted Spec (#8382)The finite/non-negative criterion is now asserted in Additional commit (0faf723)The verification runs surfaced a pre-existing flake in Verification: |
…stream master's shared upstream() helper now disables warm-up to keep selection comparisons weight-stable; the sampled-instant weight test needs the ramp, so build its own warm-up-enabled upstream instead of relying on the helper.
|
CI note: the first push failed in the merge-with-master build because master's shared upstream() test helper now disables warm-up (weight-stable comparisons), while the new sampled-instant weight test relied on the helper's ramp. Fixed in 469bc31 by building an explicit warm-up-enabled upstream inside that test, and synced master via merge commit 75e64ea. The production single-instant weight sampling complements master's fixture stabilization (which only covers the test path). Verified on the merged tree: ./mvnw -pl shenyu-loadbalancer -am test — 143 tests, 0 failures, Checkstyle clean. |
What this PR does
Fixes the adaptive EWMA quantization loss: every smoothed update was cast to whole millis, so at short feedback intervals each sub-millisecond increment was discarded and a previously fast upstream could stay pinned at its old estimate even under sustained slower responses (the issue fixture stayed at
1after 10,000 consecutive 100 ms samples).Statsnow keeps the EWMA as adoublein millis internally; rounding happens only where a long leaves the record (ewmaLatencyMillis()accessor,Math.round) and at the score ceiling. Scoring uses the unrounded value.MIN_DECAY_INTERVAL_MILLIS), so concurrent completions are blended with real weight instead of being discarded with zero weight.Related Issue
Fixes #8382
Refs #8300 (opt-in adaptive scoring), #8365 (merged implementation)
Type of change
How was this tested
./mvnw test -pl shenyu-loadbalancerpassed (126 tests)Checklist
Statsis package-private; theewmaLatencyMillis()accessor keeps its long contract)