Many people don't know about Apache Bench, even though it may be installed on their system. For instance it's installed on Mac OS X by default. It's a very simple command line utility to perform basic stress/performance testing of websites. It can request a given URL repeatedly, then report back statistics. I generally use it in this form:

> ab -n 100 -c 4 http://www.somewebsite.com/test/page.htm

Dissecting that command:
  • ab is the Apache Bench executable itself (found in /usr/sbin on my machine)
  • -n 100 tells it to send the request 100 times 
  • -c 4 tells it to use 4 concurrent threads to do so
  • finally we have the URL itself. 

Even though it's simple, there are some important gotchas worth knowing about:

  • Remember to put the URL in single quotes if it contains characters that would otherwise be interpreted by the shell. This is often the case for any URL with a query string, as the & characters will mess things up otherwise. 
  • If using a base URL for a site (just host name), you must use a trailing slash. http://foo.com doesn't work, but http://foo.com/ does work. 
  • Quite often you may see in the statistics "Failed requests: 5" or similar, followed by a list of the types of failure: "(Connect: 0, Receive: 0, Length: 5, Exceptions: 0)". If the only type of failure that actually occurred is 'Length' then don't be alarmed. This simply means that each request (for the same URL) returned a different length response, which ab regards as suspicious. However it's perfectly normal for dynamic webpages, especially if they include the time or other very dynamic data on the page. 
  • I find on one of my machines that it just doesn't like localhost as a hostname, so I have to use 127.0.0.1 instead. I have no idea why, as localhost works fine in other contexts on the same machine. 

Leave a Reply

Your email address will not be published. Required fields are marked *