Finding a Perl module to store a Hash structure in shared RAM

I would like to keep the data structure permanently in RAM and make it accessible from the pre-forked web server processes in Perl.

Ideally, I would like it to behave like memcached, but without the need for a separate daemon. Any ideas?

+4
source share
3 answers

Use Cache :: FastMmap , and all you need is a file. It uses mmap to provide a shared in-memory cache for IPC, which means it's pretty fast. See Documentation for possible problems and disclaimers.

+10
source

IPC :: SharedMem may match the score.

+6
source

Mod_perl shares RAM on systems with correctly implemented copy to write. Upload your Perl hash to the BEGIN block of your mod_perl program, and all forked instances of mod_perl will share memory if there are no entries on the pages storing your hash. This does not work perfectly (some pages will be written), but on my servers and data it reduces memory usage by 70-80%.

Mod_perl also speeds up your server by eliminating Perl compilation time on subsequent web requests. The disadvantage of mod_perl is that you must program carefully and avoid programs that modify global variables, since these variables, such as the hash, are shared by all instances of mod_perl. It’s worth learning enough Perl so you don’t have to change global variables!

Performance from mod_perl is fantastic, but mod_perl is not available on many shared hosts. It is easy to drown out and difficult to debug while you study it. I only use it when my customers value performance improvements to justify my development pain.

0
source

Source: https://habr.com/ru/post/1313254/


All Articles