ServersImproving mod_perl Driven Site's Performance -- Part II: Benchmarking Applications Page 4

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

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




This is another crashme suite originally written by Michael Schilli
(and was located at http://www.linux-magazin.de site, but now the link
has gone). I made a few modifications, mostly adding my() operators.
I also allowed it to accept more than one url to test, since sometimes
you want to test more than one script.

The tool provides the same results as ab above but it also allows
you to set the timeout value, so requests will fail if not served
within the time out period. You also get values for Latency
(seconds per request) and Throughput (requests per second). It can
do a complete simulation of your favorite Netscape browser 🙂 and give
you a better picture.

I have noticed while running these two benchmarking suites, that ab
gave me results from two and a half to three times better. Both
suites were run on the same machine, with the same load and the same
parameters, but the implementations were different.

Sample output:

  URL(s):          http://www.example.com/perl/access/access.cgi
  Total Requests:  100
  Parallel Agents: 10
  Succeeded:       100 (100.00%)
  Errors:          NONE
  Total Time:      9.39 secs
  Throughput:      10.65 Requests/sec
  Latency:         0.85 secs/Request

And the code:

  #!/usr/bin/perl -w

  use LWP::Parallel::UserAgent;
  use Time::HiRes qw(gettimeofday tv_interval);
  use strict;

  ###
  # Configuration
  ###

  my  = 10;
  my  = 100;
  my  = 10;
  my @urls = (
            'http://www.example.com/perl/faq_manager/faq_manager.pl',
            'http://www.example.com/perl/access/access.cgi',
           );

  ##################################################
  # Derived Class for latency timing
  ##################################################

  package MyParallelAgent;
  @MyParallelAgent::ISA = qw(LWP::Parallel::UserAgent);
  use strict;

  ###
  # Is called when connection is opened
  ###
  sub on_connect {
    my (, , , ) = @_;
    ->{__start_times}->{} = [Time::HiRes::gettimeofday];
  }

  ###
  # Are called when connection is closed
  ###
  sub on_return {
    my (, , , ) = @_;
    my  = ->{__start_times}->{};
    ->{__latency_total} += Time::HiRes::tv_interval();
  }

  sub on_failure {
    on_return(@_);  # Same procedure
  }

  ###
  # Access function for new instance var
  ###
  sub get_latency_total {
    return shift->{__latency_total};
  }

  ##################################################
  package main;
  ##################################################
  ###
  # Init parallel user agent
  ###
  my  = MyParallelAgent->new();
  ->agent("pounder/1.0");
  ->max_req();
  ->redirect(0);    # No redirects

  ###

Get the Free Newsletter!

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

Latest Posts

Related Stories