You are viewing a plain text version of this content. The canonical link for it is here.
Posted to modperl@perl.apache.org by "Ruslan U. Zakirov" <cu...@wildgate.miee.ru> on 2003/09/25 11:36:43 UTC
[MP1] Memory usage(eating, leaking)
Hi, all.
I'm looking for suggestions, information, may be atricles about
different memory usage issues concerned with mod_perl1.
On one Russian forum man posted an review of memory "leaks"(caveats):
sub handler
{
my $r = shift;
$r->send_http_header('text/plain');
print "Hello, World!\n";
print ttt();
return OK;
}
sub ttt
{
my $huge_text = 'x' x 1000000;
my $huge_text = $huge_text . "abc" . "bcd";
return 1;
}
1) Restart Apache
2) Start `top`
3) Request.
4) Apache eats ~4MB instead of 1....
I know that mod_perl(or may be perl) don't free memory of $huge_string
because most likely it will be needed in next call, but also it take
another MBs for concatenation. Why?
Above example uses ~4MB of memory and until child restart apache don't
free memory.
But if I want to prevent huge memory usage I can add undef($huge_text);
just before return, but undef force freeing of only 1MB. ~3MB leaks and
make me use MaxRequestsPerChild... :(
It's an hypothetical example, but now we use huge system(RT from Best
Practical) and without limiting requests per child we fall in apache
lock down.
How to debug this situations. I want to find way how to change some
calls that allow perl don't allocate additional memory. I'm looking for
approaches of debuging such leaks.
Best regards. Ruslan.
Re: [MP1] Memory usage(eating, leaking)
Posted by Perrin Harkins <pe...@elem.com>.
On Thu, 2003-09-25 at 05:36, Ruslan U. Zakirov wrote:
> I'm looking for suggestions, information, may be atricles about
> different memory usage issues concerned with mod_perl1.
The best information about this kind of tuning is at
http://perl.apache.org/ and in the book "Practical mod_perl" from
O'Reilly.
> On one Russian forum man posted an review of memory "leaks"(caveats):
>
> sub handler
> {
> my $r = shift;
> $r->send_http_header('text/plain');
> print "Hello, World!\n";
> print ttt();
> return OK;
> }
> sub ttt
> {
> my $huge_text = 'x' x 1000000;
> my $huge_text = $huge_text . "abc" . "bcd";
> return 1;
> }
>
> 1) Restart Apache
> 2) Start `top`
> 3) Request.
> 4) Apache eats ~4MB instead of 1....
When I run this (with a few changes to make it a valid module), my
apache uses 3784K of memory total, and more than half of that is shared,
leaving only 1620K per child actually being used. It doesn't grow if I
keep hitting the same handler over and over. There is no leak.
> I know that mod_perl(or may be perl) don't free memory of $huge_string
> because most likely it will be needed in next call, but also it take
> another MBs for concatenation. Why?
It's just a matter of how Perl does the concatenation. When you write
it this way, it creates a temporary string and uses more memory. It
doesn't take the additional memory if you do it like this instead:
$huge_text .= "abc" . "bcd";
You can see the same effect in a command-line Perl program.
> But if I want to prevent huge memory usage I can add undef($huge_text);
> just before return, but undef force freeing of only 1MB. ~3MB leaks and
> make me use MaxRequestsPerChild... :(
It's not really leaking (it doesn't grow). You can't undef the
temporary string you created because you have no name to reference it
by.
> It's an hypothetical example, but now we use huge system(RT from Best
> Practical) and without limiting requests per child we fall in apache
> lock down.
I don't know enough about RT to comment on it, but it's a mistake to run
any mod_perl system without Apache::SizeLimit (or Apache::GTopLimit)
enabled.
- Perrin
Re: [MP1] Memory usage(eating, leaking)
Posted by Mark Hawkes <ha...@onetel.net.uk>.
At 13:36 2003-09-25 +0400, you wrote:
> Hi, all.
>I'm looking for suggestions, information, may be atricles about different
>memory usage issues concerned with mod_perl1.
Hi there,
This contains some pretty good tips...
Code Profiling and Memory Measurement Techniques
http://www.apacheweek.com/features/mod_perl10
Mark