29219 nobody 8860 10528 0.0 2.2 httpd_perl 29220 nobody 9616 11200 0.5 2.4 httpd_perl 29221 nobody 8860 10528 0.0 2.2 httpd_perl 29222 nobody 8860 10528 0.0 2.2 httpd_perl 29224 nobody 8860 10528 0.0 2.2 httpd_perl 29225 nobody 9760 11340 0.7 2.5 httpd_perl 29235 nobody 9524 11104 0.4 2.4 httpd_perl
Now you can see the resident (RSS
) and virtual (VSZ
) memory
segments (and shared memory segment if you ask for it) of all mod_perl
processes. Please refer to the top(1)
and ps(1)
man pages for more
information.
You probably agree that using top(1)
and ps(1)
is cumbersome if we
want to use memory size sampling during the benchmark test. We want to
have a way to print memory sizes during the program execution at
desired places. If you have GTop
modules installed, which is a perl
glue to the libgtop
library, it’s exactly what we need.
Note: GTop
requires the libgtop
library but is not available for
all platforms. Visit http://www.home-of-linux.org/gnome/libgtop/ to
check whether your platform/flavor is supported.
GTop
provides an API for retrieval of information about processes
and the whole system. We are interested only in memory sampling API
methods. To print all the process related memory information we can
execute the following code:
use GTop; my = GTop->new; my = ->proc_mem(20266); for (qw(size vsize share rss)) { printf " %s => %dn", sh, ->sh(); }
When executed we see the following output (in bytes):
size => 1900544 vsize => 3108864 share => 1392640 rss => 1900544
So if we are interested in to print the process resident memory
segment before and after some event we just do it: For example if we
want to see how much extra memory was allocated after a variable
creation we can write the following code:
use GTop; my = GTop->new; my = ->proc_mem(20266)->rss; my = 'a' x 10000; my = ->proc_mem(20266)->rss; print "diff: ",-, " bytesn";and the output
diff: 20480 bytesSo we can see that Perl has allocated extra 20480 bytes to create
(of course the creation of
after
needed a few bytes as well,
but it's insignificant compared to a size of)
The
Apache::VMonitor
module with help of theGTop
module allows
you to watch all your system information using your favorite browser
from anywhere in the world without a need to telnet to your machine.
If you are looking at what information you can retrieve withGTop
,
you should look atApache::VMonitor
as it deployes a big part of
the APIGTop
provides.If you are running a true BSD system, you may use
BSD::Resource::getrusage
instead ofGTop
. For example:print "used memory = ".(BSD::Resource::getrusage)[2]."n"For more information refer to the
BSD::Resource
manpage.Measuring the Memory Usage of Subroutines
With help of
Apache::Status
you can find out the size of each
and every subroutine.
Build and install mod_perl as you always do, make sure it's version
1.22 or higher.