-
Notifications
You must be signed in to change notification settings - Fork 886
feat(lb): interleaved weighted round-robin load balancer #1019
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
Conversation
An O(1) time and O(n) memory weighted load balancing implementation
Compared with NGINX SWRR, it abandons the smooth feature, but in a large traffic scenario, the benefits brought by load balancing smoothing are very low, because a cycle will be selected in a short time. Here is the benchmark
|
An O(1) time and O(n) memory weighted load balancing implementation
An O(1) time and O(n) memory weighted load balancing implementation
Codecov ReportPatch coverage:
Additional details and impacted files@@ Coverage Diff @@
## develop #1019 +/- ##
===========================================
+ Coverage 68.01% 68.13% +0.11%
===========================================
Files 248 249 +1
Lines 18802 18867 +65
===========================================
+ Hits 12789 12855 +66
- Misses 4845 4850 +5
+ Partials 1168 1162 -6
☔ View full report in Codecov by Sentry. |
@jizhuozhi Hi,Last thing you need to do is updating the docs in : https://github.com/cloudwego/cloudwego.github.io/blob/main/content/zh/docs/kitex/Tutorials/service-governance/loadbalance.md Both chinese and english. |
Hello, @joway . The docs is updated, PTAL. |
An O(1) time and O(n) memory weighted load balancing implementation
What type of PR is this?
Check the PR title.
(Optional) Translate the PR title into Chinese.
交错式加权轮询负载均衡算法,时间复杂度O(1),空间复杂度O(n),相比于VNSWRR的O(sigma(W))更省空间且可控
(Optional) More detailed description for this PR(en: English/zh: Chinese).
https://en.wikipedia.org/wiki/Weighted_round_robin#Interleaved_WRR
与Linux O(1)调度器思路相同,维护两个队列,分别是当前队列和下一次队列。队列中的每个元素都维护remainder表示在当前队列中剩余可选中次数,初始时remainder与权重相同,每次被选中后都会减少remainder(使用GCD来缩短周期)。当remainder为0时表示当前周期内不可调度,将其放到下一次队列中。当当前队列为空时表示当前周期所有元素都被按权重选择过了,此时对换当前队列和下一次队列开始新一轮周期。由于始终复用链表节点,因此该负载均衡算法实现在初始化后可以保证是零分配的。
(Optional) Which issue(s) this PR fixes:
(optional) The PR that updates user documentation: