Loading ...
Sorry, an error occurred while loading the content.
 

Re: [MP1] Memory usage(eating, leaking)

Expand Messages
  • Perrin Harkins
    ... The best information about this kind of tuning is at http://perl.apache.org/ and in the book Practical mod_perl from O Reilly. ... When I run this (with
    Message 1 of 3 , Sep 27, 2003
      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
    Your message has been successfully submitted and would be delivered to recipients shortly.