frozenNoob opened a new pull request, #15666: URL: https://github.com/apache/dubbo/pull/15666
## What is the purpose of the change? Fix the issue:In multi-threaded parallel execution, a large number of read only operations waste a lot of unnecessary time because the combination of "read and write" operations requires "serialization issue link: https://github.com/apache/dubbo/issues/15665 ## My Solution Issue 1 must be solved, Issue 2 can be tolerated, but I currently cannot think of an efficient solution for Issue 3 which can be solved by triggering subsequent fault-tolerance and retry mechanisms. My proposed solution is as follows: allow a large number of read-only operations to proceed in parallel (memory visibility is guaranteed because the `value` field in the inner class `Node` of `ConcurrentHashMap` is `volatile`), and terminate early via detection. Related code is as follows: ```java @SuppressWarnings("unchecked") @Override protected <T> Invoker<T> doSelect(List<Invoker<T>> invokers, URL url, Invocation invocation) { String methodName = RpcUtils.getMethodName(invocation); String key = invokers.get(0).getUrl().getServiceKey() + "." + methodName; int invokersHashCode = invokers.hashCode(); // If the detection is successful, return in advance. it may be different from selector, but it doesn't matter ConsistentHashSelector<?> oldSelector0; if((oldSelector0 = selectors.get(key)) != null && oldSelector0.identityHashCode == invokersHashCode){ return oldSelector0.select(invocation); } // using the hashcode of invoker list to create consistent selector by atomic computation. ConsistentHashSelector<T> selector = (ConsistentHashSelector<T>) selectors.compute( key, (k, oldSelector) -> (oldSelector == null || oldSelector.identityHashCode != invokersHashCode) ? new ConsistentHashSelector<>(invokers, methodName, invokersHashCode) : oldSelector); return selector.select(invocation); } ``` ## Checklist - [x] Make sure there is a [GitHub_issue](https://github.com/apache/dubbo/issues) field for the change. - [x] Write a pull request description that is detailed enough to understand what the pull request does, how, and why. - [ ] Write necessary unit-test to verify your logic correction. If the new feature or significant change is committed, please remember to add sample in [dubbo samples](https://github.com/apache/dubbo-samples) project. - [x] Make sure gitHub actions can pass. [Why the workflow is failing and how to fix it?](../CONTRIBUTING.md) -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected] --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
