Using Apache Bench for Simple Load Testing
If you have access to a Mac or Linux server, chances are you may already have a really simple http load generating tool installed called Apache Bench, or ab. If you are on windows and have Apache installed, you may also have ab.exe in your apache/bin folder.
Suppose we want to see how fast Yahoo can handle 100 requests, with a maximum of 10 requests running concurrently:
It will then generate output as follows:
As you can see this is very useful information, it returned requests at a rate of 52.94 requests per second, the fastest request was 175ms, the slowest 224ms
So the next time you are tempted to whip out cfloop and GetTickCount to do some benchmarking on a piece of code, give ab a try, it’s easy to use, and will yield much more realistic results.
Because ab supports concurrency, this has two big advantages over cfloop. The main one is that it allows you to test how your code runs concurrently, this can help you identify any possible race conditions, or locking issues. Concurrent requests are also a more natural simulation of load than loops.
Suppose you wanted to test multiple url’s concurrently as well? You can do this by creating a shell script, with multiple ab calls. At the end of each line place an this makes the command run in the background, and lets the next command start execution. You will also want to redirect the output to a file for each url using filename For example:
The usage info from the ab version installed on my Mac (v2.3) is listed below. As you can see there are many useful options for outputting results, and sending additional data in the request.
20 people found this page useful, what do you think?
Download FuseGuard WAF for ColdFusion
Pete, I like your suggestion, by your method is completely incorrect. First, benchmarking Yahoo.com is useless for detecting their performance, as there are too many other variables to take into account. Second, your scripts will not gather correct result for two reasons: 1). You are benchmarking localhost, that will spike the load on the box, making the performance less accurate. and 2). You are running multiple benchmarks concurrently, which will also skew your results. You should always run your benchmarks from another machine, and run one at a time to isolate performance, all you’re doing right now it wasting electricity and getting useless results.
by Jacob Torrey on 02/05/2009 at 4:00:15 PM UTC
by Pete Freitag on 02/06/2009 at 8:40:05 AM UTC
hello pete, while i was trying to use the ab cmd,i could not get my ip addr either by ipconfig or /sbin/ifconfig -a the problem is i get different ip addr’s. how should i check the performance?
by varsee on 06/21/2009 at 8:32:37 PM UTC
Posted In: NEWS