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, with varying degrees of sophistication. It is 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. That is why some tools record actual network traffic for later replay.

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/ 


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.

The result will look similar to the following:

 This is ApacheBench, Version 2.0.40 <$Revision: 1.87 $> Copyright (c) 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/org/ Copyright (c) 1998-2001 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.40 Server Hostname:        www.example.com Server Port:            80 Document Path:          / Document Length:        8667 bytes Concurrency Level:      10 Time taken for tests:   64.525026 seconds Complete requests:      1000 Failed requests:        0 Write errors:           0 Total transferred:      8911000 bytes HTML transferred:       8667000 bytes Requests per second:    15.50 [#/sec] (mean) Time per request:       0.645 - (mean) Time per request:       0.065 - (mean, across all concurrent requests) Transfer rate:          134.86 [Kbytes/sec] received Connection Times (ms)             min  mean[+/-sd] median   max Connect:    19    62   59.7 45 727 Processing: 178   572  362.8 478 3151 Waiting:    18   114  176.9 74 1906 Total:      255   634  390.3 536 3301 
 Percentage of the requests served within a certain time (ms) 50%     536 66%     611 75%     662 80%     693 90%     872 95%     1436 98%     2162 99%     2461 100%     3301 (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 90% of the requests were served in less than one second.

You can play with different settings for the number of requests and with the number of simultaneous clients to find the point at which your server slows down significantly.

Sams Teach Yourself PHP, MySQL and Apache in 24 Hours
Sams Teach Yourself PHP, MySQL and Apache in 24 Hours
ISBN: 067232489X
EAN: 2147483647
Year: 2005
Pages: 263

Similar book on Amazon

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net