You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@dubbo.apache.org by "HarshMehta112 (via GitHub)" <gi...@apache.org> on 2026/06/13 09:07:00 UTC
[PR] perf(loadbalance): reuse timestamp when computing invoker weights [dubbo-go]
HarshMehta112 opened a new pull request, #3410:
URL: https://github.com/apache/dubbo-go/pull/3410
Fixes : #3408
### Description
Add `GetWeightAt(invoker, invocation, now int64)` alongside the existing
`GetWeight` function. Load balance strategies that loop over all invokers in
a single `Select` previously called `time.Now().Unix()` once per invoker
inside `GetWeight`, repeating the same syscall N times and allowing the
warmup calculation to drift slightly within a single selection.
`GetWeight` is preserved unchanged as a thin wrapper, keeping the public API
fully compatible. The following strategies now compute `now` once per `Select`
and forward it via `GetWeightAt`: `random`, `roundrobin`, `leastactive`,
`aliasmethod`, and `iwrr` (init path).
Benchmark (Apple M4 Pro, 255 invokers):
| Benchmark | ns/op | B/op | allocs/op |
|--------------------|-------|------|-----------|
| BenchmarkGetWeight | 120.0 | 192 | 4 |
| BenchmarkGetWeightAt | 96.2 | 192 | 4 |
~20% reduction per weight lookup; savings scale linearly with invoker count.
Fixes # (issue)
### Checklist
- [x] I confirm the target branch is `develop`
- [x] Code has passed local testing
- [x] I have added tests that prove my fix is effective or that my feature works
--
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] perf(loadbalance): reuse timestamp when computing invoker weights [dubbo-go]
Posted by "sonarqubecloud[bot] (via GitHub)" <gi...@apache.org>.
sonarqubecloud[bot] commented on PR #3410:
URL: https://github.com/apache/dubbo-go/pull/3410#issuecomment-4698081489
## [](https://sonarcloud.io/dashboard?id=apache_dubbo-go&pullRequest=3410) **Quality Gate passed**
Issues
 [0 New issues](https://sonarcloud.io/project/issues?id=apache_dubbo-go&pullRequest=3410&issueStatuses=OPEN,CONFIRMED&sinceLeakPeriod=true)
 [0 Accepted issues](https://sonarcloud.io/project/issues?id=apache_dubbo-go&pullRequest=3410&issueStatuses=ACCEPTED)
Measures
 [0 Security Hotspots](https://sonarcloud.io/project/security_hotspots?id=apache_dubbo-go&pullRequest=3410&issueStatuses=OPEN,CONFIRMED&sinceLeakPeriod=true)
 [0.0% Coverage on New Code](https://sonarcloud.io/component_measures?id=apache_dubbo-go&pullRequest=3410&metric=new_coverage&view=list)
 [0.0% Duplication on New Code](https://sonarcloud.io/component_measures?id=apache_dubbo-go&pullRequest=3410&metric=new_duplicated_lines_density&view=list)
<!-- sqra-placement-anchor -->
[See analysis details on SonarQube Cloud](https://sonarcloud.io/dashboard?id=apache_dubbo-go&pullRequest=3410)
--
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] perf(loadbalance): reuse timestamp when computing invoker weights [dubbo-go]
Posted by "Alanxtl (via GitHub)" <gi...@apache.org>.
Alanxtl commented on PR #3410:
URL: https://github.com/apache/dubbo-go/pull/3410#issuecomment-4698517175
pls comment in the issue before summiting pr
--
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] perf(loadbalance): reuse timestamp when computing invoker weights [dubbo-go]
Posted by "HarshMehta112 (via GitHub)" <gi...@apache.org>.
HarshMehta112 commented on PR #3410:
URL: https://github.com/apache/dubbo-go/pull/3410#issuecomment-4698672832
> pls comment in the issue before summiting pr
I will take care of this from next time
--
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] perf(loadbalance): reuse timestamp when computing invoker weights [dubbo-go]
Posted by "Copilot (via GitHub)" <gi...@apache.org>.
Copilot commented on code in PR #3410:
URL: https://github.com/apache/dubbo-go/pull/3410#discussion_r3409088443
##########
cluster/loadbalance/util.go:
##########
@@ -28,7 +28,14 @@ import (
// GetWeight returns the weight for the load‑balancing strategy.
func GetWeight(invoker base.Invoker, invocation base.Invocation) int64 {
+ return GetWeightAt(invoker, invocation, time.Now().Unix())
+}
Review Comment:
`GetWeight` now always evaluates `time.Now().Unix()` before it knows whether warmup logic will run. Previously, the time lookup only happened when `weight > 0`, so this wrapper introduces an extra syscall for zero/negative weights and is not fully equivalent to the prior behavior.
##########
cluster/loadbalance/util.go:
##########
@@ -46,7 +53,6 @@ func GetWeight(invoker base.Invoker, invocation base.Invocation) int64 {
// Warm‑up adjustment (same logic as before).
if weight > 0 {
- now := time.Now().Unix()
ts := url.GetParamInt(constant.RemoteTimestampKey, now)
if uptime := now - ts; uptime > 0 {
warm := url.GetParamInt(constant.WarmupKey, constant.DefaultWarmup)
Review Comment:
`GetWeightAt` assumes `now` is a valid Unix timestamp. If `GetWeight` is adjusted to pass a sentinel (e.g., 0) to avoid unnecessary time lookups, `GetWeightAt` should lazily populate `now` before using it in warmup calculations to preserve the previous semantics.
--
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] perf(loadbalance): reuse timestamp when computing invoker weights [dubbo-go]
Posted by "codecov-commenter (via GitHub)" <gi...@apache.org>.
codecov-commenter commented on PR #3410:
URL: https://github.com/apache/dubbo-go/pull/3410#issuecomment-4698086359
## [Codecov](https://app.codecov.io/gh/apache/dubbo-go/pull/3410?dropdown=coverage&src=pr&el=h1&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) Report
:x: Patch coverage is `83.33333%` with `2 lines` in your changes missing coverage. Please review.
:white_check_mark: Project coverage is 53.17%. Comparing base ([`a7b6ee6`](https://app.codecov.io/gh/apache/dubbo-go/commit/a7b6ee632a2d2e4c908cd5c10434d062c5040fe8?dropdown=coverage&el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache)) to head ([`7588ba1`](https://app.codecov.io/gh/apache/dubbo-go/commit/7588ba1227d590c6778b176d1316f7aaecaec030?dropdown=coverage&el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache)).
| [Files with missing lines](https://app.codecov.io/gh/apache/dubbo-go/pull/3410?dropdown=coverage&src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) | Patch % | Lines |
|---|---|---|
| [cluster/loadbalance/util.go](https://app.codecov.io/gh/apache/dubbo-go/pull/3410?src=pr&el=tree&filepath=cluster%2Floadbalance%2Futil.go&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache#diff-Y2x1c3Rlci9sb2FkYmFsYW5jZS91dGlsLmdv) | 0.00% | [2 Missing :warning: ](https://app.codecov.io/gh/apache/dubbo-go/pull/3410?src=pr&el=tree&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 #3410 +/- ##
===========================================
- Coverage 53.17% 53.17% -0.01%
===========================================
Files 493 493
Lines 38245 38251 +6
===========================================
+ Hits 20338 20341 +3
- Misses 16271 16273 +2
- Partials 1636 1637 +1
```
</details>
[:umbrella: View full report in Codecov by Harness](https://app.codecov.io/gh/apache/dubbo-go/pull/3410?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.
</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] perf(loadbalance): reuse timestamp when computing invoker weights [dubbo-go]
Posted by "Alanxtl (via GitHub)" <gi...@apache.org>.
Alanxtl merged PR #3410:
URL: https://github.com/apache/dubbo-go/pull/3410
--
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