You are viewing a plain text version of this content. The canonical link for it is here.
Posted to modperl@perl.apache.org by Steven Lembark <le...@wrkhors.com> on 2001/07/01 01:25:41 UTC
Re: API Design Question
> 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.
sl
Re: RFC: Logging used Perl Modules (was Re: API Design Question)
Posted by Robin Berjon <ro...@knowscape.com>.
On Tuesday 03 July 2001 16:46, darren chamberlain wrote:
> James G Smith <JG...@TAMU.Edu> said something to this effect:
> > The current code I have uses %INC, but I wanted to write
> > something like the following:
> >
> > sub use : immediate {
> > # do stuff here if logging
> > return CORE::use(@_);
> > }
>
> To go OT here, what would 'immediate' be doing here, if Perl
> supported it?
It would run, well, immediately :) C<use> is run before the rest of the code
(apart from BEGIN blocks) which is why one can't overload it (now) iirc.
--
_______________________________________________________________________
Robin Berjon <ro...@knowscape.com> -- CTO
k n o w s c a p e : // venture knowledge agency www.knowscape.com
-----------------------------------------------------------------------
In which level of metalanguage are you now speaking?
Re: RFC: Logging used Perl Modules (was Re: API Design Question)
Posted by darren chamberlain <dl...@users.sourceforge.net>.
James G Smith <JG...@TAMU.Edu> said something to this effect on 07/03/2001:
> darren chamberlain <dl...@users.sourceforge.net> wrote:
> > James G Smith <JG...@TAMU.Edu> said something to this effect on 07/02/2001:
> > > Apache::Use
> >
> > You can get this information from %INC, can't you? e.g.:
>
> Most definitely. However, you lose information about which
> modules are needed more often than others. There's no difference
> between all scripts needing CGI.pm and one script needing
> Foo::Bar.
Good point.
> We also lose timing information. If 90% of the modules are
> loaded into the process with the last request before the child is
> destroyed, there's no point in loading them during the
> configuration phase. We can help this a little by taking
> snapshots of %INC at regular intervals (at the end of each
> request, for example).
>
> The current code I have uses %INC, but I wanted to write
> something like the following:
>
> sub use : immediate {
> # do stuff here if logging
> return CORE::use(@_);
> }
To go OT here, what would 'immediate' be doing here, if Perl
supported it?
(darren)
--
The three most dangerous things are a programmer with a soldering
iron, a manager who codes, and a user who gets ideas.
Re: RFC: Logging used Perl Modules (was Re: API Design Question)
Posted by darren chamberlain <dl...@users.sourceforge.net>.
James G Smith <JG...@TAMU.Edu> said something to this effect on 07/02/2001:
> How would something like this do:
>
> NAME
>
> Apache::Use
>
> SYNOPSIS
>
> use Apache::Use (Logger => DB, File => "/www/apache/logs/modules");
>
> DESCRIPTION
>
> Apache::Use will record the modules used over the course of the
> Perl interpreter's lifetime. If the logging module is able, the
> old logs are read and frequently used modules are automatically
> loaded. Note that no symbols are imported into packages.
You can get this information from %INC, can't you? e.g.:
use Time::Local;
use Data::Dumper;
use Apache;
warn map sprintf("%-20.20s\t%s\n", $_, $INC{$_}), keys %INC;
Exporter.pm /usr/local/perl/5.6.0/Exporter.pm
Carp.pm /usr/local/perl/5.6.0/Carp.pm
XSLoader.pm /usr/local/perl/5.6.0/i686-linux/XSLoader.pm
mod_perl.pm /usr/local/perl/site_perl/5.6.0/i686-linux/mod_perl.pm
strict.pm /usr/local/perl/5.6.0/strict.pm
Apache/Connection.pm /usr/local/perl/site_perl/5.6.0/i686-linux/Apache/Connection.pm
Time/Local.pm /usr/local/perl/5.6.0/Time/Local.pm
Apache/Table.pm /usr/local/perl/site_perl/5.6.0/i686-linux/Apache/Table.pm
DynaLoader.pm /usr/local/perl/5.6.0/i686-linux/DynaLoader.pm
overload.pm /usr/local/perl/5.6.0/overload.pm
Apache/Constants/Exp /usr/local/perl/site_perl/5.6.0/i686-linux/Apache/Constants/Exports.pm
AutoLoader.pm /usr/local/perl/5.6.0/AutoLoader.pm
Apache/Server.pm /usr/local/perl/site_perl/5.6.0/i686-linux/Apache/Server.pm
Data/Dumper.pm /usr/local/perl/5.6.0/i686-linux/Data/Dumper.pm
Apache.pm /usr/local/perl/site_perl/5.6.0/i686-linux/Apache.pm
Isn't this more or less what you mean?
(darren)
--
My studies in Speculative Philosophy, metaphysics, and science are all
summed up in the image of a mouse called man running in and out of every
hole in the Cosmos hunting for the Absolute Cheese.
-- Edmund Burke
Re: API Design Question
Posted by Stas Bekman <st...@stason.org>.
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:stas@stason.org http://apachetoday.com http://eXtropia.com/
http://singlesheaven.com http://perl.apache.org http://perlmonth.com/