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

xds: wrr with random #2745

Merged
merged 5 commits into from
Apr 23, 2019
Merged

xds: wrr with random #2745

merged 5 commits into from
Apr 23, 2019

Conversation

menghanl
Copy link
Contributor

@menghanl menghanl commented Apr 4, 2019

for drops and inter-locality picks

@menghanl menghanl changed the title xds: wrr xds: wrr with random Apr 4, 2019
@dfawley dfawley requested a review from lyuxuan April 11, 2019 20:12
@dfawley dfawley assigned dfawley and lyuxuan and unassigned dfawley Apr 11, 2019

package wrr

// WRR blah
Copy link
Contributor

Choose a reason for hiding this comment

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

It's better to document there what is wrr.

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 rw.sumOfWeights == 0 {
return nil
}
randomWeight := grpcrand.Int63n(rw.sumOfWeights)
Copy link
Contributor

Choose a reason for hiding this comment

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

Make a comment saying that grpcrand.Int63n generates an integer [0, rw.sumOfweights).

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

}
}

return rw.items[len(rw.items)-1].Item
Copy link
Contributor

Choose a reason for hiding this comment

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

I think this is not necessary. The for loop will cover all the cases.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Compiler will think this is missing a return.

import "google.golang.org/grpc/internal/grpcrand"

// randWeighted is a wrapped weighted item that is used to implement weighted random algorithm.
type randWeighted struct {
Copy link
Contributor

Choose a reason for hiding this comment

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

can we remove the "rand" prefix, and name it e.g. weightedItem? The struct itself is unrelated to randomness, it's just you currently only used it for the randomWRR.

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

//
// With {a: 2, b: 3}, the Next() results will be {a, a, b, b, b}.
type testWRR struct {
itemsWithWeight []struct {
Copy link
Contributor

Choose a reason for hiding this comment

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

You can reuse the randWeighted struct once you change the name.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

They are in different packages.

)

// testWRR is a deterministic WRR implementation.
Copy link
Contributor

Choose a reason for hiding this comment

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

Can you explain in the comment why we need the deterministic WRR implementation for testing?

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

for drops and inter-locality picks
)

// testWRR is a deterministic WRR implementation. With this, the balancer
Copy link
Contributor

Choose a reason for hiding this comment

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

How about adding that the real implementation is non-deterministic, and it is covered by unit testing. And here, we use the deterministic implementation to test logic beyond the non-deterministic part.

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

package wrr

// WRR defines an interface that implements weighted round robin.
type WRR interface {
Copy link
Contributor

Choose a reason for hiding this comment

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

Does WRR need to be thread safe? Or if there's a guarantee that Add or Next won't be called concurrently. It's better to document here clearly.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Next() needs to be thread safe.

Add() I'm not sure. I'm leaving it undocumented. Will add more requirements when adding new implementations.

@menghanl menghanl merged commit a8b5bd3 into grpc:master Apr 23, 2019
@menghanl menghanl deleted the drop_wrr_random branch April 23, 2019 20:48
@lock lock bot locked as resolved and limited conversation to collaborators Oct 20, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants