8000 opt(lb): optimize the performance of weighted_random load balancer by jizhuozhi · Pull Request #569 · cloudwego/volo · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

opt(lb): optimize the performance of weighted_random load balancer #569

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

Open
wants to merge 6 commits into
base: main
Choose a base branch
from

Conversation

jizhuozhi
Copy link

Motivation

Volo provides a weighted random load balancer with CDF (cumulative distribution function) or as known as prefix sum method. But after reviewing the code, I found some optimize point to make volo having better performance:

  1. pick_one method is consuming random weight by iterating each instance from first to last, which needs O(n) time. But the prefix sum is an ordered slice, so we could using binary search to find upper bound of random weight which only need O(log n) time.
  2. Iterator of InstancePicker, each time the upstream call failed, we need to copy a new slice and then perform weighted random sampling without replacement. But since each instance is without replacement, it will act as unweighted random sampling, but always need O(n) to calculate the prefix sum of weight. Since we are weighted random picked in the first round, we could just using RoundRobin with random picked start position which only need O(1) time and zero memory allocation.

@jizhuozhi jizhuozhi requested review from a team as code owners May 1, 2025 08:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

1 participant
0