ServersImproving mod_perl Driven Site's Performance -- Part III: Code Profiling and Memory...

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

ServerWatch content and product recommendations are editorially independent. We may make money when you click on links to our partners. Learn More.




Another approach is to use Apache::DProf, which hooks
Devel::DProf into mod_perl. The Apache::DProf module will run a
Devel::DProf profiler inside each child server and write the
tmon.out file in the directory /logs/dprof/20264 when
the child is shutdown (where 20264 is the number of the child
process). All it takes is to add to httpd.conf:

  PerlModule Apache::DProf

Remember that any PerlHandler that was pulled in before
Apache::DProf in the httpd.conf or startup.pl, will not have
its code debugging information inserted. To run dprofpp, chdir to
/logs/dprof/20264 and run:

  % dprofpp

(Lookup the ServerRoot directive’s value in httpd.conf to figure
out what’s your .)

Measuring the Memory of the Process

A very important aspect of performance tuning is to make sure that your
applications don’t use much memory; since if they do, you cannot run
many servers and therefore in most cases under a heavy load the
overall performance degrades.

In addition the code may not be clean and leak memory, which is even
worse, since if the same process serves many requests and after each
request more memory is used; after a while all RAM will be used and
the machine will start swapping (use the swap partition), which is a very
undesirable event since it may lead to a machine crash.

The simplest way to figure out how big the processes are and see
whether they grow is to watch the output of top(1) or ps(1) utilities.

For example the output of top(1):

    8:51am  up 66 days,  1:44,  1 user,  load average: 1.09, 2.27, 2.61
  95 processes: 92 sleeping, 3 running, 0 zombie, 0 stopped
  CPU states: 54.0% user,  9.4% system,  1.7% nice, 34.7% idle
  Mem:  387664K av, 309692K used,  77972K free, 111092K shrd,  70944K buff
  Swap: 128484K av,  11176K used, 117308K free                170824K cached
     PID USER PRI NI SIZE  RSS SHARE STAT LIB %CPU %MEM   TIME COMMAND
  29225 nobody 0  0  9760 9760  7132 S      0 12.5  2.5   0:00 httpd_perl
  29220 nobody 0  0  9540 9540  7136 S      0  9.0  2.4   0:00 httpd_perl
  29215 nobody 1  0  9672 9672  6884 S      0  4.6  2.4   0:01 httpd_perl
  29255 root   7  0  1036 1036   824 R      0  3.2  0.2   0:01 top
    376 squid  0  0 15920  14M   556 S      0  1.1  3.8 209:12 squid
  29227 mysql  5  5  1892 1892   956 S N    0  1.1  0.4   0:00 mysqld
  29223 mysql  5  5  1892 1892   956 S N    0  0.9  0.4   0:00 mysqld
  29234 mysql  5  5  1892 1892   956 S N    0  0.9  0.4   0:00 mysqld

Which starts with overall information of the system and then displays
the most active processes at the given moment. So for example if we
look at the httpd_perl processes we can see the size of the
resident (RSS) and shared (SHARE) memory segments. This sample
was taken on the production server running linux.

But of course we want to see all the apache/mod_perl processes, and
that's where ps(1) comes to help. The options of this utility vary
from one Unix flavor to another, and some flavors provide their own
tools. Let's check the information about mod_perl processes:

  % ps -o pid,user,rss,vsize,%cpu,%mem,ucomm -C httpd_perl
    PID USER      RSS   VSZ %CPU %MEM COMMAND
  29213 root     8584 10264  0.0  2.2 httpd_perl
  29215 nobody   9740 11316  1.0  2.5 httpd_perl
  29216 nobody   9668 11252  0.7  2.4 httpd_perl
  29217 nobody   9824 11408  0.6  2.5 httpd_perl
  29218 nobody   9712 11292  0.6  2.5 httpd_perl

Get the Free Newsletter!

Subscribe to Daily Tech Insider for top news, trends & analysis

Latest Posts

Related Stories