There's more than one way to do things | |
PerlMonks |
Sharing data "cache" between forked processesby Anonymous Monk |
on Nov 23, 2018 at 11:31 UTC ( [id://1226220]=perlquestion: print w/replies, xml ) | Need Help?? |
Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question: Hi, I'm trying to implement/adopt a "cache" for frequently accessed data which is currently loaded from and stored to files on each access/modification. SituationThe data loaded from files is represented in hashes (one hash per file). The primary purpose of the "cache" would be to hide the reading/writing of files from the rest of the program, so that data retrieval and modifications stay reasonably fast even when there are high disk loads. The program is a forking server, so the "cache" needs to be shared across multiple processes. Since I don't see a great overlap between traditional perl caches (CHI, Cache and similar) and my needs (essentially an in(-shared)-memory database with reading and writing entries to files on specific conditions), I don't think using those would be wise. When trying to implement this "cache" I've considered using some sort of shared-memory module which could store a hash of hashes. On the hash of hashes in shared memory front, I've looked into IPC::MMA and IPC::Shareable but neither seems to fit the bill. IPC::MMA can only store scalars in its hash structures, so I can't nest the hashes. IPC::Shareable has the problem of possible conflicts with the 4 char glue (I need to share lots of relatively simple hashes) and might run out of usable shared memory segments. I also looked at in-memory databases, but I'm not sure about how that would affect memory usage (I imagine anything in retrieved from a table will be copied), and all databases I've looked at would need a ramdisk, since they don't support in-memory connections from multiple processes. QuestionPrimarily, I'd like to ask if you can recommend a perl module which supports nesting hashes in shared memory and doesn't suffer from the limitations IPC::Shareable has, however I'm open to suggestions of alternative approaches to solving my main issue (the "cache").
Back to
Seekers of Perl Wisdom
|
|