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: Add least request balancer #6510

Merged
merged 9 commits into from Aug 11, 2023

Conversation

zasweq
Copy link
Contributor

@zasweq zasweq commented Aug 8, 2023

This PR adds the least request load balancer, speced in https://github.com/grpc/proposal/blob/master/A48-xds-least-request-lb-policy.md.

RELEASE NOTES:

  • balancer/leastrequest: Add least request balancer

@zasweq zasweq requested a review from dfawley August 8, 2023 02:26
@zasweq zasweq added the Type: Feature New features or improvements in behavior label Aug 8, 2023
@zasweq zasweq added this to the 1.58 Release milestone Aug 8, 2023
@zasweq zasweq changed the title balancer/leastrequest: Add least request balancer (draft) balancer/leastrequest: Add least request balancer Aug 10, 2023
Copy link
Member

@dfawley dfawley left a comment

Choose a reason for hiding this comment

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

I'll wait on reviewing the tests until the e2e-style ones are done.

balancer/leastrequest/leastrequest.go Outdated Show resolved Hide resolved
balancer/leastrequest/leastrequest.go Show resolved Hide resolved
balancer/leastrequest/leastrequest.go Outdated Show resolved Hide resolved
balancer/leastrequest/leastrequest.go Outdated Show resolved Hide resolved
balancer/leastrequest/leastrequest.go Outdated Show resolved Hide resolved
balancer/leastrequest/leastrequest.go Outdated Show resolved Hide resolved
balancer/leastrequest/leastrequest.go Show resolved Hide resolved
balancer/leastrequest/balancer_test.go Outdated Show resolved Hide resolved
balancer/leastrequest/balancer_test.go Outdated Show resolved Hide resolved
balancer/leastrequest/balancer_test.go Outdated Show resolved Hide resolved
balancer/leastrequest/balancer_test.go Outdated Show resolved Hide resolved
balancer/leastrequest/balancer_test.go Outdated Show resolved Hide resolved
balancer/leastrequest/balancer_test.go Show resolved Hide resolved
balancer/leastrequest/balancer_test.go Outdated Show resolved Hide resolved
balancer/leastrequest/balancer_test.go Outdated Show resolved Hide resolved
@zasweq zasweq assigned dfawley and unassigned dfawley Aug 11, 2023
Comment on lines 302 to 307
defer func() {
stream.CloseSend()
if _, err = stream.Recv(); err != io.EOF {
t.Fatalf("unexpected error: %v, expected an EOF error", err)
}
}()
Copy link
Member

Choose a reason for hiding this comment

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

I think we can just delete all of this and rely on ctx's cancelation to clean up everything.

Same with the other test. Just make the server's handler do a <-stream.Context().Done() instead of doing a stream.Recv() in a loop.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done.

stream.CloseSend() // Finish stream to populate peer.
if _, err = stream.Recv(); err != io.EOF {
t.Fatalf("unexpected error: %v, expected an EOF error", err)
defer func() {
Copy link
Member

Choose a reason for hiding this comment

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

Same

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done.

if err != nil {
t.Fatalf("testServiceClient.FullDuplexCall failed: %v", err)
}
defer func() {
Copy link
Member

Choose a reason for hiding this comment

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

Same

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done.

balancer/leastrequest/balancer_test.go Show resolved Hide resolved
@dfawley dfawley assigned zasweq and unassigned dfawley Aug 11, 2023
gotAddrCount[p.Addr.String()]++
}
}
if diff := cmp.Diff(gotAddrCount, wantAddrCount); diff != "" {
Copy link
Member

Choose a reason for hiding this comment

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

Nit: if you're not showing the diff, just use !cmp.Equal() instead. (Also in checkRoundRobin.)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Printed diff here. In check round robin no need for diff so just used !cmp.Equal().

Comment on lines +449 to +452
if !ok {
t.Fatalf("testServiceClient.FullDuplexCall has no Peer")
}
if p.Addr != nil {
Copy link
Member

Choose a reason for hiding this comment

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

Optional: IMO it's cleaner to remove the defensive programming and just let things panic if they're breaking assertions:

p, _ := peer.FromContext(stream.Context)
gotAddrCount[p.Addr.String()]++

But this is fine, too.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done.

@zasweq zasweq merged commit dbbc983 into grpc:master Aug 11, 2023
11 checks passed
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Feb 8, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Type: Feature New features or improvements in behavior
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants