On Nov 7, 2007, at 11:59 AM, Michael Peters wrote:
Boysenberry Payne wrote:
Is Apache::SharedMem working with mod_perl2 the "same" way it did
with
mod_perl1?
Don't know, haven't used it. It hasn't been updated since 2001, so
either it's
perfect and hasn't needed any changes or it's not being maintained.
Yeah, that's why I asked...
Is Apache::SharedMem the "preferred" way to handle sharing memory
between apache children?
It's definitely not "preferred", but I'm not sure what is. It
depends on what
you're doing with the data and how often it changes. If it's static
you can just
load the data at startup in a Perl module. If it changes a lot you
can use BDB.
If it's something that needs to be shared by multiple machines then
use
something external like MySQL. If it's just some cached data then
use something
like memcached or Cache::FastMmap.
Does memcached or Cache::FastMap work with apache's shared memory pool?
I'm basically trying to organize my references along 3 lines:
- runtime data dumped with each request
- per child data sticks around as long as the apache child exists
- apache shared data sticks around for the life of the root apache
process
I'm sure there are other memory areas to deal with, but those are my
primary concerns.
I'm looking for a way to control where my references point to in memory.
For example, a already have startup.pl file included in apache's root
httpd.conf
in the form of:
in the httpd.conf file:
<snip>
# Startup file for loading assets into memory
PerlRequire /directory/to/startup.pl
</snip>
and in the startup.pl file:
<snip>
#!/usr/bin/perl
BEGIN {
use lib qw(/directory/to/perl_mods);
}
use Apache::DBI ();
...(many more too)...
1;
</snip>
In this situation if its possible (which it should be for my own
modules) I would like
the package symbol table and contents to be loaded into the shared
server wide memory.
How could I insure the packages aren't loaded into each child process?
If a package is loaded into "shared" memory is "our" and "my" handled
the same as they are
when its loaded into the apache child process memory?
Are modules loaded using "use ModuleName;" in an apache startup.pl
file
loaded into shared memory
or copied to each child separately?
There's nothing special about "use". "require" would work just as
well. The
thing to remember is that you need to load the Perl modules into
the Apache
process's memory before it forks. Anything loaded before the fork
will be shared
(as long as it doesn't change) with Copy-On-Write.
I'm sure I've read about Copy-On-Write, better safe than sorry, have
any links you can
point me at that will allow me to understand it better? I want to
make sure if I write
I don't copy unless I'm sure that's what I need to do (like for
temporary runtime changes.)
Thanks,
-bop