Load Testing with ApacheBench
You can test the scalability and performance of your site with benchmarking and traffic generation tools. There are many commercial and open-source tools available, each with varying degrees of sophistication. In general, it is very difficult to accurately simulate real-world request traffic because visitors have different navigation patterns, access the Internet using connections with different speeds, stop a download if it is taking too long, press the reload button repeatedly if they get impatient, and so on. As such, some tools record actual network traffic for later replay.
However, for a quickbut accurateglimpse at basic information regarding your server's capability to handle heavy traffic, the Apache server comes with a simple, but useful, load-testing tool, called ApacheBench, or ab. You can find it in the /bin directory of the Apache distribution.
This tool enables you to request a certain URL a number of times and display a summary of the result. The following command requests the main page of the www.example.com server 1000 times, with 10 simultaneous clients at any given time:
# /usr/local/apache2/bin/ab -n 1000 -c 10 http://www.example.com/
By the Way
If you invoke ab without any arguments, you will get a complete listing of command-line options and syntax. Additionally, the trailing slash on the target URL is required, unless a specific page is named.
This is ApacheBench, Version 2.0.40-dev <$Revision: 188.8.131.52 $> apache-2.0 Copyright (c) 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/ Copyright (c) 1998-2002 The Apache Software Foundation, http://www.apache.org/ Benchmarking www.example.com (be patient) Completed 100 requests Completed 200 requests Completed 300 requests Completed 400 requests Completed 500 requests Completed 600 requests Completed 700 requests Completed 800 requests Completed 900 requests Finished 1000 requests Server Software: Apache/2.0.50 Server Hostname: www.example.com Server Port: 80 Document Path: / Document Length: 16 bytes Concurrency Level: 10 Time taken for tests: 2.269667 seconds Complete requests: 1000 Failed requests: 0 Write errors: 0 Total transferred: 252255 bytes HTML transferred: 16080 bytes Requests per second: 440.59 [#/sec] (mean) Time per request: 22.697 - (mean) Time per request: 2.270 - (mean, across all concurrent requests) Transfer rate: 108.39 [Kbytes/sec] received Connection Times (ms) min mean[+/-sd] median max Connect: 0 0 1.9 0 15 Processing: 1 20 61.9 15 689 Waiting: 0 19 60.6 14 687 Total: 1 21 61.9 15 689 Percentage of the requests served within a certain time (ms) 50% 15 66% 16 75% 17 80% 18 90% 19 95% 22 98% 224 99% 422 100% 689 (longest request)
These requests were made over the Internet to a sample server. You should get many more requests per second if you conduct the test against a server in the same machine or over a local network. The output of the tool is self-explanatory. Some of the relevant results are the number of requests per second and the average time it takes to service a request. You can also see how more than 95% of the requests were served in less than one second.