You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@dubbo.apache.org by "mochengqian (via GitHub)" <gi...@apache.org> on 2026/05/06 04:05:13 UTC

[PR] fix(cluster): switch cluster lookup to runtime map [dubbo-go-pixiu]

mochengqian opened a new pull request, #923:
URL: https://github.com/apache/dubbo-go-pixiu/pull/923

   ### Description
   
   Implements Issue #905 Step 4 only: switch cluster lookup to O(1).
   
   Issue #905 step progress:
   - [x] Add tests and benchmarks
   - [x] Fix current correctness issues
   - [x] Tighten runtime consistency
   - [x] Switch cluster lookup to O(1)
   - [ ] Introduce healthy endpoint snapshots
   - [ ] Optimize simple LB hot path
   - [ ] Optimize consistent-hash LB last
   
   ### Why
   
   `ClusterManager` read paths still resolve clusters by scanning `store.Config`.
   
   After Step 3, `clustersMap` is now maintained as the coherent runtime cluster source: write paths keep `clustersMap[name].Config` aligned with the current cluster config, repair stale runtime entries during store swap, and stop replaced runtime clusters.
   
   That makes this PR the narrow next step: move cluster lookup on request read paths from O(n) config scanning to O(1) runtime map lookup.
   
   ### Root Cause:
   
   `ClusterManager.getCluster()` still iterated over `store.Config` by cluster name.
   
   That means `PickEndpoint()`, `PickNextEndpoint()`, and `GetEndpointByID()` paid linear lookup cost before reaching load balancing or endpoint selection logic.
   
   ### PR Goal:
   
   Use `clustersMap` as the runtime lookup source for cluster read paths.
   
   Keep public behavior unchanged while making cluster name resolution O(1).
   
   ### Success Criteria:
   
   `PickEndpoint()` no longer linearly scans `store.Config` to find a cluster.
   
   `PickNextEndpoint()` no longer linearly scans `store.Config` to find a cluster.
   
   `GetEndpointByID()` follows the same runtime lookup path.
   
   Missing clusters still return `nil`.
   
   Existing load-balancer behavior is unchanged.
   
   ### Paths this PR should affect:
   
   pkg/server/cluster_manager.go
   
   pkg/server/cluster_manager_test.go
   
   ### Revise
   
   Changing `getCluster`: lookup `cm.store.clustersMap[clusterName]` and return `runtimeCluster.Config`.
   
   Adding regression tests: proves `PickEndpoint`, `PickNextEndpoint`, and `GetEndpointByID` use runtime map state even when `store.Config` contains stale config data.
   
   ### Benchmark Evidence
   
   Command:
   
   `go test ./pkg/server -run '^$' -bench '^BenchmarkClusterLookupSerial$' -benchmem -count=3`
   
   The table below uses the average of 3 local benchmark runs, comparing `upstream/develop` with this branch:
   
   | Cluster count | Before avg | After avg | Meaning |
   | --- | ---: | ---: | --- |
   | 1 | ~3.36 ns/op | ~4.70 ns/op | map lookup has tiny fixed overhead |
   | 32 | ~18.38 ns/op | ~6.75 ns/op | no longer grows with cluster scan cost |
   | 256 | ~115.60 ns/op | ~6.73 ns/op | lookup cost stays nearly flat |
   | 1024 | ~780.87 ns/op | ~7.23 ns/op | O(n) scan removed |
   
   Both before and after remain `0 B/op, 0 allocs/op`.
   
   The single-cluster case is slightly slower because a map lookup has more fixed overhead than scanning one item, but the issue target is multi-cluster request-path scalability. At 1024 clusters, lookup drops from hundreds of ns/op to single-digit ns/op and stays effectively flat as cluster count grows.
   
   ### Tests
   
   `go test ./pkg/server`
   
   `go test ./pkg/cluster/...`
   
   `go test -race ./pkg/server -run 'TestClusterManager'`
   
   `go test ./pkg/server -run '^$' -bench '^BenchmarkClusterLookupSerial$' -benchmem -count=3`


-- 
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: notifications-unsubscribe@dubbo.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@dubbo.apache.org
For additional commands, e-mail: notifications-help@dubbo.apache.org


