blog advertising is good for you


blog advertising is good for you
User login

Stress-Test Apache With ab

I’ve been having some issues with Apache lately in that it and MySQL aren’t playing nicely performance-wise. I’ve raised meaningful numbers. I’ve raised, lowered, raised, lowered, deleted, added, moved, and raised meaningless numbers. I’ve done a lot.

In the end, “time wget” gets you only so far when it comes to seeing how fast a page loads. Once you get Apache doing its job, it’s down to the database and the PHP code that’s running it all and that can get real fun to test.

Happily, Apache includes a very useful tool (in my experience) for hammering the living hell out of a server. It’s called Apache Benchmark (“ab” is the binary’s name) and it can really hand a server it’s own ass if you don’t watch it.

ab -kc 10 -t 30 http://localhost/

That will open 10 connections, use Keep-Alive on them, and then hammer localhost for 30 seconds through those connections. When done, you get a pretty little chart telling you what broke and how long it took to start screaming. Try fifty KA connections for five minutes if you really feel sadistic. That’d be equal to a very high-end hammering from Fark or Slashdot. Watch your server cry.

For best results, though, use it on another machine. You want to not only test the network connection but also leave the server’s CPU and OS to think about serving, not about pulling it down as well.

ab is included in Mac OS X as a part of the built-in Apache-based PWS.

That’s where my day’s been, so enjoy. Smiling

Average rating
(0 votes)
About Adam Knight
Adam Knight's picture

Author Biography

Adam Knight is one of the founders of Mac Geekery and is a geek at heart. Programmer by day, hacker by night, his daily life revolves around the Macintosh platform, which he has been a user and programmer for since the early days of System 7 when his LCII replaced his Apple //c.

In-between tech jobs, he’s managed to learn the basics of any web hacker: PHP, MySQL, Perl, Apache, Linux, *BSD, and the intricacies of ./configure —prefix=~/bombshelter/. Today, codepoet is concentrating on blogging again, writing some software for the Mac by himself (including Notae) and for his company (such as Switchblade) and has a few other toys coming out soon.

Bug him over AIM or email [link fixed].

flood is a good tool, but hard to find… It was a testbed for APR (apache portable runtime) and uses an XML document to describe how and what to hit. Nice for basic code coverage.

If you want more detail, there are a few packages if you want to write some code that can be extremely useful. Perl’s WWW::Mechanize is almost industry standard these days for finding bottlenecks. There is also a Ruby package that is highly regarded, but the name escapes me at this time. I want to say it’s called WARTS or something similar.

Also, don’t forget the power of netcat. You can easily write a few small scripts to walk your tree and find the real bottlenecks that the above tools might not be fine-grained enough to handle.

here it is: WATIR

It’s Friday so WTH,

Did it pass?

Xserve1:~ admin$ ab -kc 50 -t 300 http://localhost/
This is ApacheBench, Version 1.3d <$Revision: 1.73 $> apache-1.3
Copyright © 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/
Copyright © 1998-2002 The Apache Software Foundation, http://www.apache.org/

Benchmarking localhost (be patient)
Completed 5000 requests
Completed 10000 requests
Completed 15000 requests
Completed 20000 requests
Completed 25000 requests
Completed 30000 requests
Completed 35000 requests
Completed 40000 requests
Completed 45000 requests
Finished 50000 requests
Server Software: Apache/1.3.33
Server Hostname: localhost
Server Port: 80

Document Path: /
Document Length: 5634 bytes

Concurrency Level: 50
Time taken for tests: 200.636 seconds
Complete requests: 50000
Failed requests: 100 (Connect: 50, Length: 50, Exceptions: 0)
Broken pipe errors: 0
Keep-Alive requests: 0
Total transferred: 298926522 bytes
HTML transferred: 281536614 bytes
Requests per second: 249.21 [#/sec] (mean)
Time per request: 200.64 [ms] (mean)
Time per request: 4.01 [ms] (mean, across all concurrent requests)
Transfer rate: 1489.89 [Kbytes/sec] received

Connnection Times (ms) min mean[+/-sd] median max
Connect: 0 193 nan 2 74978
Processing: 0 7 7.1 5 170
Waiting: 0 6 7.1 5 169
Total: 0 200 nan 7 74978

Percentage of the requests served within a certain time (ms) 50% 7 66% 8 75% 10 80% 11 90% 13 95% 17 98% 26 99% 43 100% 74978 (last request)

Adam Knight's picture

I’m going to say “yes” to that. Smiling

cp

Post new comment
The content of this field is kept private and will not be shown publicly.
1 + 6 =
Solve this simple math problem and enter the result. E.g. for 1+3, enter 4.