redis-rdb-tools icon indicating copy to clipboard operation
redis-rdb-tools copied to clipboard

Question - How is the reported size calculated

Open avnerbarr opened this issue 7 years ago • 3 comments

I'm trying to understand the discrepancies on key size that I am getting

for example:

127.0.0.1:6379> set a a
OK
127.0.0.1:6379> MEMORY usage a
(integer) 52
127.0.0.1:6379> DEBUG OBJECT a
Value at:0x7f98563a1770 refcount:1 encoding:embstr serializedlength:2 lru:11685905 lru_seconds_idle:10
127.0.0.1:6379>

vs

(venv) /tmp/rdb/venv: redis-memory-for-key a
Key				a
Bytes				56
Type				string
(venv) /tmp/rdb/venv:

avnerbarr avatar Mar 21 '18 12:03 avnerbarr

There may be some small differences in how each is calculating the size and what extra overheads it sums in or not. For instance, the MEMORY command doesn't take internal fragmentation into account, but redis-rdb-tools does (or at least attempts to do that). Please note that Redis's used_memory field in INFO MEMORY does include internal fragmentation.. So in that respect redis-rdb-tools is more accurate, and the MEMORY USAGE command is wrong.

On the other hand, redis-rdb-tools doesn't count the fact (or even knows about it), that this key is encoded as EMBSTR, so it's estimation of internal fragmentation may be wrong.

Other than that please note that on non string keys, MEMORY USAGE only gives you an estimation, not an accurate measure.

oranagra avatar Mar 21 '18 12:03 oranagra

what is "internal fragmentation"?

avnerbarr avatar Mar 21 '18 14:03 avnerbarr

https://en.m.wikipedia.org/wiki/Fragmentation_(computing)#Internal_fragmentation

oranagra avatar Mar 21 '18 16:03 oranagra