Re: [PR] fix(cluster): switch cluster lookup to runtime map [dubbo-go-pixiu]

Posted by "codecov-commenter (via GitHub)" <gi...@apache.org>.
codecov-commenter commented on PR #923:
URL: https://github.com/apache/dubbo-go-pixiu/pull/923#issuecomment-4385390118

   ## [Codecov](https://app.codecov.io/gh/apache/dubbo-go-pixiu/pull/923?dropdown=coverage&src=pr&el=h1&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) Report
   :white_check_mark: All modified and coverable lines are covered by tests.
   :white_check_mark: Project coverage is 22.44%. Comparing base ([`55c6210`](https://app.codecov.io/gh/apache/dubbo-go-pixiu/commit/55c62109a5f73633ce4755cbd0a8c92f4980c5fd?dropdown=coverage&el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache)) to head ([`844abf4`](https://app.codecov.io/gh/apache/dubbo-go-pixiu/commit/844abf445d72159c492ec64b27f655bbedd66a12?dropdown=coverage&el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache)).
   
   <details><summary>Additional details and impacted files</summary>
   
   
   
   ```diff
   @@             Coverage Diff             @@
   ##           develop     #923      +/-   ##
   ===========================================
   + Coverage    22.38%   22.44%   +0.05%     
   ===========================================
     Files          272      272              
     Lines        20459    20459              
   ===========================================
   + Hits          4580     4592      +12     
   + Misses       15422    15407      -15     
   - Partials       457      460       +3     
   ```
   
   | [Flag](https://app.codecov.io/gh/apache/dubbo-go-pixiu/pull/923/flags?src=pr&el=flags&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) | Coverage Δ | |
   |---|---|---|
   | [unittests](https://app.codecov.io/gh/apache/dubbo-go-pixiu/pull/923/flags?src=pr&el=flag&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) | `22.44% <100.00%> (+0.05%)` | :arrow_up: |
   
   Flags with carried forward coverage won't be shown. [Click here](https://docs.codecov.io/docs/carryforward-flags?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache#carryforward-flags-in-the-pull-request-comment) to find out more.
   </details>
   
   [:umbrella: View full report in Codecov by Sentry](https://app.codecov.io/gh/apache/dubbo-go-pixiu/pull/923?dropdown=coverage&src=pr&el=continue&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache).   
   :loudspeaker: Have feedback on the report? [Share it here](https://about.codecov.io/codecov-pr-comment-feedback/?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache).
   <details><summary> :rocket: New features to boost your workflow: </summary>
   
   - :snowflake: [Test Analytics](https://docs.codecov.com/docs/test-analytics): Detect flaky tests, report on failures, and find test suite problems.
   - :package: [JS Bundle Analysis](https://docs.codecov.com/docs/javascript-bundle-analysis): Save yourself from yourself by tracking and limiting bundle sizes in JS merges.
   </details>


-- 
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: notifications-unsubscribe@dubbo.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@dubbo.apache.org
For additional commands, e-mail: notifications-help@dubbo.apache.org


Re: [PR] fix(cluster): switch cluster lookup to runtime map [dubbo-go-pixiu]

Posted by "sonarqubecloud[bot] (via GitHub)" <gi...@apache.org>.
sonarqubecloud[bot] commented on PR #923:
URL: https://github.com/apache/dubbo-go-pixiu/pull/923#issuecomment-4385003563

   ## [![Quality Gate Passed](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/checks/QualityGateBadge/qg-passed-20px.png 'Quality Gate Passed')](https://sonarcloud.io/dashboard?id=apache_dubbo-go-pixiu&pullRequest=923) **Quality Gate passed**  
   Issues  
   ![](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/common/passed-16px.png '') [0 New issues](https://sonarcloud.io/project/issues?id=apache_dubbo-go-pixiu&pullRequest=923&issueStatuses=OPEN,CONFIRMED&sinceLeakPeriod=true)  
   ![](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/common/accepted-16px.png '') [0 Accepted issues](https://sonarcloud.io/project/issues?id=apache_dubbo-go-pixiu&pullRequest=923&issueStatuses=ACCEPTED)
   
   Measures  
   ![](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/common/passed-16px.png '') [0 Security Hotspots](https://sonarcloud.io/project/security_hotspots?id=apache_dubbo-go-pixiu&pullRequest=923&issueStatuses=OPEN,CONFIRMED&sinceLeakPeriod=true)  
   ![](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/common/passed-16px.png '') [0.0% Coverage on New Code](https://sonarcloud.io/component_measures?id=apache_dubbo-go-pixiu&pullRequest=923&metric=new_coverage&view=list)  
   ![](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/common/passed-16px.png '') [0.0% Duplication on New Code](https://sonarcloud.io/component_measures?id=apache_dubbo-go-pixiu&pullRequest=923&metric=new_duplicated_lines_density&view=list)  
     
   [See analysis details on SonarQube Cloud](https://sonarcloud.io/dashboard?id=apache_dubbo-go-pixiu&pullRequest=923)
   
   


-- 
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: notifications-unsubscribe@dubbo.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@dubbo.apache.org
For additional commands, e-mail: notifications-help@dubbo.apache.org


Re: [PR] fix(cluster): switch cluster lookup to runtime map [dubbo-go-pixiu]

Posted by "sonarqubecloud[bot] (via GitHub)" <gi...@apache.org>.
sonarqubecloud[bot] commented on PR #923:
URL: https://github.com/apache/dubbo-go-pixiu/pull/923#issuecomment-4386783677

   ## [![Quality Gate Passed](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/checks/QualityGateBadge/qg-passed-20px.png 'Quality Gate Passed')](https://sonarcloud.io/dashboard?id=apache_dubbo-go-pixiu&pullRequest=923) **Quality Gate passed**  
   Issues  
   ![](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/common/passed-16px.png '') [0 New issues](https://sonarcloud.io/project/issues?id=apache_dubbo-go-pixiu&pullRequest=923&issueStatuses=OPEN,CONFIRMED&sinceLeakPeriod=true)  
   ![](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/common/accepted-16px.png '') [0 Accepted issues](https://sonarcloud.io/project/issues?id=apache_dubbo-go-pixiu&pullRequest=923&issueStatuses=ACCEPTED)
   
   Measures  
   ![](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/common/passed-16px.png '') [0 Security Hotspots](https://sonarcloud.io/project/security_hotspots?id=apache_dubbo-go-pixiu&pullRequest=923&issueStatuses=OPEN,CONFIRMED&sinceLeakPeriod=true)  
   ![](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/common/passed-16px.png '') [0.0% Coverage on New Code](https://sonarcloud.io/component_measures?id=apache_dubbo-go-pixiu&pullRequest=923&metric=new_coverage&view=list)  
   ![](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/common/passed-16px.png '') [0.0% Duplication on New Code](https://sonarcloud.io/component_measures?id=apache_dubbo-go-pixiu&pullRequest=923&metric=new_duplicated_lines_density&view=list)  
     
   <!-- sqra-placement-anchor -->
   [See analysis details on SonarQube Cloud](https://sonarcloud.io/dashboard?id=apache_dubbo-go-pixiu&pullRequest=923)
   
   


-- 
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: notifications-unsubscribe@dubbo.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@dubbo.apache.org
For additional commands, e-mail: notifications-help@dubbo.apache.org


Re: [PR] fix(cluster): switch cluster lookup to runtime map [dubbo-go-pixiu]

Posted by "Alanxtl (via GitHub)" <gi...@apache.org>.
Alanxtl commented on PR #923:
URL: https://github.com/apache/dubbo-go-pixiu/pull/923#issuecomment-4385449203

   pls merge to main to fix ci fail


-- 
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: notifications-unsubscribe@dubbo.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@dubbo.apache.org
For additional commands, e-mail: notifications-help@dubbo.apache.org


Re: [PR] fix(cluster): switch cluster lookup to runtime map [dubbo-go-pixiu]

Posted by "Alanxtl (via GitHub)" <gi...@apache.org>.
Alanxtl merged PR #923:
URL: https://github.com/apache/dubbo-go-pixiu/pull/923


-- 
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: notifications-unsubscribe@dubbo.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@dubbo.apache.org
For additional commands, e-mail: notifications-help@dubbo.apache.org