-
Notifications
You must be signed in to change notification settings - Fork 26.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Optimize RoundRobinLoadBalance #2586
Conversation
Codecov Report
@@ Coverage Diff @@
## master #2586 +/- ##
============================================
- Coverage 55.2% 55.11% -0.09%
+ Complexity 5298 5291 -7
============================================
Files 573 573
Lines 25538 25529 -9
Branches 4531 4530 -1
============================================
- Hits 14097 14070 -27
- Misses 9341 9355 +14
- Partials 2100 2104 +4
Continue to review full report at Codecov.
|
@kimmking |
@@ -77,6 +77,6 @@ | |||
} | |||
} | |||
// Round robin | |||
return invokers.get(sequence.incrementAndGet() % length); | |||
return invokers.get(sequence.getAndIncrement() % length); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
good!!
@carryxyh it's okay and works well. |
@kimmking Have a look! I made a little change. |
@Override | ||
protected <T> Invoker<T> doSelect(List<Invoker<T>> invokers, URL url, Invocation invocation) { | ||
String key = invokers.get(0).getUrl().getServiceKey() + "." + invocation.getMethodName(); | ||
int length = invokers.size(); // Number of invokers | ||
int maxWeight = 0; // The maximum weight | ||
int minWeight = Integer.MAX_VALUE; // The minimum weight | ||
final LinkedHashMap<Invoker<T>, IntegerWrapper> invokerToWeightMap = new LinkedHashMap<Invoker<T>, IntegerWrapper>(); | ||
int weightSum = 0; | ||
final List<Invoker<T>> invokerToWeightList = new ArrayList<>(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The name invokerToWeightList
can be improved. I think weightedInvokerList
or nonZeroWeightedInvokers
should be better. :)
This pull request looks good to me. Nice work! |
great, I also writed some UT for it. we can PR our UTs after merging it. |
int currentWeight; | ||
if (index == 0) { | ||
currentWeight = sequence.incrementAndGet() % maxWeight; | ||
}else { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
space need:)
What is the purpose of the change
fix:#2578
Brief changelog
Optimize RoundRobinLoadBalance
Verifying this change
Follow this checklist to help us incorporate your contribution quickly and easily:
[Dubbo-XXX] Fix UnknownException when host config not exist #XXX
. Each commit in the pull request should have a meaningful subject line and body.mvn clean install -DskipTests
&mvn clean test-compile failsafe:integration-test
to make sure unit-test and integration-test pass.