SHARE
Facebook X Pinterest WhatsApp

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

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



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
  ###
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.