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

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;

Replies are listed 'Best First'.
Re: Re^2: Repetitive File I/O vs. Memory Caching
by perrin (Chancellor) on Mar 28, 2004 at 17:25 UTC
    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.