You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Fill a Redis 2.8 cluster (with activerehashing on) with > 1 billion keys. (I'm not sure the exact number needed to trigger the issue.) I used redis-benchmark to set random values.
Perform a bgsave
The bgsave successfully finishes in 0 seconds, and upon inspection contains 0 items (i.e. the line linked to above is true for the first element). It looks like there isn't support for hash tables of size greater than INT_MAX even if there are fewer than INT_MAX elements in the database?
What OS and platform (32/64-bit) are you running? Sadly, Redis uses variable length type specifiers, so long on some platforms is 32 bits and 64 bits on others, but in either case, the iterator is too short.
Can you checkout my dict-size branch and run your test again? I converted the iterator size to 64 bits instead of int and forced the dict size types to be 64 bits instead of unsigned long.
Should be easy to clone and get working:
git clone https://github.com/mattsta/redis trydict
cd trydict
git checkout dict-size
make -j
[your tests]
It's looking good. I'm able to save and load RDB files that have 1-2 billion items. Redis still segfaults when I get above 2^31 items (dictAddRaw is the culprit), but it looks like RDB dumping works as long as Redis works...
Oh, the int index in dictAddRaw? That's an easy fix too. I just added a fix for that to my dict-size branch.
Great to hear it fixed the RDB dump problem.
Did you run into the save failure actually in production or just during testing?
For your tests, did you just run redis-benchmark with a very large -n and -r values? If you add your testing command(s) here I can double verify everything works too.
Do you have 2 billion of keys in a single instance!? :-)
A few notes:
This was not done before since I assumed the dictht structure as using int, in order to save space, since it is unlikely you have an instance with a dictionary containing 2 billion items.
However it was broken as I used long instead, for some obscure reason. Probably because dict.h is so old that back I had no 64 bit system at all and did not cared enough.
So now the thing is if to convert it to uint32_t and save memory, or to make it more future-proof given that the dictionary is used to hold the main hash table, not just the set/zset/hash types.
I did a quick test, 2 million sets with a,b,c as elements. It is one of the use cases where the 32 bit integer make the biggest savings:
32 bit int: 681.13M
64 bit int: 708.80M
So the difference is small... I'm more happy applying Matt's patch instead of saving this small amount of memory.
However I'm still curious in what environment Kevin was able to store billion of keys in Redis!
No wait... before merging, doesn't it actually make more sense to use unsigned long everywhere? So take the original type, but fix the iterator to also use unsigned long everywhere. You can't have billions of keys in a 32 bit instance, so why to use more memory than currently?
unsigned long is convenient as it the same size of the memory address space in all our target architecture, so we can use a fat integer where it makes sense, and a smaller one where we'll never be able to exploit the additonal bits.
Correct! I wasn't sure if these changes would even fix the problem and was half guessing at a fix (there could have been other keyspace or save size issues somewhere). If it looks correct to you, even better. :)
fix the iterator to also use unsigned long everywhere
The iterator currently uses -1 for index in some cases. If we remove the use of -1, the iterator/index values can be unsigned long too. I was just trying to make the code as clear as possible for immediate testing. 🐱
This problem was encountered during testing using a very large memory EC2 instance. 2 billion keys is a bit of a contrived test, but 1 billion keys is doable with 200+GB of RAM.
redis-benchmark isn't the best way to reproduce this issue because it takes a while to get 1 billion unique random keys, but you can do something like
redis-benchmark -r 2147483646-n 5000000-q -l -P32 set __rand_int__ ''
Fixed in 064d5c9, I left the unsigned long approach in order to have an arch dependent type without side effects in 32 bit systems. Also switched the rehashing index to long, since otherwise it works for a quick test but then the dictionary is not able to rehash. Thanks.
Activity
mattsta commentedon Jun 13, 2014
What OS and platform (32/64-bit) are you running? Sadly, Redis uses variable length type specifiers, so long on some platforms is 32 bits and 64 bits on others, but in either case, the iterator is too short.
Can you checkout my
dict-sizebranch and run your test again? I converted the iterator size to 64 bits instead ofintand forced the dict size types to be 64 bits instead ofunsigned long.Should be easy to clone and get working:
kevinmcgehee commentedon Jun 13, 2014
I'm using Amazon Linux 2014.03 64-bit on EC2. I'll try your branch and report back.
mattsta commentedon Jun 13, 2014
Good to know. Thanks for reporting the issue (and congrats on having so much data)! I'm looking forward to your results.
kevinmcgehee commentedon Jun 14, 2014
It's looking good. I'm able to save and load RDB files that have 1-2 billion items. Redis still segfaults when I get above 2^31 items (dictAddRaw is the culprit), but it looks like RDB dumping works as long as Redis works...
Convert dictIterator to use 64 bit sizes
mattsta commentedon Jun 14, 2014
Oh, the
int indexin dictAddRaw? That's an easy fix too. I just added a fix for that to mydict-sizebranch.Great to hear it fixed the RDB dump problem.
Did you run into the save failure actually in production or just during testing?
For your tests, did you just run
redis-benchmarkwith a very large-nand-rvalues? If you add your testing command(s) here I can double verify everything works too.antirez commentedon Jun 16, 2014
Do you have 2 billion of keys in a single instance!? :-)
A few notes:
dicthtstructure as using int, in order to save space, since it is unlikely you have an instance with a dictionary containing 2 billion items.longinstead, for some obscure reason. Probably because dict.h is so old that back I had no 64 bit system at all and did not cared enough.So now the thing is if to convert it to uint32_t and save memory, or to make it more future-proof given that the dictionary is used to hold the main hash table, not just the set/zset/hash types.
I did a quick test, 2 million sets with a,b,c as elements. It is one of the use cases where the 32 bit integer make the biggest savings:
So the difference is small... I'm more happy applying Matt's patch instead of saving this small amount of memory.
However I'm still curious in what environment Kevin was able to store billion of keys in Redis!
antirez commentedon Jun 16, 2014
@mattsta I see no pull request, I'm just merging your commit manually.
antirez commentedon Jun 16, 2014
@mattsta p.s. thank you, as always...!
antirez commentedon Jun 16, 2014
No wait... before merging, doesn't it actually make more sense to use unsigned long everywhere? So take the original type, but fix the iterator to also use unsigned long everywhere. You can't have billions of keys in a 32 bit instance, so why to use more memory than currently?
unsigned longis convenient as it the same size of the memory address space in all our target architecture, so we can use a fat integer where it makes sense, and a smaller one where we'll never be able to exploit the additonal bits.mattsta commentedon Jun 16, 2014
Correct! I wasn't sure if these changes would even fix the problem and was half guessing at a fix (there could have been other keyspace or save size issues somewhere). If it looks correct to you, even better. :)
The iterator currently uses -1 for
indexin some cases. If we remove the use of -1, the iterator/index values can be unsigned long too. I was just trying to make the code as clear as possible for immediate testing. 🐱kevinmcgehee commentedon Jun 16, 2014
This problem was encountered during testing using a very large memory EC2 instance. 2 billion keys is a bit of a contrived test, but 1 billion keys is doable with 200+GB of RAM.
redis-benchmark isn't the best way to reproduce this issue because it takes a while to get 1 billion unique random keys, but you can do something like
until you reach that number of keys.
mattsta commentedon Jul 28, 2014
Checking: did this fix get added? I can't track down in any commits.
Use long for rehash and iterator index in dict.h.
antirez commentedon Aug 26, 2014
Fixed in 064d5c9, I left the unsigned long approach in order to have an arch dependent type without side effects in 32 bit systems. Also switched the rehashing index to long, since otherwise it works for a quick test but then the dictionary is not able to rehash. Thanks.
Use long for rehash and iterator index in dict.h.
Use long for rehash and iterator index in dict.h.