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

Improve Client Side Weighted Round Robin lb policy. #37127

Merged
merged 6 commits into from
Nov 21, 2024

Conversation

efimki
Copy link
Contributor

@efimki efimki commented Nov 13, 2024

  • Track whether updateWeightsOnHosts() changes any host weights and applyWeightsToAllWorkers() if necessary.
  • Use thread local storage to track callbacks to worker-local load balancers and use runOnAllThreads to refresh them to apply the new weights.
  • Update weights on hosts when new hosts are added, so they get reasonable initial weight.
  • Calculate median weight of even number of valid hosts as an average of two weights closest to the median.

Risk Level: Low
Testing: bazel test //test/extensions/load_balancing_policies/client_side_weighted_round_robin/...

#34777

- Track whether `updateWeightsOnHosts()` changes any host weights and `applyWeightsToAllWorkers()` if necessary.
- Use thread local storage to track callbacks to worker-local load balancers and use `runOnAllThreads` to refresh them to apply the new weights.
- Update weights on hosts when new hosts are added, so they get reasonable initial weight.
- Calculate median weight of even number of valid hosts as an average of two weights closest to the median.

Signed-off-by: Misha Efimov <mef@google.com>
@adisuissa adisuissa self-assigned this Nov 13, 2024
Signed-off-by: Misha Efimov <mef@google.com>
Copy link
Contributor

@adisuissa adisuissa left a comment

Choose a reason for hiding this comment

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

Thanks!
Overall LGTM, although it is challenging for me to prove that the threads interactions (main and worker threads) will always be safe. I think that adding more time-based integration tests may assist in validating that they are safe.

@wbpcode
Copy link
Member

wbpcode commented Nov 19, 2024

The code change is LGTM overall. Thanks for the update. Only one comment is added.

Signed-off-by: Misha Efimov <mef@google.com>
Signed-off-by: Misha Efimov <mef@google.com>
Copy link
Contributor Author

@efimki efimki left a comment

Choose a reason for hiding this comment

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

Thank you for your comments!

I believe I've addressed all of them, so please take a look when you have a chance.

Signed-off-by: Misha Efimov <mef@google.com>
adisuissa
adisuissa previously approved these changes Nov 19, 2024
Copy link
Contributor

@adisuissa adisuissa left a comment

Choose a reason for hiding this comment

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

LGTM, thanks!

@efimki
Copy link
Contributor Author

efimki commented Nov 19, 2024

/retest

@wbpcode
Copy link
Member

wbpcode commented Nov 21, 2024

Please merge the main and resolve the conflicts. Than we can land this.

Signed-off-by: Misha Efimov <mef@google.com>
@efimki
Copy link
Contributor Author

efimki commented Nov 21, 2024

Done, PTAL.

@wbpcode
Copy link
Member

wbpcode commented Nov 21, 2024

cc @adisuissa to merge because @adisuissa have proposed more great suggestions.

@adisuissa
Copy link
Contributor

cc @adisuissa to merge because @adisuissa have proposed more great suggestions.

I think they were addressed.
I'm 99% convinced that the only race-errors will be the correctness of the LB structures, but not anything that could cause a crash.
I'll merge.

@adisuissa adisuissa merged commit 150e16d into envoyproxy:main Nov 21, 2024
24 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants