Report slot to keys map size in MEMORY STATS in cluster mode (#10017)

Report slot to keys map size in MEMORY STATS in cluster mode
Report dictMetadataSize in MEMORY USAGE command as well
This commit is contained in:
Joey from AWS 2022-01-02 00:39:59 -08:00 committed by GitHub
parent 45a155bd0f
commit 09c668f220
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 14 additions and 1 deletions

View File

@ -1233,6 +1233,11 @@ struct redisMemOverhead *getMemoryOverheadData(void) {
mh->db[mh->num_dbs].overhead_ht_expires = mem;
mem_total+=mem;
/* Account for the slot to keys map in cluster mode */
mem = dictSize(db->dict) * dictMetadataSize(db->dict);
mh->db[mh->num_dbs].overhead_ht_slot_to_keys = mem;
mem_total+=mem;
mh->num_dbs++;
}
@ -1523,6 +1528,7 @@ NULL
size_t usage = objectComputeSize(c->argv[2],dictGetVal(de),samples,c->db->id);
usage += sdsZmallocSize(dictGetKey(de));
usage += sizeof(dictEntry);
usage += dictMetadataSize(c->db->dict);
addReplyLongLong(c,usage);
} else if (!strcasecmp(c->argv[1]->ptr,"stats") && c->argc == 2) {
struct redisMemOverhead *mh = getMemoryOverheadData();
@ -1560,15 +1566,19 @@ NULL
char dbname[32];
snprintf(dbname,sizeof(dbname),"db.%zd",mh->db[j].dbid);
addReplyBulkCString(c,dbname);
addReplyMapLen(c,2);
addReplyMapLen(c,3);
addReplyBulkCString(c,"overhead.hashtable.main");
addReplyLongLong(c,mh->db[j].overhead_ht_main);
addReplyBulkCString(c,"overhead.hashtable.expires");
addReplyLongLong(c,mh->db[j].overhead_ht_expires);
addReplyBulkCString(c,"overhead.hashtable.slot-to-keys");
addReplyLongLong(c,mh->db[j].overhead_ht_slot_to_keys);
}
addReplyBulkCString(c,"overhead.total");
addReplyLongLong(c,mh->overhead_total);

View File

@ -344,6 +344,8 @@ int dictExpandAllowed(size_t moreMem, double usedRatio) {
* belonging to the same cluster slot. See the Slot to Key API in cluster.c. */
size_t dictEntryMetadataSize(dict *d) {
UNUSED(d);
/* NOTICE: this also affect overhead_ht_slot_to_keys in getMemoryOverheadData.
* If we ever add non-cluster related data here, that code must be modified too. */
return server.cluster_enabled ? sizeof(clusterDictEntryMetadata) : 0;
}

View File

@ -1267,6 +1267,7 @@ struct redisMemOverhead {
size_t dbid;
size_t overhead_ht_main;
size_t overhead_ht_expires;
size_t overhead_ht_slot_to_keys;
} *db;
};