dcsimg

Improving mod_perl Driven Site's Performance -- Part II: Benchmarking Applications

By Stas Bekman (Send Email)
Posted Dec 16, 2000


In this article we will talk about tools that we need to get armed with before we can start working on the performance of our service.

In this article we will talk about tools that we need to get armed with before we can start working on the performance of our service. In order to improve performance we need measurement tools. The main tool categories are benchmarking and code profiling.

Essential Tools

In order to improve performance we need measurement tools. The main tool categories are benchmarking and code profiling.

It's important to understand that in a major number of the benchmarking tests that we will execute we will not look at the absolute result numbers but the relation between the two and more result sets. The purpose of the benchmarks is to try to show which coding approach is preferable. You shouldn't try to compare the absolute results presented in the articles with those that you get while running the same benchmarks on your machine, since you won't have the exact hardware and software setup anyway. This kind of comparison would be misleading. If you compare the relative results from the tests running on your machine, you will do the right thing.

Benchmarking Applications

How much faster is mod_perl than mod_cgi (aka plain perl/CGI)? There are many ways to benchmark the two. I'll present a few examples and numbers below. Check out the benchmark directory of the mod_perl distribution for more examples.

If you are going to write your own benchmarking utility, use the Benchmark module for heavy scripts and the Time::HiRes module for very fast scripts (faster than 1 sec) where you will need better time precision.

There is no need to write a special benchmark though. If you want to impress your boss or colleagues, just take some heavy CGI script you have (e.g. a script that crunches some data and prints the results to STDOUT), open two xterms and call the same script in mod_perl mode in one xterm and in mod_cgi mode in the other. You can use lwp-get from the LWP package to emulate the browser. The benchmark directory of the mod_perl distribution includes such an example.

Benchmarking Perl Code

If you are going to write your own benchmarking utility, use the Benchmark module and the Time::HiRes module where you need better time precision (<10msec).

An example of the Benchmark.pm module usage:


  benchmark.pl
  ------------
  use Benchmark;

  timethis (1_000,
   sub {
    my  = 100;
    my  = log ( ** 100)  for (0..10000);
  });
  % perl benchmark.pl
  timethis 1000: 25 wallclock secs (24.93 usr +  0.00 sys = 24.93 CPU)

If you want to get the benchmark results in micro-seconds you will have to use the Time::HiRes module, its usage is similar to Benchmark's.

  use Time::HiRes qw(gettimeofday tv_interval);
  my  = [ gettimeofday ];
  sub_that_takes_a_teeny_bit_of_time();
  my  = [ gettimeofday ];
  my  = tv_interval(,);
  print "The sub took  seconds."

Benchmarking a Graphic Hits Counter with Persistent DB Connections

Page 1 of 6


Comment and Contribute

Your name/nickname

Your email

(Maximum characters: 1200). You have characters left.