Hi,

I've been looking for a good technique to find out what module is
using all my memory.

Imagine some sneaky user creates this module:

package MemoryHog;

my %big_hash;
sub handler {
       my $r = shift;

       foreach (1..1_000_000) {
               $big_hash{$_} = $_ * 5;
       }

       $r->print("I've hogged some memory");

       return 200;
}

1;

Then, puts this in httpd.conf:
PerlModule MemoryHog
<Location /hogmem>
   SetHandler perl-script
   PerlHandler MemoryHog
</Location>

I run top and see that all my httpd children processes are using about
30 mb.  Then the sneaky user goes to http://localhost/hogmem/.  I
check top again and see that one process is using over 100 mb while
the other httpd's still hover around 30 mb!  Ack! I need to find out
how that happened so I can tell that sneaky user to get that code off
my box!

How do I track down that MemoryHog.pm is what is using all my memory?

I've tried Apache::Status, Apache::VMonitor, but no where was I able
to get the information I needed.  There was no way I could tell what
module was sucking up all the memory.  I followed the techiniques in
Practical mod_perl:
http://modperlbook.org/html/ch09_04.html but this only told me how
much memory the *code* was using, not how much memory the package's
variables where sucking up.  /perl-status/ tells me that MemoryHog is
using 5142 bytes, which is kind of useless for me.

I'm considering writing a PerlLogHandler that will print out the
memory usage (using GTop) before and after each request so I can find
the offending code path.

Links to books or articles would be much appreciated.

Thanks!
Jay

Reply via email to