Disclaimer: the numbers here are too low for mod_perl, because my machine
is to slooooow :( I'll rerun the same tests on a much faster machine
before releasing the new version of the Guide. 

=head1 Benchmarking Apache::Registry and Perl Content Handler

=head2 Empty scripts

First lets see the overhead that Apache::Regsitry adds. In order to do
that we will use an almost empty scripts, that only send a basic
header and one word as a content.

The I<registry.pl> script running under C<Apache::Registry>:

  registry.pl
  -----------
  use strict;
  print "Content-type: text/plain\r\n\r\n";
  print "Hello";

The Perl Content handler:

  Benchmark/Handler.pm
  --------------------
  package Benchmark::Handler;
  use Apache::Constants qw(:common);
  
  sub handler{
    $r = shift;
    $r->send_http_header('text/html');
    $r->print("Hello");
    return OK;
  }
  1;

with settings:

  PerlModule Benchmark::Handler
  <Location /benchmark_handler>
    SetHandler perl-script
    PerlHandler Benchmark::Handler
  </Location>

The benchmark:

  % ab -n 1000 -c 10 http://localhost/perl/benchmarks/registry.pl
  
  Requests per second:    21.27
  Time taken for tests:   43.924 seconds
  Connnection Times (ms)
                min   avg   max
  Connect:        0     3   218
  Processing:   223   435   679
  Total:        223   438   897

  % ab -n 1000 -c 10 http://localhost/benchmark_handler
  
  Requests per second:    49.03
  Time taken for tests:   20.394 seconds
  Connnection Times (ms)
                min   avg   max
  Connect:        0     1   201
  Processing:    59   201   605
  Total:         59   202   806

So we can see that the average added overhead is about:

  438 - 202 = 236 milli-seconds

per script.

=head2 Heavy Scripts

Of course this overhead is insignificant when the code itself is
significantly heavier and slower. Let's leave the above code examples
umodified but add some CPU intensive processing operation (it can be
also an IO operation or a database query.)

  my $x = 100;
  my $y = log ($x ** 100)  for (0..10000);

  % ab -n 1000 -c 10 http://localhost/perl/benchmarks/registry.pl

  Time taken for tests:   121.944 seconds
  Requests per second:    8.20
  
  Connnection Times (ms)
                min   avg   max
  Connect:        0    11   950
  Processing:   747  1204   888
  Total:        747  1215  1838

  %ab -n 1000 -c 10  http://localhost/benchmark_handler

  Time taken for tests:   41.166 seconds
  Requests per second:    24.29
  
  Connnection Times (ms)
                min   avg   max
  Connect:        0     3   150
  Processing:    73   407  1211
  Total:         73   410  1361

META: something is wrong here! It shouldn't be that slower. Should try
run it on a faster machine!




______________________________________________________________________
Stas Bekman             | JAm_pH    --    Just Another mod_perl Hacker
http://stason.org/      | mod_perl Guide  http://perl.apache.org/guide 
mailto:[EMAIL PROTECTED]  | http://perl.org    http://stason.org/TULARC/
http://singlesheaven.com| http://perlmonth.com http://sourcegarden.org
----------------------------------------------------------------------

Reply via email to