Fellow Monks
I discovered what I assumed to be a memory leak in an application I am writing
using CGI::Application as a base. Initially I blamed my OO style - believing
that some references were circular but this turned out to be untrue (I think).
The problem arises when using CGI::Application to return data to the browser. I used the following as a method to deliver images.
sub getimage { my $self = shift; my $stuff = shift; # Set the correct header $self->header_props( -type=>$stuff->{mime} ); open ( IMAGE , $stuff->{image} ) or die "Screaming $!"; return join '', <IMAGE>; }
Which functioned beautifully (once PodMaster slapped some sense into me regarding returning scalars to CGI:Application) however my httpd processes grew at an alarming rate. For every 1Mb image served , httpd grows by a larger amount.
PID USER PRI NI SIZE RSS SHARE STAT %CPU %MEM TIME COMMAND 18388 root 15 0 2848 2848 2736 S 0.0 0.5 0:00 httpd 18389 vvr 18 0 2836 2836 2716 S 0.0 0.5 0:00 httpd 18390 vvr 18 0 2836 2836 2716 S 0.0 0.5 0:00 httpd
PID USER PRI NI SIZE RSS SHARE STAT %CPU %MEM TIME COMMAND 18388 root 15 0 2848 2848 2736 S 0.0 0.5 0:00 httpd 18389 vvr 15 0 31940 31M 2372 S 0.0 6.2 0:00 httpd 18390 vvr 18 0 2836 2836 2716 S 0.0 0.5 0:00 httpd
The resident memory size has grown from under 3Mb to over 31Mb. Almost 5 times the size of the data actually served. I am most curious to hear from anyone who has experienced similar behaviour (with CGI::Application especially).
This is occuring on a RH7.3 system, using apache1.3.26 and mod_perl 1.27. Below is the smallest case that exhibits this behaviour.
#!/usr/bin/perl -w # foo.pm , to be executed by Apache package foo; use strict; use base 'CGI::Application'; use CGI::Carp; sub handler { warn "## handler"; my $request = shift; my $app = foo->new(); $app->run(); exit; } sub setup { warn "## setup"; my $self = shift; $self->run_modes( start=>'start' ); } sub start { warn "## start"; my $self = shift; open ( FH , '/path/to/some/image' ) or confess $!; $self->header_props( -type=>'your/mimetype' ); return join '' , <FH>; } 1;
PerlModule Apache PerlModule foo <Location /testleak/> SetHandler perl-script PerlHandler foo </Location>
If you've solved this before, or think you can see where I have done something bass-ackwards please let me know.
In reply to CGI::Application + mod_perl =|!= memory leak by submersible_toaster
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |