Why does my script use much more memory when working with mod_perl?

I am trying to learn how to profile perl memory.

I have a very simple Perl hello-world script, and I want to know its size in memory.

I use the GTop utility to measure memory ( recommended in the mod_perl book by Stas Beckman). GTop gives me confusing results.

When I run the script from the command line, GTop says: 7M.

When I run it under mod_perl , GTop says: 54M.

Why so much?!

Why does script memory grow so much in mod_perl ? Or maybe I'm measuring memory incorrectly? How do you view perl script memory?

Here is the script and its output (I added commas manually to make numbers easy to read)

  • Run from command line

      > perl simple.pl 
    
     size: 7,282688
     share: 2,027520
     diff: 5,255168
    
  • Running in mod_perl mode

      size: 54,878208
     share: 4.661248
     diff: 50,216960
    

Script simple.pl

 #!/usr/bin/perl use strict; use warnings; use CGI (); my $cgi = CGI->new; print $cgi->header('text/plain'); use GTop; print "Hello, world!\n"; my $m = GTop->new->proc_mem($$); print "size: ".$m->size."\n"; print "share: ".$m->share."\n"; my $diff = $m->size - $m->share; print "diff: $diff\n"; 
+4
source share
1 answer

I think when you run your script in mod_perl, you get the memory usage of the script, plus mod_perl, plus apache.

See also the answers to these questions:

+7
source

All Articles