by hakunin · 3y ago · 0 comments
In one of my old jobs we had megabytes of infrequently accessed static key-value data. If we simply loaded it into a const (i.e. a hash table), it would blow up the RAM so much, that we would need to upgrade to bigger VPSes. If we put it in database, it would make it annoying to keep these tables up to date, track changes in them.
I figured this was one of those in-between use cases, where the best solution is to have zero-RAM lookups from SSD. In my case, I wrote a little ruby library[1] that arranges data in equal cells in a file, and performs binary searches via `pread`. This was perfect for us, because we kept data in our repos, sacrificed no RAM at runtime, SSD lookups were fast enough, and we didn't have to support a more elaborate db.
[UPDATE] I missed a crucial part of the problem setup, which is that the data is read-only. That obviously moots my objection.
Edit: oh and I think I did come across some article like the one linked in the neighbor comment. It's starting to come back.
Those lookups eventually made their way into the kernel's page cache.
Yes, they did.
Yeah, there's a build step that sorts and arranges data into "cells", making binary search possible.
Not sure about kernel/user space. I'm just calling `pread` from ruby, so only a few bytes are loaded per lookup.