27

What is Redis's database size to memory ratio?

For instance, if I have an 80MB database, how much RAM will Redis use (when used with a normal web app)?

Philip Wernersbach
  • 461
  • 1
  • 5
  • 11

2 Answers2

24

Redis will use a bit more RAM than disk. The dumpfile format is probably a bit more densely packed. This is some numbers from a real production system (a 64 bit EC2 large instance running Redis 2.0.4 on Ubuntu 10.04):

$ redis-cli info | grep used_memory_human
used_memory_human:1.36G

$ du -sh /mnt/data/redis/dump.rdb 
950M /mnt/data/redis/dump.rdb

As you can see, the dumpfile is a few hundred megs smaller than the memory usage.

In the end it depends on what you store in the database. I have mainly hashes in mine, with only a few (perhaps less than 1%) sets. None of the keys contain very large objects, the average object size is 889 bytes.

Theo
  • 131,503
  • 21
  • 160
  • 205
  • I did some tests on my machine and I can confirm this; it appears that Redis doesn't include the RAM it uses for accounting toward the database size limit. – Philip Wernersbach Jan 21 '11 at 01:17
  • One of our four redis instances has a 3.4G dumpfile but redis says it used 16.52G in memory. – Kien Nguyen May 28 '12 at 08:28
  • 1
    If you're using a Redis version older than 2.4 and do a lot of deletion this can happen. Older versions of Redis never released memory back to the OS so the memory usage would stay at the high water mark until a restart. – Theo May 28 '12 at 08:55
  • For those of us still using redis 1.2.0, there is no used_memory_human so you have to do `redis-cli info | grep used_memory`. – David Grayson Oct 18 '12 at 20:33
-3

Redis databases are stored in memory, so an 80mb database would take up 80mb in ram.

Redis is an extremely low memory using program, and you can see that from this example from the website "1 Million keys with the key being the natural numbers from 0 to 999999 and the string "Hello World" as value uses 100MB [of Ram]". My Redis app uses around 300kb to 500kb of ram, so you would need a lot of data to reach a database of 80mb. Redis also saves to disk snapshots of the database, so 80mb in ram and 80mb on the hard drive.

Colum
  • 3,844
  • 1
  • 22
  • 26
  • 1
    -1 This is not accurate at all. I have 4.1gb of data that takes up 11gb of RAM. – Alan Sep 14 '13 at 17:52
  • "64 bit systems will use considerably more memory than 32 bit systems to store the same keys, especially if the keys and values are small, this is because pointers takes 8 bytes in 64 bit systems" – Issam Zoli Dec 21 '13 at 16:30