Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions include/seastar/net/api.hh
Original file line number Diff line number Diff line change
Expand Up @@ -360,6 +360,9 @@ public:
port,
// This algorithm distributes all new connections to listen_options::fixed_cpu shard only.
fixed,
// This algorithm distributes new connections to shards in a round-robin fashion,

Copy link
Copy Markdown
Contributor

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").

// cycling through shards 0, 1, ..., N-1, 0, 1, ... regardless of current load.
round_robin,
default_ = connection_distribution
};
/// Constructs a \c server_socket without being bound to any address
Expand Down
10 changes: 10 additions & 0 deletions include/seastar/net/posix-stack.hh
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ using namespace seastar;
class conntrack {
class load_balancer {
std::vector<unsigned> _cpu_load;
unsigned _rr_counter = 0;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The 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) {
Expand All @@ -74,6 +75,12 @@ class conntrack {
_cpu_load[cpu]++;
return cpu;
}
shard_id next_cpu_rr() {
auto cpu = shard_id(_rr_counter % smp::count);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The 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;
Expand Down Expand Up @@ -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);
}
Expand Down
3 changes: 3 additions & 0 deletions src/net/posix-stack.cc
Original file line number Diff line number Diff line change
Expand Up @@ -724,6 +724,9 @@ posix_server_socket_impl::accept() {
case server_socket::load_balancing_algorithm::fixed:
cth = _conntrack.get_handle(_fixed_cpu);
break;
case server_socket::load_balancing_algorithm::round_robin:
cth = _conntrack.get_handle_rr();
break;
default: abort();
}

Expand Down
Loading