mirror of
https://github.com/dragonflydb/dragonfly.git
synced 2025-05-11 10:25:47 +02:00
fix: improve performance of listpack sorted sets (#1885)
1. Cherry-pick changes from Redis 7 that encode integer scores more efficiently 2. Introduces optimization that first checks if the new element should be the last for listpack sorted sets. 3. Consolidates listpack related constants and tightens usage for listpack. 4. Introduce MEMORY USAGE command. 5. Introduce a small delay before decommitting memory pages back to OS. Signed-off-by: Roman Gershman <roman@dragonflydb.io>
This commit is contained in:
parent
cfd83a66a2
commit
8d1474aeac
18 changed files with 124 additions and 279 deletions
|
@ -69,6 +69,10 @@ std::string MallocStats(bool backing, unsigned tid) {
|
|||
return str;
|
||||
}
|
||||
|
||||
size_t MemoryUsage(PrimeIterator it) {
|
||||
return it->first.MallocUsed() + it->second.MallocUsed();
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
||||
MemoryCmd::MemoryCmd(ServerFamily* owner, ConnectionContext* cntx) : cntx_(cntx) {
|
||||
|
@ -83,15 +87,14 @@ void MemoryCmd::Run(CmdArgList args) {
|
|||
"MALLOC-STATS [BACKING] [thread-id]",
|
||||
" Show malloc stats for a heap residing in specified thread-id. 0 by default.",
|
||||
" If BACKING is specified, show stats for the backing heap.",
|
||||
"USAGE",
|
||||
" (not implemented).",
|
||||
"USAGE <key>",
|
||||
};
|
||||
return (*cntx_)->SendSimpleStrArr(help_arr);
|
||||
};
|
||||
|
||||
if (sub_cmd == "USAGE") {
|
||||
// dummy output, in practice not implemented yet.
|
||||
return (*cntx_)->SendLong(1);
|
||||
if (sub_cmd == "USAGE" && args.size() > 1) {
|
||||
string_view key = ArgS(args, 1);
|
||||
return Usage(key);
|
||||
}
|
||||
|
||||
if (sub_cmd == "MALLOC-STATS") {
|
||||
|
@ -121,4 +124,22 @@ void MemoryCmd::Run(CmdArgList args) {
|
|||
return (*cntx_)->SendError(err, kSyntaxErrType);
|
||||
}
|
||||
|
||||
void MemoryCmd::Usage(std::string_view key) {
|
||||
ShardId sid = Shard(key, shard_set->size());
|
||||
ssize_t memory_usage = shard_set->pool()->at(sid)->AwaitBrief([key, this]() -> ssize_t {
|
||||
auto& db_slice = EngineShard::tlocal()->db_slice();
|
||||
auto [pt, exp_t] = db_slice.GetTables(cntx_->db_index());
|
||||
PrimeIterator it = pt->Find(key);
|
||||
if (IsValid(it)) {
|
||||
return MemoryUsage(it);
|
||||
} else {
|
||||
return -1;
|
||||
}
|
||||
});
|
||||
|
||||
if (memory_usage < 0)
|
||||
return cntx_->SendError(kKeyNotFoundErr);
|
||||
(*cntx_)->SendLong(memory_usage);
|
||||
}
|
||||
|
||||
} // namespace dfly
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue