Thursday, December 18, 2008

Simple request benchmarking of a Ruby on Rails application using ApacheBenchmarker

You can use ApacheBenchmarker which comes with your default Apache install.  You can find the ab.exe executable in C:\Program Files\Apache Group\Apache2\bin on Windows.

Usage: ab [options] [http://]hostname[:port]/path
Options are:
  -n requests     Number of requests to perform
  -c concurrency  Number of multiple requests to make
  -t timelimit    Seconds to max. wait for responses
  -p postfile     File containing data to POST
  -T content-type Content-type header for POSTing
  -v verbosity    How much troubleshooting info to print
  -w              Print out results in HTML tables
  -i              Use HEAD instead of GET
  -x attributes   String to insert as table attributes
  -y attributes   String to insert as tr attributes
  -z attributes   String to insert as td or th attributes
  -C attribute    Add cookie, eg. 'Apache=1234. (repeatable)
  -H attribute    Add Arbitrary header line, eg. 'Accept-Encoding: gzip'
                  Inserted after all normal header lines. (repeatable)
  -A attribute    Add Basic WWW Authentication, the attributes
                  are a colon separated username and password.
  -P attribute    Add Basic Proxy Authentication, the attributes
                  are a colon separated username and password.
  -X proxy:port   Proxyserver and port number to use
  -V              Print version number and exit
  -k              Use HTTP KeepAlive feature
  -d              Do not show percentiles served table.
  -S              Do not show confidence estimators and warnings.
  -g filename     Output collected data to gnuplot format file.
  -e filename     Output CSV file with percentages served
  -h              Display usage information (this message)

My simple benchmarking tests for my Ruby on Rails website.  I wanted to compare the performance of RoR over CGI with a new server instance created on each request versus requests over CGI proxied to a single long-running mongrel_rails server.  These tests do 10 individual requests, then 100 requests, 5 concurrently. Results are output in HTML.

ab -n 10 -c 1 -w > 10-requests.html ab -n 100 -c 5 -w > 100-5-concurrent-requests.html

For your information I'm running my mongrel_rails using God on port 3000 and I am proxying requests using the standard RoR .htaccess file as follows:

RewriteEngine On RewriteCond %{HTTP_HOST} ^$ RewriteRule ^(.*)${REQUEST_URI} [P,QSA,L]

I have to adopt such an arcane setup because my host HostGator only supports RoR over CGI, which is not very performant.

The test results basically tell me what I already: never, ever run a RoR app over CGI where you're starting the server on every request! Holy smokes! For 100 requests (5 concurrent) over CGI average total request time was 16437 ms (ouch!!!) serving 0.3 reqs/sec. Talking to a proxied mongrel server fared much better with average total request time being 565 ms serving 8.61 reqs/sec.

Here is the output from the latter test.

This is ApacheBench, Version 2.0.41-dev <$Revision: $> apache-2.0 Copyright (c) 1996 Adam Twiss, Zeus Technology Ltd, Copyright (c) 2006 The Apache Software Foundation,


Server Software:Mongrel
Server Port:80
Document Path:/
Document Length:4174 bytes
Concurrency Level:5
Time taken for tests:0.11609 seconds
Complete requests:100
Failed requests:0
Total transferred:457200 bytes
HTML transferred:417400 bytes
Requests per second:8.61
Transfer rate:39.38 kb/s received
Connnection Times (ms)
Connect: 62 107 3062
Processing: 188 458 703
Total: 250 565 3765

1 comment:

Blogger said...

Bluehost is ultimately the best hosting provider for any hosting services you might require.