Thomas Hilbig wrote:
> I have about a dozen small cgi programs under mod_perl2 that all pretty well look like this..
>
> use CGI;
> use DBI;
> use perlchartdir ; # graphing


To think about how this works under mod_perl, pretend that all of your scripts are put together into
1 larger script and all those "use" statements are repeated. Does having multiple "use CGI"
statements make your script use more memory? No. CGI.pm is only loaded once.

> Under mod_perl, will the memory footprint of the libraries be shared across all of the programs that use them


The specifics depend on what OS you're running, what version of Apache/mod_perl you're running, but
it's basically like this: Each Apache child has it's own Perl interpreter and what is loaded in that
interpreter is persistant across requests. So different scripts can use the same CGI.pm or DBI that
you've loaded for another script. Combining them all into the same program won't make any noticeable
difference in memory one way or the other.

> I also use a PerlRequire startup.pl to preload most modules (CGI, DBI), but I thought that was only for quicker startup times and not for sharing memory. Is that correct?


Preloading helps with speed (you don't get the the initial loading hit for a module the first time
it's used in a specific process) but it can also help with memory on certain OSs. For instance,
Linux has Copy-On-Write memory so that if you preload modules it saves on actual physical RAM used
(even though the separate processes think they have their own separate memory spaces).

But remember that each Apache child get's it's own perl interpreter. So if you have a high
MaxClients you will run out of memory. It's basically Perl Memory * MaxClients for how much RAM
could be used if your system got busy. This is one of the reasons that most people put a vanilla
Apache (or something else like squid, lighttpd, varnish, etc) in front as a Proxy. When you do that,
even if you're running both the proxy and the mod_perl server on the same physical machine you need
a lot less RAM then if you just ran a mod_perl server trying to do static and dynamic requests.

HTH

--
Michael Peters
Plus Three, LP