Skip to content

Commit 8f2b4de

Browse files
frozenNoobzrlw
andauthored
End the 'read/write' combination operation early to improve performance (#15666)
Co-authored-by: zrlw <zrlw@sina.com>
1 parent f6b78d2 commit 8f2b4de

File tree

1 file changed

+7
-0
lines changed

1 file changed

+7
-0
lines changed

dubbo-cluster/src/main/java/org/apache/dubbo/rpc/cluster/loadbalance/ConsistentHashLoadBalance.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,13 @@ protected <T> Invoker<T> doSelect(List<Invoker<T>> invokers, URL url, Invocation
5151
String methodName = RpcUtils.getMethodName(invocation);
5252
String key = invokers.get(0).getUrl().getServiceKey() + "." + methodName;
5353
int invokersHashCode = invokers.hashCode();
54+
// If the detection is successful, return in advance. it may be different from selector, but it doesn't matter
55+
ConsistentHashSelector<T> oldSelector0;
56+
if ((oldSelector0 = (ConsistentHashSelector<T>) selectors.get(key)) != null
57+
&& oldSelector0.identityHashCode == invokersHashCode) {
58+
return oldSelector0.select(invocation);
59+
}
60+
5461
// using the hashcode of invoker list to create consistent selector by atomic computation.
5562
ConsistentHashSelector<T> selector = (ConsistentHashSelector<T>) selectors.compute(
5663
key,

0 commit comments

Comments
 (0)