This is an automated email from the ASF dual-hosted git repository.
kimmking pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-dubbo.git
The following commit(s) were added to refs/heads/master by this push:
new 5e60bef Optimize the doSelect method of RandomLoadBalance to reduce
the times of invoke of the getWeight method of the AbstractLoadBalance (#2597)
5e60bef is described below
commit 5e60beff91319ec11946d27558e65483f143b0cb
Author: tswstarplanet <[email protected]>
AuthorDate: Sun Oct 21 23:04:30 2018 +0800
Optimize the doSelect method of RandomLoadBalance to reduce the times of
invoke of the getWeight method of the AbstractLoadBalance (#2597)
---
.../apache/dubbo/rpc/cluster/loadbalance/RandomLoadBalance.java | 8 ++++----
1 file changed, 4 insertions(+), 4 deletions(-)
diff --git
a/dubbo-cluster/src/main/java/org/apache/dubbo/rpc/cluster/loadbalance/RandomLoadBalance.java
b/dubbo-cluster/src/main/java/org/apache/dubbo/rpc/cluster/loadbalance/RandomLoadBalance.java
index 90bc60c..eea0ca3 100644
---
a/dubbo-cluster/src/main/java/org/apache/dubbo/rpc/cluster/loadbalance/RandomLoadBalance.java
+++
b/dubbo-cluster/src/main/java/org/apache/dubbo/rpc/cluster/loadbalance/RandomLoadBalance.java
@@ -34,13 +34,13 @@ public class RandomLoadBalance extends AbstractLoadBalance {
@Override
protected <T> Invoker<T> doSelect(List<Invoker<T>> invokers, URL url,
Invocation invocation) {
int length = invokers.size(); // Number of invokers
- int totalWeight = 0; // The sum of weights
boolean sameWeight = true; // Every invoker has the same weight?
- for (int i = 0; i < length; i++) {
+ int firstWeight = getWeight(invokers.get(0), invocation);
+ int totalWeight = firstWeight; // The sum of weights
+ for (int i = 1; i < length; i++) {
int weight = getWeight(invokers.get(i), invocation);
totalWeight += weight; // Sum
- if (sameWeight && i > 0
- && weight != getWeight(invokers.get(i - 1), invocation)) {
+ if (sameWeight && weight != firstWeight) {
sameWeight = false;
}
}