Recipe 21.4. Stress Testing Your Web Site

21.4.1. Problem

You want to find out how well your web site performs under a heavy load.

21.4.2. Solution

Use a stress-testing and benchmarking tool to simulate a variety of load levels.

21.4.3. Discussion

Stress testing is frequently confused with benchmarking, and it is important to recognize the difference between the two activities.

Benchmarking a web site is often a somewhat casual activity when performed by an individual developer. The most commonly used tool is the Apache HTTP server benchmarking tool, ab, which is designed to test how many requests per second an HTTP server is capable of serving. For example:

% /usr/bin/ab -n 1000 -c 100 -k

This test would return a report illustrating the average response time for requests to, based on 1,000 requests, grouped in batches of 100 concurrent requests.

While that sort of test has value'it gives you a reasonable estimation of how many requests you can serve per second under normal load'it doesn't tell you much about how your entire web application will behave under heavy load. It only pounds on one URL at a time, after all.

Stress testing is a testing technique whose intent is to break your web application. By testing to a breaking point, you can identify and repair weaknesses in your application, or gain a better understanding of when you will need to add additional hardware. When combined with code profiling, you can also get an idea of what part of your application will need to scale first; i.e., will you need to add more servers to your database cluster before you need to add more frontend web server machines?

An excellent open source tool for stress testing is Siege. Siege can be configured to read a large number of URLs from a configuration file and run through them in order (regression testing), or it can read a list or URLs and hit them randomly, which better approximates real-world usage of a web site. Siege can also pound on a single URL in a similar fashion to ab.

If you are unable to install Siege on your system, Lincoln Stein's script is a good alternative. Many of Siege's design concepts were inspired by, and the two tools produce similar reports.

21.4.4. See Also

Source and documentation for Siege at; ab at; source and documentation for at

PHP Cookbook, 2nd Edition
PHP Cookbook: Solutions and Examples for PHP Programmers
ISBN: 0596101015
EAN: 2147483647
Year: 2006
Pages: 445

Similar book on Amazon © 2008-2017.
If you may any questions please contact us: