Skip to content

Commit

Permalink
io_queue: Scatter requests across shards evenly
Browse files Browse the repository at this point in the history
All requests that get queued to specific ptiotity class are spread among
all shards evenly in plain round-robin manner.

Signed-off-by: Pavel Emelyanov <[email protected]>
  • Loading branch information
xemul committed Jun 7, 2024
1 parent 5236129 commit 23a8769
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 2 deletions.
2 changes: 1 addition & 1 deletion include/seastar/core/io_queue.hh
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ private:

priority_class_data& find_or_create_class(internal::priority_class pc);
future<size_t> queue_request(internal::priority_class pc, internal::io_direction_and_length dnl, internal::io_request req, io_intent* intent, iovec_keeper iovs) noexcept;
future<size_t> queue_one_request(internal::priority_class pc, internal::io_direction_and_length dnl, internal::io_request req, io_intent* intent, iovec_keeper iovs) noexcept;
future<size_t> queue_one_request(internal::priority_class pc, internal::io_direction_and_length dnl, internal::io_request req, io_intent* intent, iovec_keeper iovs, bool foreign = false) noexcept;
future<size_t> queue_one_request(priority_class_data& pclass, internal::io_direction_and_length dnl, internal::io_request req, io_intent* intent, iovec_keeper iovs) noexcept;

// The fields below are going away, they are just here so we can implement deprecated
Expand Down
16 changes: 15 additions & 1 deletion src/core/io_queue.cc
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,7 @@ class io_queue::priority_class_data {
std::chrono::duration<double> _total_execution_time;
std::chrono::duration<double> _starvation_time;
io_queue::clock_type::time_point _activated;
unsigned _balance_round_robbin = 0;

io_group::priority_class_data& _group;
size_t _replenish_head;
Expand Down Expand Up @@ -212,6 +213,10 @@ class io_queue::priority_class_data {

std::vector<seastar::metrics::impl::metric_definition_impl> metrics();
metrics::metric_groups metric_groups;

unsigned balance() noexcept {
return _balance_round_robbin++ % smp::count;
}
};

class io_desc_read_write final : public io_completion {
Expand Down Expand Up @@ -957,9 +962,18 @@ future<size_t> io_queue::queue_one_request(priority_class_data& pclass, io_direc
return fut;
}

future<size_t> io_queue::queue_one_request(internal::priority_class pc, io_direction_and_length dnl, internal::io_request req, io_intent* intent, iovec_keeper iovs) noexcept {
future<size_t> io_queue::queue_one_request(internal::priority_class pc, io_direction_and_length dnl, internal::io_request req, io_intent* intent, iovec_keeper iovs, bool foreign) noexcept {
try {
auto& pclass = find_or_create_class(pc);
if (!foreign) {
auto target = pclass.balance();
if (target != this_shard_id()) {
// FIXME: intent is lost :(
return smp::submit_to(target, [pc = std::move(pc), dnl = std::move(dnl), req = std::move(req), iovs = std::move(iovs), g = _group] () mutable {
return g->_io_queues[this_shard_id()]->queue_one_request(std::move(pc), std::move(dnl), std::move(req), nullptr, std::move(iovs), true);
});
}
}
return queue_one_request(pclass, std::move(dnl), std::move(req), intent, std::move(iovs));
} catch (...) {
return make_exception_future<size_t>(std::current_exception());
Expand Down

0 comments on commit 23a8769

Please sign in to comment.