faqts : Computers : Programming : Languages : Perl : webside heack : Tips and Tricks

+ Search
Add Entry AlertManage Folder Edit Entry Add page to http://del.icio.us/
Did You Find This Entry Useful?

9 of 12 people (75%) answered Yes
Recently 7 of 10 people (70%) answered Yes

Entry

How can i share a data structure (e.g.: a Hash Table) between the Apache's (child) processes?

Oct 9th, 2001 05:41
Robert Dober, Luis Campos de Carvalho,


Unfortunately I came up late on your question, but maybe it still helps.
You can preload any module and initialize its data during Server 
Startup. 
Either within a <perl> section in your startup file or -even better- in 
a perl startup file...
e.g.
<code>
use MyBigData::Module;
MyBigData::Module::initData();
</code>
As long as you do not modify the page where the data is stored it will 
stay shared. There are more details in the excellent mod_perl guide ==> 

<ref>
"http://perl.apache.org/guide/performance.html#Sharing_Memory"
</ref>
 
It works out fine for me. I preload data about the state of about 50 
UNIX machines. By timer events or by requests the data gets updated and 
the memory pages "unshared". In order to get some memory back I reshare 
the data by restarting child processes after 200 requests (as mentioned 
in the guide with the MaxRequestsPerChild directive). Gives me a good 
compromise between speed and memory.

Hope that helped.
Cheers
Robert