Reputation: 1821
I have a requirement wherein
I have to place a data structure (Perl hash) in memory, so that each HTTP process (running a Perl script) will use that hash.
The hash structure is around 300 MB.
The environment is mod_perl
I thought of creating a module to load at Apache start that creates a hash in a shared region and returns a reference to it.
Can you please comment on the behaviour, or suggest alternative solutions. Also please point to some good resources to check the examples.
Upvotes: 4
Views: 545
Reputation: 44
If you place huge hash data on mod_perl memory, then mod_perl parent process reads it at server startup phase.
In first, you create Your/HugeData.pm
on @INC
directory.
package Your::HugeData;
our %dictionary = (
....
);
Next, apache process reads this on startup.
# In apache.conf (or anywhere apache config file)
PerlModule Your::HugeData
Then your script can use %Your::HugeData::dictionary
as package variable.
# In mod_perl handler script or ModPerl::Registry (CGI emulate) script.
use Your::HugeData;
...
my $tokyo = $Your::HugeData::dictionary{tokyo};
When you use prefork MPM on Linux Apache, OS prefers "Copy on Write" mechanism. So forked child processes see parent proces'es data if you only read the data. In other words, there may be not waste memory using.
Upvotes: 1