Apache Ab Example



Apache Bench

Apache ab examples

Time: How long ab spent handling the connection, from the beginning of its attempt to contact the server to when the connection closed (i.e., done - start) From there, ab uses the data object to calculate the remaining latency-related metrics: aggregated connection times, percentiles, and, if you use the -g flag, data for individual requests. Apache Bench ( Popularly known as ab ) is used to test the performance of webserver running Apache, It is a famous light weight command line utility used to do load testing of a website and is useful in checking the scalability of your apache webserver. Apache HTTP Server comes with the following programs. Httpd Apache hypertext transfer protocol server apachectl Apache HTTP server control interface ab Apache HTTP server benchmarking tool apxs APache eXtenSion tool dbmmanage Create and update user authentication files in DBM format for basic authentication fcgistarter Start a FastCGI program.

httpd and IHS ship with a cool little command line utility called Apache Bench (ab). At its simplest, you pass the number of requests you want to send (-n), at what concurrency (-c) and the URL to benchmark. ab will return various statistics on the responses (mean, median, max, standard deviation, etc.). This is really useful when you want to 'spot check' backend server performance or compare two different environments, because you do not need to install complex load testing software, and since IHS usually has direct access to WAS, you do not have to worry about firewalls, etc.

Below is an example execution.

The key things to look at are:

  1. Time taken for tests: This is how long it took for all requests finish. When comparing two environments, if your mean and median are similar but total time is worse in one case, this may suggest queueing effects.
  2. Failed requests, write errors, and Non-2xx responses: These may indicate some problem. See below for a caveat on 'Failed requests.'
  3. Requests per second: Throughput.
  4. Total: Look at min, mean, median, max and sd (standard deviation). Usually the mean is the place to start.
  5. Percentage of the requests served within a certain time: Response times on a percentile basis. Many customers look at 95%, but this is arbitrary and usually based on what percentage of requests are expected to have errors or do weird behavior.

Some important notes:

  1. ab has odd behavior in that it counts requests with varying Content-Length headers as 'Failed requests' due to 'length;' for example:

    It is common to have different content lengths, so usually this can be disregarded (only if the 'Length' number counts all the 'failed' requests). There is a patch for this, but it has never made it into the core code: https://issues.apache.org/bugzilla/show_bug.cgi?id=27888.

  2. Non-2xx responses may or may not be okay. HTTP status codes are usually okay if they are 304 (Not Modified), for example. They are usually not okay if they are 4xx or 5xx. To get details on the response code, use '-v 2' which will print a warning for non-2xx response codes and list what the code was.

  3. ab is not a browser, so when you request a page, ab will not fetch any resources within the page such as images, scripts, iframes, etc.

Previous Section (R Project) | Next Section (awk) | Back to Table of Contents

Synopsis

