-
Notifications
You must be signed in to change notification settings - Fork 4.7k
*: Implementation of weighted random shuffling (A113) #8864
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
Merged
Merged
Changes from 6 commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
6f9d9cf
simplify the implementation of groupLocalitiesByPriority
easwars 633fab8
Remove code that handles localities and endpoints of weight 0.
easwars 3bd5a7d
add the env var GRPC_EXPERIMENTAL_PF_WEIGHTED_SHUFFLING
easwars 3a582da
Weight computation changes in cluster_resolver LB policy
easwars aaa9d86
Fix a broken test in ring_hash due to the new weight computation
easwars d4d3d88
Weighted shuffling in pick_first
easwars fa17114
first round of review comments from Arjan
easwars 3f4487d
second round of review comments from Arjan
easwars File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -1240,29 +1240,30 @@ func (s) TestRingHash_UnsupportedHashPolicyUntilChannelIdHashing(t *testing.T) { | |
| // Tests that ring hash policy that hashes using a random value can spread RPCs | ||
| // across all the backends according to locality weight. | ||
| func (s) TestRingHash_RandomHashingDistributionAccordingToLocalityAndEndpointWeight(t *testing.T) { | ||
| testutils.SetEnvConfig(t, &envconfig.PickFirstWeightedShuffling, true) | ||
| backends := backendAddrs(startTestServiceBackends(t, 2)) | ||
|
|
||
| const clusterName = "cluster" | ||
| const locality1Weight = uint32(1) | ||
| const endpoint1Weight = uint32(1) | ||
| const locality2Weight = uint32(2) | ||
| const endpoint2Weight = uint32(2) | ||
| const locality0Weight = uint32(1) | ||
|
arjan-bal marked this conversation as resolved.
|
||
| const endpoint0Weight = uint32(1) | ||
| const locality1Weight = uint32(2) | ||
| const endpoint1Weight = uint32(2) | ||
| endpoints := e2e.EndpointResourceWithOptions(e2e.EndpointOptions{ | ||
| ClusterName: clusterName, | ||
| Localities: []e2e.LocalityOptions{ | ||
| { | ||
| Backends: []e2e.BackendOptions{{ | ||
| Ports: []uint32{testutils.ParsePort(t, backends[0])}, | ||
| Weight: endpoint1Weight, | ||
| Weight: endpoint0Weight, | ||
| }}, | ||
| Weight: locality1Weight, | ||
| Weight: locality0Weight, | ||
| }, | ||
| { | ||
| Backends: []e2e.BackendOptions{{ | ||
| Ports: []uint32{testutils.ParsePort(t, backends[1])}, | ||
| Weight: endpoint2Weight, | ||
| Weight: endpoint1Weight, | ||
| }}, | ||
| Weight: locality2Weight, | ||
| Weight: locality1Weight, | ||
| }, | ||
| }, | ||
| }) | ||
|
|
@@ -1289,21 +1290,19 @@ func (s) TestRingHash_RandomHashingDistributionAccordingToLocalityAndEndpointWei | |
| defer conn.Close() | ||
| client := testgrpc.NewTestServiceClient(conn) | ||
|
|
||
| const weight1 = endpoint1Weight * locality1Weight | ||
| const weight2 = endpoint2Weight * locality2Weight | ||
| const wantRPCs1 = float64(weight1) / float64(weight1+weight2) | ||
| const wantRPCs2 = float64(weight2) / float64(weight1+weight2) | ||
| numRPCs := computeIdealNumberOfRPCs(t, math.Min(wantRPCs1, wantRPCs2), errorTolerance) | ||
| const wantRPCs0 = float64(1) / float64(3) | ||
|
arjan-bal marked this conversation as resolved.
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. FWIW you only need to float64 either the numerator or the denominator. |
||
| const wantRPCs1 = float64(2) / float64(3) | ||
| numRPCs := computeIdealNumberOfRPCs(t, math.Min(wantRPCs0, wantRPCs1), errorTolerance) | ||
|
|
||
| // Send a large number of RPCs and check that they are distributed randomly. | ||
| gotPerBackend := checkRPCSendOK(ctx, t, client, numRPCs) | ||
| got := float64(gotPerBackend[backends[0]]) / float64(numRPCs) | ||
| if !cmp.Equal(got, wantRPCs1, cmpopts.EquateApprox(0, errorTolerance)) { | ||
| t.Errorf("Fraction of RPCs to backend %s: got %v, want %v (margin: +-%v)", backends[2], got, wantRPCs1, errorTolerance) | ||
| if !cmp.Equal(got, wantRPCs0, cmpopts.EquateApprox(0, errorTolerance)) { | ||
| t.Errorf("Fraction of RPCs to backend %s: got %v, want %v (margin: +-%v)", backends[0], got, wantRPCs0, errorTolerance) | ||
| } | ||
| got = float64(gotPerBackend[backends[1]]) / float64(numRPCs) | ||
| if !cmp.Equal(got, wantRPCs2, cmpopts.EquateApprox(0, errorTolerance)) { | ||
| t.Errorf("Fraction of RPCs to backend %s: got %v, want %v (margin: +-%v)", backends[2], got, wantRPCs2, errorTolerance) | ||
| if !cmp.Equal(got, wantRPCs1, cmpopts.EquateApprox(0, errorTolerance)) { | ||
| t.Errorf("Fraction of RPCs to backend %s: got %v, want %v (margin: +-%v)", backends[1], got, wantRPCs1, errorTolerance) | ||
| } | ||
| } | ||
|
|
||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
We should continue cloning the endpoints list here. Directly mutating the
ResolverStatecan lead to data races if the caller ofUpdateClientConnStatereads the state concurrently. It would also be helpful to add a comment explaining this to prevent the accidental removal of the copy in the future.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.
Done.
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.
Argh. I feel like we need to either make
resolver.State.Endpointsan immutable type (EndpointList) or guarantee it's deeply copied whenresolver.Stateis copied.