From 3edaaab49337476c3851c749f0c06dfe3fe88650 Mon Sep 17 00:00:00 2001 From: Kefu Chai Date: Tue, 2 Mar 2021 18:08:27 +0800 Subject: [PATCH] crimson/mon: use a vector for mon_commands for smaller memory foot print. as we don't have lots of mon_command in flight, hence not likely to benefit from a O(log(n)) lookup. Signed-off-by: Kefu Chai --- src/crimson/mon/MonClient.cc | 19 +++++++++++-------- src/crimson/mon/MonClient.h | 3 ++- 2 files changed, 13 insertions(+), 9 deletions(-) diff --git a/src/crimson/mon/MonClient.cc b/src/crimson/mon/MonClient.cc index 3dcd4e69978..b42e98f8856 100644 --- a/src/crimson/mon/MonClient.cc +++ b/src/crimson/mon/MonClient.cc @@ -829,9 +829,13 @@ Client::handle_get_version_reply(Ref m) seastar::future<> Client::handle_mon_command_ack(Ref m) { const auto tid = m->get_tid(); - if (auto found = mon_commands.find(tid); + if (auto found = std::find_if(mon_commands.begin(), + mon_commands.end(), + [tid](auto& cmd) { + return cmd.req->get_tid() == tid; + }); found != mon_commands.end()) { - auto& command = found->second; + auto& command = *found; logger().trace("{} {}", __func__, tid); command.result.set_value(std::make_tuple(m->r, m->rs, std::move(m->get_data()))); mon_commands.erase(found); @@ -1005,10 +1009,9 @@ Client::run_command(std::string&& cmd, m->set_tid(tid); m->cmd = {std::move(cmd)}; m->set_data(std::move(bl)); - [[maybe_unused]] auto [command, added] = - mon_commands.try_emplace(tid, m); - assert(added); - return send_message(m).then([&result=command->second.result] { + mon_commands.emplace_back(m); + auto& command = mon_commands.back(); + return send_message(command.req).then([&result=command.result] { return result.get_future(); }); } @@ -1037,8 +1040,8 @@ seastar::future<> Client::on_session_opened() return seastar::now(); }).then([this] { return seastar::parallel_for_each(mon_commands, - [this](auto &tid_command) { - return send_message(tid_command.second.req); + [this](auto &command) { + return send_message(command.req); }); }); } diff --git a/src/crimson/mon/MonClient.h b/src/crimson/mon/MonClient.h index 335f76bf0a9..f6bb75da3aa 100644 --- a/src/crimson/mon/MonClient.h +++ b/src/crimson/mon/MonClient.h @@ -4,6 +4,7 @@ #pragma once #include +#include #include #include @@ -73,7 +74,7 @@ class Client : public crimson::net::Dispatcher, typename command_result_t::promise_type result; mon_command_t(ceph::ref_t req); }; - std::map mon_commands; + std::vector mon_commands; MonSub sub; -- 2.39.5