You are viewing a plain text version of this content. The canonical link for it is here.
Posted to modperl@perl.apache.org by Jason Leidigh <jl...@uol.com.ar> on 2001/03/15 19:50:52 UTC
Memory Leaks?
At the the mod_perl/Apache web site (http://perl.apache.org/faq/#Why_is_httpd_using_so_much_memor)
there is a section about memory usage and a subroutine is given which can help test for memory leaks which perl "does no overtly report"
Joel Wagner reports that calling an undefined subroutine in a module can cause a tight loop that consumes all memory. Here is a way to catch such errors. Define an autoload subroutine
sub UNIVERSAL::AUTOLOAD {
my $class = shift;
warn "$class can't `$UNIVERSAL::AUTOLOAD'!\n";
}
It will produce a nice error in error_log, giving the line number of the call and the name of the undefined subroutine.
I edited this to get a little more info:
sub UNIVERSAL::AUTOLOAD {
my $class = shift;
my($package,$file,$line) = caller;
warn "$class can't `$UNIVERSAL::AUTOLOAD'\n\tCaller Info:\n\t$package\n\t$file\n\t$line\n";
$" = "\n";
warn @_ , "\n\n";
}
I was able to clean up a number of errors which seemed as though they were indeed causing leaks. For example:
$regex = qr'xx?'i;
Causes the following error:
(?i-xsm:xx?) can't `Regexp::DESTROY'
Caller Info:
Apache::JProxy
/usr/local/apachessl/mod_perl/Apache/JProxy.pm
780
The only solution I found was to not precompile the regex but it would definilty be nice so as to save some time as I repeatedly use numeros patterns which I was precompliling.
Another error I found was with the use of LWP:
LWP::UserAgent=HASH(0x5acb10) can't `LWP::UserAgent::DESTROY'
Caller Info:
Apache::JProxy
/usr/local/apache2_mod_perl/mod_perl/Apache/JProxy.pm
980
I was able to erradicat this error by adding DynaLoader to the @ISA of LWP::UserAgent.
OK not so bad but one error I have been unable erradicat is the following:
Apache=SCALAR(0x84da840) can't `Apache::DESTROY'
Caller Info:
main
/dev/null
0
I have not found that Apache,pm has a ISA to add dynaloader to and I have not yet trid adding it my self but......any ideas on where this (apparent) leak is comming from? It adds 4k to a child per request. On a site with the amount of traffic we have that is death!!!!
Thanks in advance!
Jason Z. Leidigh
Project Leader
UOL Internacional
Av.Libertador 1068 - Piso 3
Capital Federal - ( C1112ABN )
Buenos Aires - Argentina
T.E: 0054-11-5777-2446
Fax: 0054-11-5777-2402
www.uol.com.ar
jleidigh@uol.com.ar
Re: Memory Leaks?
Posted by Robin Berjon <ro...@knowscape.com>.
At 15:50 15/03/2001 -0300, Jason Leidigh wrote:
>I was able to clean up a number of errors which seemed as
>though they were indeed causing leaks. For example:
>
>$regex = qr'xx?'i;
>
>Causes the following error:
>
>(?i-xsm:xx?) can't `Regexp::DESTROY'
AUTOLOADs will catch DESTROYs, the latter being called on every object
destruction (I never noticed that they were called on regexen, that's
nice). Chances are, unless you clearly see a memory leak with DESTROYs
(which are expected not to be found most of the time) then your AUTOLOAD
should probably explicitly ignore them.
Another solution is:
sub Regexp::DESTROY {}
sub Apache::DESTROY {}
etc...
-- robin b.
"Science is like sex: sometimes something useful comes out, but that is not
the reason we are doing it." -- R. Feynman