Testing Web Services using ApacheBench

ApacheBench (ab) is a tool for benchmarking an Apache Hypertext Transfer Protocol (HTTP) server. This shows how many requests per second the server is capable of handling.

A point to note is that ApacheBench will only use one operating system thread regardless of the concurrency level; specified by the -c parameter. In some cases, especially when benchmarking high-capacity servers, a single instance of ApacheBench can itself be a bottleneck. To overcome this, additional instances of ApacheBench may be used in parallel to more fully saturate the target URL.

ApacheBench was recently used to test the capability of the Caleum server, to find the threshold of total number web requests it can concurrently serve, in its current configuration.

Working with ApacheBench

Installing on a Windows machine

  1. Download the software from the link http://www.apache.org/dist/httpd/binaries/win32/ by selecting any mirrors in the site.
  2. Select the latest version of software or later
  3. Double click and install the software. While installing provide the information

Network Domain: localhost

Server Name: localhost

Admin Email: provide a real or fake email

Leave all default check boxes checked

  1. After installation an icon will be displayed in the system tray. This means Apache2.2 has been installed and started.
  2. To verify further type http://localhost/ in browser. If Apache 2.2 has been started a message “It works!” in bold will be loaded in browser
  3. To stop/restart the server click on the icon ->Apache 2.2->Stop/Restart.

To measure performance of a server you may need to point your files to Apache. Since we are doing a web service testing this step is optional.

Execution:

  1. Open command prompt and go to the path where ApacheBench is installed say “C:\Program Files\Apache Software Foundation\Apache2.2\bin”
  2. Type ab –n 100 –c 10 http://{webserver hostname:port}/{document path}

You can also provide the authentication details as the parameters in document path.

Other options that can be used are

Options are:

-nrequestsNumber of requests to perform
-ttimelimitSeconds to max. wait for responses
-vverbosityHow much troubleshooting info to print
-bwindowsizeSize of TCP send/receive buffer, in bytes
-CattributeAdd cookie, eg. ‘Apache=1234. (repeatable)
-HattributeAdd Arbitrary header line, eg. ‘Accept-Encoding: gzip’ Inserted after all normal header lines. (repeatable)
-AattributeAdd Basic WWW Authentication, the attributesare a colon separated username and password.
-PattributeAdd Basic Proxy Authentication, the attributes are a colon separated username and password.
-xattributesString to insert as table attributes
-yattributesString to insert as tr attributes
-zattributesString to insert as td or th attributes
-ZciphersuiteSpecify SSL/TLS cipher suite (See openssl ciphers)
-cconcurrencyNumber of multiple requests to make
-Tcontent-typeContent-type header for POSTing, eg. ‘application/x-www-form-urlencoded’. Default is ‘text/plain’
-gfilenameOutput collected data to gnuplot format file.
-efilenameOutput CSV file with percentages served
-ppostfileFile containing data to POST. Remember also to set -T
-fprotocolSpecify SSL/TLS protocol (SSL2, SSL3, TLS1, or ALL)
-Xproxy:portProxyserver and port number to use
-iUse HEAD instead of GET
-VPrint version number and exit
-kUse HTTP KeepAlive feature
-dDo not show percentiles served table.
-SDo not show confidence estimators and warnings.
-rDon’t exit on socket receive errors.
-hDisplay usage information (this message)
-wPrint out results in HTML tables

 

An output as below is displayed in the cmd prompt after the execution

Concurrency Level:10
Time taken for tests:321.212 sec
Complete requests:1000
Failed requests:11(Connect: 0, Receive: 0, Length: 11, Exceptions: 0)
Write errors:0
Document length21bytes
Total transferred:22124 bytes
HTML transferred:11994 bytes
Requests per second:1.01 [#/sec] (mean)
Time per request:1216.319 [ms] (mean)
Time per request:156.272 [ms] (mean, across all concurrent requests)
Transfer rate:1.81 [Kbytes/sec] received

1.61 kb/s sent

0.42 kb/s total

Connection Times (ms)minmean[+/-sd]medianmax
Connect:2002001212123000
Processing:3012121612.819213267
Waiting:2112112211211211
Total:7113546799.332816547

 

Percentage of the requests served within a certain time (ms)

50%1212
66%3823
75%2211
80%4555
90%5555
95%6666
98%7777
99%8888
100%8899 (longest request)

It shows total time to complete the entire test and the number of completed request and failed requests. If there is any fail an additional line will be displayed. Connect:, Receive:, Length:, Exceptions:

While testing web server, we mainly focus on the fails in Connect and Receive. The fail in the length are due the content length not being specified or some additional data like ads come up in the page which goes beyond the specified length.



Author: InApp
We are a custom software development company offering Testing Services, Application Development, Mobility Solutions & more. Customers: Startups - Fortune 500

Leave a Reply

19 − 7 =