SHARE
Facebook X Pinterest WhatsApp

Improving mod_perl Driven Site’s Performance — Part III: Code Profiling and Memory Measurement Techniques Page 4

Written By
thumbnail Jeremy Reed
Jeremy Reed
Jan 1, 2001
ServerWatch content and product recommendations are editorially independent. We may make money when you click on links to our partners. Learn More



  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 bytes

So 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 the GTop 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 with GTop,
you should look at Apache::VMonitor as it deployes a big part of
the API GTop provides.

If you are running a true BSD system, you may use
BSD::Resource::getrusage instead of GTop. 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.

  1. Build and install mod_perl as you always do, make sure it's version
    1.22 or higher.

thumbnail Jeremy Reed

Jeremy Reed is a ServerWatch contributor.

Recommended for you...

Data Center Survey 2021: Outages Less Common, More Expensive
Sam Ingalls
Sep 21, 2021
On-Prem Infrastructure is Here to Stay. But What Workloads Go Where?
Sam Ingalls
Jul 3, 2021
IBM’s 2nm Breakthrough: Implications for Chip and Server Makers
Sam Ingalls
Jun 4, 2021
A Tale of Two 3rd Gen Processors: AMD & Intel
Sam Ingalls
May 20, 2021
ServerWatch Logo

ServerWatch is a top resource on servers. Explore the latest news, reviews and guides for server administrators now.

Property of TechnologyAdvice. © 2025 TechnologyAdvice. All Rights Reserved

Advertiser Disclosure: Some of the products that appear on this site are from companies from which TechnologyAdvice receives compensation. This compensation may impact how and where products appear on this site including, for example, the order in which they appear. TechnologyAdvice does not include all companies or all types of products available in the marketplace.