Skip to content

Conversation

@frozenNoob
Copy link
Contributor

@frozenNoob frozenNoob commented Sep 2, 2025

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: #15665

My Solution

Issue 1 must be solved, Issue 2 can be tolerated.
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:

@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<T> oldSelector0;
        if((oldSelector0 = (ConsistentHashSelector<T>) 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

  • Make sure there is a GitHub_issue field for the change.
  • 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 project.
  • Make sure gitHub actions can pass. Why the workflow is failing and how to fix it?

@codecov-commenter
Copy link

codecov-commenter commented Sep 17, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 61.01%. Comparing base (b869c2c) to head (2619195).

Additional details and impacted files
@@             Coverage Diff              @@
##                3.3   #15666      +/-   ##
============================================
- Coverage     61.02%   61.01%   -0.02%     
- Complexity    11702    11708       +6     
============================================
  Files          1923     1923              
  Lines         87074    87077       +3     
  Branches      13112    13114       +2     
============================================
- Hits          53134    53127       -7     
- Misses        28490    28500      +10     
  Partials       5450     5450              
Flag Coverage Δ
integration-tests-java21 32.91% <0.00%> (-0.01%) ⬇️
integration-tests-java8 33.03% <0.00%> (+0.07%) ⬆️
samples-tests-java21 32.65% <0.00%> (+0.01%) ⬆️
samples-tests-java8 30.30% <0.00%> (-0.06%) ⬇️
unit-tests-java11 59.00% <100.00%> (-0.01%) ⬇️
unit-tests-java17 58.74% <100.00%> (-0.02%) ⬇️
unit-tests-java21 58.74% <100.00%> (-0.01%) ⬇️
unit-tests-java8 58.98% <100.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.

@zrlw zrlw added the type/enhancement Everything related with code enhancement or performance label Sep 18, 2025
@zrlw zrlw requested review from RainYuY, oxsean and zrlw September 18, 2025 07:46
@zrlw
Copy link
Contributor

zrlw commented Sep 18, 2025

LGTM

@zrlw zrlw requested a review from EarthChen September 23, 2025 11:57
Copy link
Member

@EarthChen EarthChen left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@EarthChen EarthChen merged commit 8f2b4de into apache:3.3 Sep 24, 2025
32 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

type/enhancement Everything related with code enhancement or performance

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants