Skip to content

Conversation

@SURYAS1306
Copy link

What is the purpose of the change?

This PR fixes an issue in AdaptiveLoadBalance / AdaptiveMetrics where latency decay behaves incorrectly when provider metrics are not updated for a period of time.

Currently, when no new provider metrics arrive, getLoad() may repeatedly apply the penalty branch or aggressively right-shift lastLatency, which can result in stale or extreme values dominating EWMA. This makes adaptive load balancing unstable, especially in low-QPS or intermittent-update scenarios.

This PR ensures that latency decays safely and progressively instead of collapsing or being stuck at penalty values.

Fixes #15810

What is changed?

1. Improved decay logic in AdaptiveMetrics#getLoad()

  • Prevents lastLatency from collapsing to zero.
  • Ensures decay happens smoothly when provider metrics are not refreshed.
  • Avoids repeatedly applying the penalty path when timestamps are equal.

2. Added unit test

Added testAdaptiveMetricsDecayWithoutProviderUpdate

Verifies that when provider metrics are not updated:

  • latency decays over time
  • penalty value is not stuck
  • EWMA continues to evolve

Why is this needed?

Adaptive load balancing relies on EWMA latency to reflect recent performance trends.

Without this fix:

  • old latency values can dominate indefinitely
  • penalty values may be repeatedly re-applied
  • low-traffic services become unfairly weighted

This change makes adaptive load balancing more stable, realistic, and robust under real-world traffic patterns.

Verifying this change

  • Added new unit test covering the decay scenario
  • All tests pass locally:
mvn -pl dubbo-cluster -am test

Checklist

@codecov-commenter
Copy link

codecov-commenter commented Jan 25, 2026

Codecov Report

❌ Patch coverage is 50.00000% with 1 line in your changes missing coverage. Please review.
✅ Project coverage is 60.73%. Comparing base (be40746) to head (8946d40).

Files with missing lines Patch % Lines
...ain/java/org/apache/dubbo/rpc/AdaptiveMetrics.java 50.00% 0 Missing and 1 partial ⚠️
Additional details and impacted files
@@             Coverage Diff              @@
##                3.3   #16048      +/-   ##
============================================
- Coverage     60.74%   60.73%   -0.01%     
+ Complexity    11754    11745       -9     
============================================
  Files          1949     1949              
  Lines         88898    88898              
  Branches      13407    13407              
============================================
- Hits          53998    53993       -5     
- Misses        29337    29342       +5     
  Partials       5563     5563              
Flag Coverage Δ
integration-tests-java21 32.23% <0.00%> (+<0.01%) ⬆️
integration-tests-java8 32.36% <0.00%> (-0.03%) ⬇️
samples-tests-java21 32.11% <0.00%> (-0.02%) ⬇️
samples-tests-java8 29.84% <0.00%> (+0.14%) ⬆️
unit-tests-java11 59.00% <50.00%> (-0.01%) ⬇️
unit-tests-java17 58.49% <50.00%> (-0.03%) ⬇️
unit-tests-java21 58.51% <50.00%> (+0.01%) ⬆️
unit-tests-java25 58.45% <50.00%> (-0.01%) ⬇️
unit-tests-java8 59.00% <50.00%> (+<0.01%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@SURYAS1306
Copy link
Author

Hi maintainers,

This PR fixes the adaptive metrics decay issue when provider metrics are not updated and adds a unit test covering the scenario.

All checks are green. I’d really appreciate your review when you have time.

Thanks!

Sign up for free to 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.

[BUG] Questions about Dubbo Adaptive Load Balance

2 participants