Funny you should ask. This is one of the more common questions fielded for Net::Server.
In either of PreFork or PreForkSimple you are going to have this problem. As
salvix already pointed out, forked processes get a snapshot of the state of the parent at the time of fork. Any updates to the parent after that point will not be reflected in the already forked processes. You need a method to share the data.
For caching the data I'd recommend one of Cache::Memcached or Cache::FastMmap. Both of these are extremely fast. If all you are doing with the server is serving the cached data then Cache::Memcached already does everything you need (if you are doing more and just want a way to share common data then you still will need the Net::Server).
In the end I'd benchmark a few of the Cache systems (Memcached, FastMmap, and IPC::Shareable) and see which one performs the best under your load circumstances.
Another solution that is even faster - assuming you don't care about whether the data is shared between the processes (if you don't care that each process has a full copy of the data in memory) - you could go with a hybrid approach where the parent updates the Cache and the child processes only periodically check the cache for updates and then copy the entire cache into perl variables local to the child processes. For 99% of the server needs this would probably be overkill.
I think it is about time to add a section discussing this to the PreFork perldoc.
my @a=qw(random brilliant braindead); print $a[rand(@a)];
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
|
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.