-
Notifications
You must be signed in to change notification settings - Fork 4.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
balancer/leastrequest: Cache atomic load and also add concurrent rpc test #6602
Conversation
continue | ||
} | ||
if sc.numRPCs.Load() < pickedSC.numRPCs.Load() { | ||
if sc.numRPCs.Load() < pickedSCNumRPCs { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should sc.numRPCS.Load()
be cached too? to save one more Load
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh good point. Switched.
scNumRPCs := sc.numRPCs.Load() | ||
if scNumRPCs < pickedSCNumRPCs { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Optional: these can be merged into a compound if if desired. Or even simpler:
sc := p.subConns[index]
n := sc.numRPCs.Load()
if pickedSC == nil || n < pickedSCNumRPCs {
pickedSC = &sc
pickedSCNumRPCs = n
}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah, beautiful suggestion :D. I tried breaking it but it works and is much cleaner. Thanks.
wg.Add(1) | ||
go func() { | ||
defer wg.Done() | ||
testServiceClient.EmptyCall(ctx, &testpb.Empty{}) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should these do several calls each, maybe, to make concurrent pick calls more likely? Just make sure it doesn't run too long.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good point. Made each goroutine perform 5 calls.
This PR caches the atomic load of the picked SubConn in the picker algorithm in least request picker for efficiency reasons, rather than doing it per iteration. It also adds an e2e test which performs concurrent RPCs to check for a race condition.
Continuation of #6587. Needs to be backported to 1.58 alongside that bug fix PR.
RELEASE NOTES: N/A