On Sat, 30 Jun 2001, Steven Lembark wrote:

>
>
> > Note that if they do get called this will end up using more memory than if
> > you had just loaded them during startup, since they won't be shared between
> > child processes.
>
> Original assumption is that they are called infrequently.  You'll also find
> that the amount of memory sucked up by a single subroutine isn't much,
> less than pre-loading possibly 10' s of sub's that never get called.

The optimal approach would be

1. Use CGI.pm's like -compile import tag or Autosplit/Autoload to
provide the interface for loading only the wanted subs.

2. Use DB::DB hook to collect the stats on what subs are actually used See
this nice article for more info:
http://www.ddj.com/columns/perl/2001/0103pl002.htm?topic=perl

3. Use ab or something else to exercise your service to call all possible
URIs/args. Here you can use the access_log to feed learn what to feed to
ab assuming that access_log is big enough to exercise all your services
(which of course won't work for new services, and then you have to supply
the possible URIs/args by yourself)

4. Feed the results of 2 and 3 into 1 in startup.pl and voila you have the
perfect optimization.

5. If you modify your code you need either to rerun the stats collection
or manually adjust the startup.pl file.

Depending on how important is to squeeze the most our of your boxes and
how big is your code base, this scenario may or may not apply to your
situation, but it gives you a good idea of how Perl can help you.

All these stages can be completely automated.

This seems to be an interesting project for someone to implement and
release as a general module. So one can plug a stats handler which will
collect all the used modules (so you can preload them all at startup.pl)
and all used package::sub's to be fed into modules using
autosplit/autoload to load these from startup.pl.

Here is a simple Apache::UsedModules

package Apache::UsedModules;

use strict;
use Apache;

if($ENV{MOD_PERL}) {
    Apache->push_handlers(PerlChildExitHandler => \&handler);
}

sub handler {
    my $r = shift;

    my $file = "/tmp/modules.$$";
    open LOG, ">$file" or die "cannot open $file: $!";
    print LOG "\n# Used modules\n\n";
    for (sort grep !/^main$/, keys %INC){
        next if m!^/|\.pl$!; # skip non modules
        print LOG qq{require "$_";\n}; # ($INC{$_})\n";
    }
    close LOG;

}
1;

usage:
PerlModule Apache::UsedModules

or
use Apache::UsedModules; # in startup.pl

For subs stats you actually need to rework the DB::DB hook from
Apache::DB or write a new one based on Apache::DB (preferrably).

_____________________________________________________________________
Stas Bekman              JAm_pH     --   Just Another mod_perl Hacker
http://stason.org/       mod_perl Guide  http://perl.apache.org/guide
mailto:[EMAIL PROTECTED]   http://apachetoday.com http://eXtropia.com/
http://singlesheaven.com http://perl.apache.org http://perlmonth.com/



Reply via email to