Tutorial

How To Use ApacheBench To Do Load Testing on an Arch Linux VPS

Published on November 22, 2013
author

Robert Qualls

How To Use ApacheBench To Do Load Testing on an Arch Linux VPS

Introduction


Load testing is a good idea before any deployment. Although it’s not something to be skimped out on, sometimes it’s nice to quickly establish a best-case scenario for a project before running more detailed tests down the road.

The ApacheBench tool (ab) can load test servers by sending an arbitrary number of concurrent requests. Although ab was designed for testing Apache installations, it can be used to benchmark any HTTP server.

In this tutorial, we will see how a Ruby interpreter with different servers performs under load. The tutorial steps assume a fresh Arch Linux x86_64 image. The results were obtained from a 512 MB droplet.

Installation


Refresh the package database.

pacman -Sy

Install the apache package to get access to ApacheBench. Alternatively, it is contained in the apache-tools package in the AUR.

pacman -S apache

Limited Privilege User


Next, create the user that will manage Ruby. It’s not a good idea to run some of the commands in the next section as root.

useradd -m -d /home/test test

Switch to the new user.

su test

RVM


The Ruby Version Manager makes it easy to work with different Ruby environments. It takes care of the process of installing specific Ruby versions and isolating gemsets. It is currently installed by running a bash script from their website.

\curl -L https://get.rvm.io | bash -s stable

In order to use the rvm command, you need to first run the rvm script.

source ~/.rvm/scripts/rvm

Next, install Ruby 2.0.0. RVM generally builds Ruby from source, so this step may take a while.

rvm install 2.0.0

Switch to the new Ruby. This might happen by default after the installation, but checking doesn’t hurt.

rvm use 2.0.0

Testing


Now that Ruby is installed, you can create a simple site and see how many requests it can handle.

Install Sinatra. It’s a microframework/DSL for creating Ruby web applications. The --no-* flags skip the documentation.

gem install sinatra --no-rdoc --no-ri

Create the sample sinatra app which just echoes “hello world”.

cd ~
vi app.rb

# app.rb
require 'sinatra'

get '/' do
  'hello world'
end

Run the server.

ruby app.rb

With the server finally up, you can start load testing. A call to ab looks like this:

ab -n <num_requests> -c <concurrency> <addr>:<port><path>

Open another terminal and ssh into the server again. Run a test with ApacheBench. I used 1000 requests with a concurrency of 100. Don’t forget the final ‘/’ at the end for the path.

ab -n 1000 -c 100 http://localhost:4567/

Server Software:        WEBrick/1.3.1
Server Hostname:        0.0.0.0
Server Port:            4567

Document Path:          /
Document Length:        11 bytes

Concurrency Level:      100
Time taken for tests:   2.950 seconds
Complete requests:      1000
Failed requests:        0
Write errors:           0
Total transferred:      288000 bytes
HTML transferred:       11000 bytes
Requests per second:    338.94 [#/sec] (mean)
Time per request:       295.041 [ms] (mean)
Time per request:       2.950 [ms] (mean, across all concurrent requests)
Transfer rate:          95.33 [Kbytes/sec] received

Connection Times (ms)
              min  mean[+/-sd] median   max
Connect:        0    1   2.8      0      15
Processing:   117  285  94.3    268     553
Waiting:       70  248  91.8    234     544
Total:        117  286  93.6    271     553

Percentage of the requests served within a certain time (ms)
  50%    271
  66%    327
  75%    354
  80%    361
  90%    413
  95%    468
  98%    512
  99%    539
100%    553 (longest request)

My results converged around 300 requests/second. WEBrick is not known for its speed. Go ahead and interrupt the server with Ctrl-c.

Thin is a popular ruby web server that uses Mongrel for parsing and EventMachine for non-blocking IO. Install Thin and run the server again. Sinatra should load Thin automatically and let you know (“…with backup from Thin”).

gem install thin
ruby app.rb

Now, try the load test again. It should be a bit faster this time.

Note: Thin does not appear to allow ApacheBench connections via localhost, but it allows 0.0.0.0 or 127.0.0.1.

ab -n 1000 -c 100 http://0.0.0.0:4567/

...
Concurrency Level:      100
Time taken for tests:   0.989 seconds
Complete requests:      1000
Failed requests:        0
Write errors:           0
Total transferred:      244000 bytes
HTML transferred:       11000 bytes
Requests per second:    1011.13 [#/sec] (mean)
Time per request:       98.899 [ms] (mean)
Time per request:       0.989 [ms] (mean, across all concurrent requests)
Transfer rate:          240.93 [Kbytes/sec] received
...

At least in this case, it looks like Thin makes for a notably faster server than WEBrick at over 1000 requests/second (You can try raising the total requests, but it didn’t get much higher for me). Not bad.

Conclusion


Obviously, these results do not reflect realistic server performance. HTTP is just one piece of the puzzle. A slow templating engine and/or database will drag these numbers down significantly. Still, it gives you a quick ballpark figure for comparison.

Other performance tools you might be interested in:

<div class=“author”>Submitted by: <a href=“http://robertqualls.com”>Robert Qualls</a></div>

Thanks for learning with the DigitalOcean Community. Check out our offerings for compute, storage, networking, and managed databases.

Learn more about our products

About the authors
Default avatar
Robert Qualls

author

Still looking for an answer?

Ask a questionSearch for more help

Was this helpful?
 
1 Comments


This textbox defaults to using Markdown to format your answer.

You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!

Siege is another great load testing option – http://www.joedog.org/siege-home/

Try DigitalOcean for free

Click below to sign up and get $200 of credit to try our products over 60 days!

Sign up

Join the Tech Talk
Success! Thank you! Please check your email for further details.

Please complete your information!

Become a contributor for community

Get paid to write technical tutorials and select a tech-focused charity to receive a matching donation.

DigitalOcean Documentation

Full documentation for every DigitalOcean product.

Resources for startups and SMBs

The Wave has everything you need to know about building a business, from raising funding to marketing your product.

Get our newsletter

Stay up to date by signing up for DigitalOcean’s Infrastructure as a Newsletter.

New accounts only. By submitting your email you agree to our Privacy Policy

The developer cloud

Scale up as you grow — whether you're running one virtual machine or ten thousand.

Get started for free

Sign up and get $200 in credit for your first 60 days with DigitalOcean.*

*This promotional offer applies to new accounts only.