in reply to Repetitive File I/O vs. Memory Caching

Your understanding of data sharing in perl threads is not quite correct. You need to explicitly make that variable shared. Nothing is shared by default. Look at the threads::shared man page.

If you end up switching to a multi-process MPM, don't use Cache::SharedMemoryCache -- it is extremely slow. Use a fast one like BerkeleyDB (with built-in locking), Cache::FastMmap, or MySQL.

  • Comment on Re: Repetitive File I/O vs. Memory Caching

Replies are listed 'Best First'.
Re^2: Repetitive File I/O vs. Memory Caching
by Anonymous Monk on Mar 28, 2004 at 08:32 UTC

    It's the mod_perl that is threaded, not my perl script. Under a single-process/multi-threaded Apache, any variables declared such as what I did will share that variable across each mod_perl thread... it works for me anyhow :) If you don't believe me, pop this script under a mod_perl environment. Indeed, if I were using a multi-process Apache (forked rather than threaded), a separate count would be kept for each Apache process:

    #!c:/perl/bin/perl -w $|++; use strict; use CGI::Simple; use vars qw($count); # could also use our() my $CGI = CGI::Simple->new(); print $CGI->header(), ++$count;
      Sorry, it's just not true. There is no sharing between perl threads unless you declare it, and perl threads are what mod_perl uses. Now, you can load data during startup, and it will be copied into each thread (or process), but it will not be shared. As soon as you write anything to it after startup, the thread you did the writing in will have a different version of it than all the others.

      The script that you've shown here will show a seprate count for every thread. The only way tha variable could be the same for every request with this script is if you are actually only running one thread, so everything keeps hitting the same one. If you don't believe me, ask our resident threads expert, liz, or ask on the mod_perl list.