dcsimg

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

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


  # Register all requests
  ###
  foreach (1..) {
    foreach my  (@urls) {
      my  = HTTP::Request->new('GET', );
      ->register();
    }
  }

  ###
  # Launch processes and check time
  ###
  my  = [gettimeofday];
  my  = ->wait();
  my  = tv_interval();

  ###
  # Requests all done, check results
  ###

  my      = 0;
  my %errors = ();

  foreach my  (values %) {
    my  = ->response();
    if(->is_success()) {
      ++; # Another satisfied customer
    } else {
      # Error, save the message
      ->message("TIMEOUT") unless ->code();
      {->message}++;
    }
  }

  ###
  # Format errors if any from %errors
  ###
  my  = join(',', map "sh ({sh})", keys %errors);
   = "NONE" unless ;

  ###
  # Format results
  ###

  #@urls = map {(sh,".")} @urls;
  my @P = (
        "URL(s)"          => join("\n\t\t ", @urls),
        "Total Requests"  => "",
        "Parallel Agents" => ,
        "Succeeded"       => sprintf(" (%.2f%%)\n",
                                    * 100 / ),
        "Errors"          => ,
        "Total Time"      => sprintf("%.2f secs\n", ),
        "Throughput"      => sprintf("%.2f Requests/sec\n",
                                    / ),
        "Latency"         => sprintf("%.2f secs/Request",
                                   (->get_latency_total() || 0) /
                                   ),
       );


  my (, );
  ###
  # Print out statistics
  ###
  format STDOUT =
  @<<<<<<<<<<<<<<< @*
  ":",        
  .

  while((, ) = splice(@P, 0, 2)) {
    write;
  }

Benchmarking PerlHandlers

The Apache::Timeit module does PerlHandler Benchmarking. With the help of this module you can log the time taken to process the request, just like you'd use the Benchmark module to benchmark a regular Perl script. Of course you can extend this module to perform more advanced processing like putting the results into a database for a later processing. But all it takes is adding this configuration directive inside httpd.conf:

  PerlFixupHandler Apache::Timeit

Since scripts running under Apache::Registry are running inside the PerlHandler these are benchmarked as well.

An example of the lines which show up in the error_log file:

  timing request for /perl/setupenvoff.pl:
    0 wallclock secs ( 0.04 usr +  0.01 sys =  0.05 CPU)
  timing request for /perl/setupenvoff.pl:
    0 wallclock secs ( 0.03 usr +  0.00 sys =  0.03 CPU)

The Apache::Timeit package is a part of the Apache-Perl-contrib files collection available from CPAN.

References



Comment and Contribute

Your name/nickname

Your email

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