Skip to content
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

Merged
merged 3 commits into from Sep 5, 2023

Conversation

zasweq
Copy link
Contributor

@zasweq zasweq commented Aug 31, 2023

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

@zasweq zasweq requested a review from dfawley August 31, 2023 23:10
@zasweq zasweq added the Type: Internal Cleanup Refactors, etc label Aug 31, 2023
@zasweq zasweq added this to the 1.58 Release milestone Aug 31, 2023
continue
}
if sc.numRPCs.Load() < pickedSC.numRPCs.Load() {
if sc.numRPCs.Load() < pickedSCNumRPCs {
Copy link
Contributor

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

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Oh good point. Switched.

Comment on lines 167 to 168
scNumRPCs := sc.numRPCs.Load()
if scNumRPCs < pickedSCNumRPCs {
Copy link
Member

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
}

Copy link
Contributor Author

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{})
Copy link
Member

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.

Copy link
Contributor Author

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.

@zasweq zasweq merged commit 1e0d82e into grpc:master Sep 5, 2023
11 checks passed
arvindbr8 pushed a commit to arvindbr8/grpc-go that referenced this pull request Sep 5, 2023
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Mar 4, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants