Re: [MP1] Memory usage(eating, leaking)
- On Thu, 2003-09-25 at 05:36, Ruslan U. Zakirov wrote:
> I'm looking for suggestions, information, may be atricles aboutThe best information about this kind of tuning is at
> different memory usage issues concerned with mod_perl1.
http://perl.apache.org/ and in the book "Practical mod_perl" from
> On one Russian forum man posted an review of memory "leaks"(caveats):When I run this (with a few changes to make it a valid module), my
> sub handler
> my $r = shift;
> 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....
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_stringIt's just a matter of how Perl does the concatenation. When you write
> because most likely it will be needed in next call, but also it take
> another MBs for concatenation. Why?
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);It's not really leaking (it doesn't grow). You can't undef the
> just before return, but undef force freeing of only 1MB. ~3MB leaks and
> make me use MaxRequestsPerChild... :(
temporary string you created because you have no name to reference it
> It's an hypothetical example, but now we use huge system(RT from BestI don't know enough about RT to comment on it, but it's a mistake to run
> Practical) and without limiting requests per child we fall in apache
> lock down.
any mod_perl system without Apache::SizeLimit (or Apache::GTopLimit)