Do you know where your variables are? | |
PerlMonks |
Re^2: 32bit/64bit hash function: Use perls internal hash function?by sectokia (Pilgrim) |
on Apr 09, 2022 at 01:53 UTC ( [id://11142863]=note: print w/replies, xml ) | Need Help?? |
My situations is this, any suggestions appreciated, probably someone has done this before: In some situations perl hashes are bloated in memory usage: Example: store 100million 64 byte keys with 32bit values. If you do this perl uses >50GiB RAM! If you try and do 1billion keys... forget it. Now I don't need to retrieve the keys or store them in memory (I am given them as input and just want the value back from the key). So what I am doing is: Hash the key to 2x32bit. Use one 32bit hash as a lookup to an array of 4billion entries. In the array I store the 32bit value and the another 32bits of the hash for collision detection/handling. Result is I can store 100million items in 32GiB RAM. In fact I can store 500million and even push to 2billion items in 32GiB ram. Its only when I approach 4B will re-hashing for collision detecting become a problem. Obviously to get perls performance, I need a faster hash than md5, benchmarks were showing it was very slow compared to perls internal hash. The values I fetch are then used to seek to a file/positions on disk, to fetch small amounts of data (<64bytes). I was finding the fastest I could achieve was about 20% of the random IOPS of the SSD, with reads being 8KB. By changing to sysread I have been able to completely eliminate this problem 5x faster and now get IOPS same as SSD benchmark results.
In Section
Seekers of Perl Wisdom
|
|