Skip to content

Commit

Permalink
k/connection_context: replaced node hash map with chunked hash map
Browse files Browse the repository at this point in the history
Replaced `node_hash_map` keeping state of virtualized connections with
`chunked_hash_map`. The change will allow us to avoid large allocations
when dealing with large virtual connection number.

Signed-off-by: Michał Maślanka <michal@redpanda.com>
  • Loading branch information
mmaslankaprv committed May 15, 2024
1 parent 953135b commit 187dcbf
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 8 deletions.
15 changes: 8 additions & 7 deletions src/v/kafka/server/connection_context.cc
Original file line number Diff line number Diff line change
Expand Up @@ -720,13 +720,14 @@ connection_context::dispatch_method_once(request_header hdr, size_t size) {
"request from virtual connection {}, client id: {}",
client_connection_id.v_connection_id,
client_connection_id.client_id);
auto it = _virtual_states.lazy_emplace(
client_connection_id.v_connection_id,
[v_connection_id = client_connection_id.v_connection_id](
const auto& ctr) mutable {
return ctr(
v_connection_id, ss::make_lw_shared<virtual_connection_state>());
});

auto it = _virtual_states.find(client_connection_id.v_connection_id);
if (it == _virtual_states.end()) {
auto p = _virtual_states.emplace(
client_connection_id.v_connection_id,
ss::make_lw_shared<virtual_connection_state>());
it = p.first;
}

co_await it->second->process_request(
shared_from_this(), std::move(rctx), sres);
Expand Down
3 changes: 2 additions & 1 deletion src/v/kafka/server/connection_context.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
#pragma once
#include "base/seastarx.h"
#include "config/property.h"
#include "container/chunked_hash_map.h"
#include "kafka/server/fwd.h"
#include "kafka/server/handlers/handler_probe.h"
#include "kafka/server/logger.h"
Expand Down Expand Up @@ -437,7 +438,7 @@ class connection_context final
* A map keeping virtual connection states, during default operation the map
* is empty
*/
absl::node_hash_map<
chunked_hash_map<
virtual_connection_id,
ss::lw_shared_ptr<virtual_connection_state>>
_virtual_states;
Expand Down

0 comments on commit 187dcbf

Please sign in to comment.