Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why a 500MB Redis dump.rdb file takes about 5.0GB memory?

Tags:

redis

Actually, I have 3 Redis instances and I put them together into this 500MB+ dump.rdb. The Redis server can read this dump.rdb and it seems that everything is ok. Then I notice that redis-server cost more than 5.0GB memory. I don't know why.

Is there anything wrong with my file? My db has about 3 million keys, values for each key is a list contains about 80 integers.

I use this METHOD to put 3 instance together.

PS:Another dump.rdb with the same size and same key-value structure cost only 1GB memory.

And my data looks like keyNum->{num1, num2, num3,......}. All numbers is between 1 and 4,000,000. So should I use List to store them? For now, I use lpush(k, v). Did this way cost too much?

like image 653
wyp Avatar asked Nov 06 '12 03:11

wyp


People also ask

What is dump RDB file in Redis?

By default Redis saves snapshots of the dataset on disk, in a binary file called dump. rdb . You can configure Redis to have it save the dataset every N seconds if there are at least M changes in the dataset, or you can manually call the SAVE or BGSAVE commands.

Where does Redis store dump RDB?

rdb file in the /var/lib/redis/ directory. You'll want to update the permissions so the file is owned by the redis user and group: sudo chown redis:redis /var/lib/redis/dump.


1 Answers

The ratio of memory to dump size depends on the data types Redis uses internally.

For small objects (hashes, lists and sortedsets), redis uses ziplists to encode data. For small sets made of integers, redis uses Intsets. ZipLists and IntSets are stored on disk in the same format as they are stored in memory. So, you'd expect a 1:1 ratio if your data uses these encodings.

For larger objects, the in-memory representation is completely different from the on-disk representation. The on-disk format is compressed, doesn't have pointers, doesn't have to deal with memory fragmentation. So, if your objects are large, a 10:1 memory to disk ratio is normal and expected.

If you want to know which objects eat up memory, use redis-rdb-tools to profile your data (disclaimer: I am the author of this tool). From there, follow the memory optimization notes on redis.io, as well as the memory optimization wiki entry on redis-rdb-tools.

like image 79
Sripathi Krishnan Avatar answered Sep 28 '22 07:09

Sripathi Krishnan