3 ms·
I agree. These days, I tend to approach a persistency implementation by asking myself: * will it be read or write heavy? * by what data/key will I access the
by sebcat 12y ago
I agree. These days, I tend to approach a persistency implementation by asking myself:
* will it be read or write heavy?
* by what data/key will I access the persistent data?
Most commonly for the type of work that I do, it's write once - read N number of times. What I end up doing then is just to keep the data in-mem in a hash table while writing it async to disk. Concurrent reads hit the hash table while the disk write is being performed. The file(s) are indexed by using a hash of the data itself, multiple ways to to lookups can also be done by using softlinks. Hashing lookup-keys are almost always prefered because of possible locale/security reasons (makes it harder for you to implement an accidental LFI if you only deal with base36) If needed and/or depending on access patterns, I also keep the N most accessed items in a hash table in-mem over time. The API for this usually ends up as two functions, Get and Put.
The amount of code for doing this is a couple of hundred lines at most and it's complexity I've found by experience to be preferable to using a db for the type of work that I do. YMMV.
- pavlov 12y agoThat's my usual approach as well. Usually an app's data will easily fit in memory within one process (and if it doesn't, that means the app has become so popular that adding an extra X GB of memory is an insignificant cost). Using the language's native data types and an append-only file for persistence is simple and offers high performance compared to doing all access over a socket.