On Wed, 9 May 2001, Morbus Iff wrote:

> I'm relatively new to mod_perl... I've got a 700k file that is loaded each 
> time I run a CGI script, so I'm hoping to cache the file using mod_perl 
> somehow. The file will change occasionally (maybe once a week) - the reload 
> of a few seconds isn't worrisome, but it has to be done without restarting 
> the server.
[...]
> ** The 700k file is an XML file, read in by XML::Simple. XML::Simple can 
> cache that file into memory. Is this how I should do it? Or should I load 
> the file from my startup.pl script so that the file is shared amongst all 
> the apache children? 

As others have pointed out it'll only be shared until you reload it
so I wouldn't worry about it.

Things I would try:

   1) Have an external process parse the XML::Simple into the
      datastructure you need and save it with Storable::nfreeze.
      Then the apache processes can load it with thaw which should
      be much faster and might very well use less memory than the
      XML::Simple foo.

      For checking for updates something like 

      my $last_reload = 0;
      my $last_check  = 0;
      sub handler {
         reload_data() if time >= $last_check+3600; # check every hour
         [...]
      }

      sub reload_data {
        $last_check = time;
        return unless (stat "/home/foo/data/datafile")[9] > $last_reload;
        
        # load data
               
        $last_load = time;
      }       
      

   2) Save the data in a BerkeleyDB 3 database (which can be
      shared) and have an external process just load the data into
      it. Update will "just work".


 - ask


-- 
ask bjoern hansen, http://ask.netcetera.dk/   !try; do();
more than 100M impressions per day, http://valueclick.com

Reply via email to