SHARE
Facebook X Pinterest WhatsApp

Improving mod_perl Driven Site’s Performance — Part II: Benchmarking Applications Page 5

Written By
thumbnail Stas Bekman
Stas Bekman
Jul 20, 2010
ServerWatch content and product recommendations are editorially independent. We may make money when you click on links to our partners. Learn More



  # 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("ntt ", @urls),
        "Total Requests"  => "",
        "Parallel Agents" => ,
        "Succeeded"       => sprintf(" (%.2f%%)n",
                                    * 100 / ),
        "Errors"          => ,
        "Total Time"      => sprintf("%.2f secsn", ),
        "Throughput"      => sprintf("%.2f Requests/secn",
                                    / ),
        "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

thumbnail Stas Bekman

Stas Bekman is a ServerWatch contributor.

Recommended for you...

What Is a Container? Understanding Containerization
What Is a Print Server? | How It Works and What It Does
Nisar Ahmad
Dec 8, 2023
What Is a Network Policy Server (NPS)? | Essential Guide
Virtual Servers vs. Physical Servers: Comparison and Use Cases
Ray Fernandez
Nov 14, 2023
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.