-
Notifications
You must be signed in to change notification settings - Fork 1.7k
net: Introduce round-robin connection balancing policy #3371
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
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -60,6 +60,7 @@ using namespace seastar; | |
| class conntrack { | ||
| class load_balancer { | ||
| std::vector<unsigned> _cpu_load; | ||
| unsigned _rr_counter = 0; | ||
|
Contributor
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. nitpick: If you're familiar with this code, you can guess that the acronym "rr" refers to round-robin, but it's not obvious. I would add a comment that this variable is used by load_balancing_algorithm::round_robin to choose the next shard. |
||
| public: | ||
| load_balancer() : _cpu_load(size_t(smp::count), 0) {} | ||
| void closed_cpu(shard_id cpu) { | ||
|
|
@@ -74,6 +75,12 @@ class conntrack { | |
| _cpu_load[cpu]++; | ||
| return cpu; | ||
| } | ||
| shard_id next_cpu_rr() { | ||
| auto cpu = shard_id(_rr_counter % smp::count); | ||
|
Contributor
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. Note that in #3355 @avikivity deprecates smp::count, so this call will need to be fixed (in the same way Avi fixed the lines above). |
||
| _rr_counter++; | ||
| _cpu_load[cpu]++; | ||
| return cpu; | ||
| } | ||
| shard_id force_cpu(shard_id cpu) { | ||
| _cpu_load[cpu]++; | ||
| return cpu; | ||
|
|
@@ -119,6 +126,9 @@ public: | |
| handle get_handle() { | ||
| return handle(_lb->next_cpu(), _lb); | ||
| } | ||
| handle get_handle_rr() { | ||
| return handle(_lb->next_cpu_rr(), _lb); | ||
| } | ||
| handle get_handle(shard_id cpu) { | ||
| return handle(_lb->force_cpu(cpu), _lb); | ||
| } | ||
|
|
||
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.
nitpick: typo in the commit message title ("balaning").