ab [-Aauth-username:password ] [ -bwindowsize ] [ -cconcurrency ] [-Ccookie-name=value ] [ -d ] [-ecsv-file ] [ -fprotocol ] [-ggnuplot-file ] [ -h ] [ -Hcustom-header ] [ -i ] [ -k ] [-nrequests ] [ -pPOST-file ] [-Pproxy-auth-username:password ] [-q ] [ -r ] [ -s ] [ -S ] [-ttimelimit ] [ -Tcontent-type] [ -uPUT-file ] [ -vverbosity] [ -V ] [ -w ] [ -x<table>-attributes ] [ -Xproxy[:port] ] [ -y<tr>-attributes ] [ -z<td>-attributes ] [ -Zciphersuite ][http[s]://]hostname[:port]/path


add an example, a script, a trick and tips

examples

3

options

-Aauth-username:password

Supply BASIC Authenticationcredentials to the server. The username and password areseparated by a single : and sent on the wire base64 encoded.The string is sent regardless of whether the server needs it(i.e., has sent an 401 authentication needed).

-b windowsize

Size of TCP send/receivebuffer, in bytes.

-c concurrency

Number of multiple requests toperform at a time. Default is one request at a time.

-Ccookie-name=value

Add a Cookie: line to therequest. The argument is typically in the form of aname=value pair. This field is repeatable.

-d

Do not display the 'percentage served within XX[ms] table'. (legacy support).

-e csv-file

Write a Comma separated value(CSV) file which contains for each percentage (from 1% to100%) the time (in milliseconds) it took to serve thatpercentage of the requests. This is usually more useful thanthe ’gnuplot’ file; as the results are already’binned’.

-f protocol

Specify SSL/TLS protocol (SSL2,SSL3, TLS1, or ALL).

-g gnuplot-file

Write all measured values outas a ’gnuplot’ or TSV (Tab separate values)file. This file can easily be imported into packages likeGnuplot, IDL, Mathematica, Igor or even Excel. The labelsare on the first line of the file.

-h

Display usage information.

-H custom-header

Append extra headers to therequest. The argument is typically in the form of a validheader line, containing a colon-separated field-value pair(i.e., 'Accept-Encoding:zip/zop;8bit').

Apache Ab Example

-i

Do HEAD requests instead of GET.

-k

Enable the HTTP KeepAlive feature, i.e., performmultiple requests within one HTTP session. Default is noKeepAlive.

-n requests

Number of requests to performfor the benchmarking session. The default is to just performa single request which usually leads to non-representativebenchmarking results.

-p POST-file

File containing data to POST.Remember to also set -T.

-Pproxy-auth-username:password

Apache Ab Example

Supply BASIC Authenticationcredentials to a proxy en-route. The username and passwordare separated by a single : and sent on the wire base64encoded. The string is sent regardless of whether the proxyneeds it (i.e., has sent an 407 proxy authenticationneeded).

-q

When processing more than 150 requests, ab outputs aprogress count on stderr every 10% or 100 requests or so.The -q flag will suppress these messages.

-r

Don’t exit on socket receive errors.

-s

When compiled in (ab -h will show you) use the SSLprotected https rather than the http protocol. This featureis experimental and very rudimentary. You probably donot want to use it.

-S

Do not display the median and standard deviation values,nor display the warning/error messages when the average andmedian are more than one or two times the standard deviationapart. And default to the min/avg/max values. (legacysupport).

-t timelimit

Maximum number of seconds tospend for benchmarking. This implies a -n 50000 internally.Use this to benchmark the server within a fixed total amountof time. Per default there is no timelimit.

-T content-type

Content-type header to use forPOST/PUT data, eg. application/x-www-form-urlencoded.Default: text/plain.

-u PUT-file

File containing data to PUT.Remember to also set -T.

-v verbosity

Set verbosity level - 4 andabove prints information on headers, 3 and above printsresponse codes (404, 200, etc.), 2 and above prints warningsand info.

-V

Display version number and exit.

-w

Print out results in HTML tables. Default table is twocolumns wide, with a white background.

-x<table>-attributes

String to use as attributes for<table>. Attributes are inserted <table here>.

-Xproxy[:port]

Use a proxy server for therequests.

-y<tr>-attributes

String to use as attributes for<tr>.

-z<td>-attributes

String to use as attributes for<td>.

-Z ciphersuite

Specify SSL/TLS cipher suite(See openssl ciphers).

summary

Apache Ab Example

ab is a tool for benchmarking your Apache Hypertext Transfer Protocol (HTTP) server. It is designed to give you an impression of how your current Apache installation performs. This especially shows you how many requests per second your Apache installation is capable of serving.


Apache Ab Examples

bugs

There arevarious statically declared buffers of fixed length.Combined with the lazy parsing of the command linearguments, the response headers from the server and otherexternal inputs, this might bite you.

It does notimplement HTTP/1.x fully; only accepts some’expected’ forms of responses. The rather heavyuse of strstr(3) shows up top in profile, which mightindicate a performance problem; i.e., you wouldmeasure the ab performance rather than theserver’s.