mirror of
https://github.com/dragonflydb/dragonfly.git
synced 2025-05-11 18:35:46 +02:00
feat(server): Tracking memory usage for client tracking table (#2431)
Tracking memory usage for client tracking table using C++ memory resource and polymorphic allocator.
This commit is contained in:
parent
e06b736c02
commit
d1db48d9d4
2 changed files with 23 additions and 3 deletions
|
@ -249,7 +249,10 @@ SliceEvents& SliceEvents::operator+=(const SliceEvents& o) {
|
|||
#undef ADD
|
||||
|
||||
DbSlice::DbSlice(uint32_t index, bool caching_mode, EngineShard* owner)
|
||||
: shard_id_(index), caching_mode_(caching_mode), owner_(owner) {
|
||||
: shard_id_(index),
|
||||
caching_mode_(caching_mode),
|
||||
owner_(owner),
|
||||
client_tracking_map_(owner->memory_resource()) {
|
||||
db_arr_.emplace_back();
|
||||
CreateDb(0);
|
||||
expire_base_[0] = expire_base_[1] = 0;
|
||||
|
|
|
@ -4,6 +4,7 @@
|
|||
|
||||
#pragma once
|
||||
|
||||
#include "core/mi_memory_resource.h"
|
||||
#include "facade/dragonfly_connection.h"
|
||||
#include "facade/op_status.h"
|
||||
#include "server/common.h"
|
||||
|
@ -491,8 +492,24 @@ class DbSlice {
|
|||
}
|
||||
};
|
||||
|
||||
// the table that maps keys to the clients that are tracking them.
|
||||
absl::flat_hash_map<std::string, absl::flat_hash_set<facade::Connection::WeakRef, Hash>>
|
||||
// the following type definitions are confusing, and they are for achieving memory
|
||||
// usage tracking for client_tracking_map_ data structure through C++'s memory resource and
|
||||
// and polymorphic allocator (new C++ features)
|
||||
// the declarations below meant to say:
|
||||
// absl::flat_hash_map<std::string,
|
||||
// absl::flat_hash_set<facade::Connection::WeakRef, Hash>> client_tracking_map_
|
||||
using HashSetAllocator = PMR_NS::polymorphic_allocator<facade::Connection::WeakRef>;
|
||||
|
||||
using ConnectionHashSet =
|
||||
absl::flat_hash_set<facade::Connection::WeakRef, Hash,
|
||||
absl::container_internal::hash_default_eq<facade::Connection::WeakRef>,
|
||||
HashSetAllocator>;
|
||||
|
||||
using AllocatorType = PMR_NS::polymorphic_allocator<std::pair<std::string, ConnectionHashSet>>;
|
||||
|
||||
absl::flat_hash_map<std::string, ConnectionHashSet,
|
||||
absl::container_internal::hash_default_hash<std::string>,
|
||||
absl::container_internal::hash_default_eq<std::string>, AllocatorType>
|
||||
client_tracking_map_;
|
||||
};
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue