ab.c revision 14a74fec28467218c159a3c1c6dd90e3bcc5c2cc
1cc20a8827ff6056399d64e3106b44d31e8e0e53nd/* ====================================================================
1cc20a8827ff6056399d64e3106b44d31e8e0e53nd * The Apache Software License, Version 1.1
fd9abdda70912b99b24e3bf1a38f26fde908a74cnd * Copyright (c) 2000-2001 The Apache Software Foundation. All rights
fd9abdda70912b99b24e3bf1a38f26fde908a74cnd * reserved.
1cc20a8827ff6056399d64e3106b44d31e8e0e53nd * Redistribution and use in source and binary forms, with or without
1cc20a8827ff6056399d64e3106b44d31e8e0e53nd * modification, are permitted provided that the following conditions
1cc20a8827ff6056399d64e3106b44d31e8e0e53nd * are met:
1cc20a8827ff6056399d64e3106b44d31e8e0e53nd * 1. Redistributions of source code must retain the above copyright
1cc20a8827ff6056399d64e3106b44d31e8e0e53nd * notice, this list of conditions and the following disclaimer.
2e545ce2450a9953665f701bb05350f0d3f26275nd * 2. Redistributions in binary form must reproduce the above copyright
d29d9ab4614ff992b0e8de6e2b88d52b6f1f153erbowen * notice, this list of conditions and the following disclaimer in
d29d9ab4614ff992b0e8de6e2b88d52b6f1f153erbowen * the documentation and/or other materials provided with the
1cc20a8827ff6056399d64e3106b44d31e8e0e53nd * distribution.
af33a4994ae2ff15bc67d19ff1a7feb906745bf8rbowen * 3. The end-user documentation included with the redistribution,
3f08db06526d6901aa08c110b5bc7dde6bc39905nd * if any, must include the following acknowledgment:
1cc20a8827ff6056399d64e3106b44d31e8e0e53nd * "This product includes software developed by the
1cc20a8827ff6056399d64e3106b44d31e8e0e53nd * Apache Software Foundation (http://www.apache.org/)."
1cc20a8827ff6056399d64e3106b44d31e8e0e53nd * Alternately, this acknowledgment may appear in the software itself,
3f08db06526d6901aa08c110b5bc7dde6bc39905nd * if and wherever such third-party acknowledgments normally appear.
1cc20a8827ff6056399d64e3106b44d31e8e0e53nd * 4. The names "Apache" and "Apache Software Foundation" must
1cc20a8827ff6056399d64e3106b44d31e8e0e53nd * not be used to endorse or promote products derived from this
1cc20a8827ff6056399d64e3106b44d31e8e0e53nd * software without prior written permission. For written
1cc20a8827ff6056399d64e3106b44d31e8e0e53nd * permission, please contact apache@apache.org.
1cc20a8827ff6056399d64e3106b44d31e8e0e53nd * 5. Products derived from this software may not be called "Apache",
bf7fcf0c216a914407c0877aa37894fd9aecc219nilgun * nor may "Apache" appear in their name, without prior written
f086b4b402fa9a2fefc7dda85de2a3cc1cd0a654rjung * permission of the Apache Software Foundation.
9a58dc6a2b26ec128b1270cf48810e705f1a90dbsf * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
4b575a6b6704b516f22d65a3ad35696d7b9ba372rpluem * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
1cc20a8827ff6056399d64e3106b44d31e8e0e53nd * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
1cc20a8827ff6056399d64e3106b44d31e8e0e53nd * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
1cc20a8827ff6056399d64e3106b44d31e8e0e53nd * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
1cc20a8827ff6056399d64e3106b44d31e8e0e53nd * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
1cc20a8827ff6056399d64e3106b44d31e8e0e53nd * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
1cc20a8827ff6056399d64e3106b44d31e8e0e53nd * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
30471a4650391f57975f60bbb6e4a90be7b284bfhumbedooh * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
1cc20a8827ff6056399d64e3106b44d31e8e0e53nd * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
1cc20a8827ff6056399d64e3106b44d31e8e0e53nd * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
1cc20a8827ff6056399d64e3106b44d31e8e0e53nd * SUCH DAMAGE.
1cc20a8827ff6056399d64e3106b44d31e8e0e53nd * ====================================================================
1cc20a8827ff6056399d64e3106b44d31e8e0e53nd * This software consists of voluntary contributions made by many
1cc20a8827ff6056399d64e3106b44d31e8e0e53nd * individuals on behalf of the Apache Software Foundation. For more
1cc20a8827ff6056399d64e3106b44d31e8e0e53nd * information on the Apache Software Foundation, please see
2893256d86dd891d5859ef01dec4d85bf6488b69nd * Portions of this software are based upon public domain software
1cc20a8827ff6056399d64e3106b44d31e8e0e53nd * originally written at the National Center for Supercomputing Applications,
1cc20a8827ff6056399d64e3106b44d31e8e0e53nd * University of Illinois, Urbana-Champaign.
1cc20a8827ff6056399d64e3106b44d31e8e0e53nd ** This program is based on ZeusBench V1.0 written by Adam Twiss
1cc20a8827ff6056399d64e3106b44d31e8e0e53nd ** which is Copyright (c) 1996 by Zeus Technology Ltd. http://www.zeustech.net/
2893256d86dd891d5859ef01dec4d85bf6488b69nd ** This software is provided "as is" and any express or implied waranties,
1cc20a8827ff6056399d64e3106b44d31e8e0e53nd ** including but not limited to, the implied warranties of merchantability and
1cc20a8827ff6056399d64e3106b44d31e8e0e53nd ** fitness for a particular purpose are disclaimed. In no event shall
1cc20a8827ff6056399d64e3106b44d31e8e0e53nd ** Zeus Technology Ltd. be liable for any direct, indirect, incidental, special,
1cc20a8827ff6056399d64e3106b44d31e8e0e53nd ** exemplary, or consequential damaged (including, but not limited to,
1cc20a8827ff6056399d64e3106b44d31e8e0e53nd ** procurement of substitute good or services; loss of use, data, or profits;
1cc20a8827ff6056399d64e3106b44d31e8e0e53nd ** or business interruption) however caused and on theory of liability. Whether
1cc20a8827ff6056399d64e3106b44d31e8e0e53nd ** in contract, strict liability or tort (including negligence or otherwise)
1cc20a8827ff6056399d64e3106b44d31e8e0e53nd ** arising in any way out of the use of this software, even if advised of the
1cc20a8827ff6056399d64e3106b44d31e8e0e53nd ** possibility of such damage.
1cc20a8827ff6056399d64e3106b44d31e8e0e53nd ** HISTORY:
1cc20a8827ff6056399d64e3106b44d31e8e0e53nd ** - Originally written by Adam Twiss <adam@zeus.co.uk>, March 1996
1cc20a8827ff6056399d64e3106b44d31e8e0e53nd ** with input from Mike Belshe <mbelshe@netscape.com> and
1cc20a8827ff6056399d64e3106b44d31e8e0e53nd ** Michael Campanella <campanella@stevms.enet.dec.com>
1cc20a8827ff6056399d64e3106b44d31e8e0e53nd ** - Enhanced by Dean Gaudet <dgaudet@apache.org>, November 1997
1cc20a8827ff6056399d64e3106b44d31e8e0e53nd ** - Cleaned up by Ralf S. Engelschall <rse@apache.org>, March 1998
1cc20a8827ff6056399d64e3106b44d31e8e0e53nd ** - POST and verbosity by Kurt Sussman <kls@merlot.com>, August 1998
1cc20a8827ff6056399d64e3106b44d31e8e0e53nd ** - HTML table output added by David N. Welton <davidw@prosa.it>, January 1999
1cc20a8827ff6056399d64e3106b44d31e8e0e53nd ** - Added Cookie, Arbitrary header and auth support. <dirkx@webweaving.org>, April 1999
1cc20a8827ff6056399d64e3106b44d31e8e0e53nd ** Version 1.3d
1cc20a8827ff6056399d64e3106b44d31e8e0e53nd ** - Increased version number - as some of the socket/error handling has
1cc20a8827ff6056399d64e3106b44d31e8e0e53nd ** fundamentally changed - and will give fundamentally different results
1cc20a8827ff6056399d64e3106b44d31e8e0e53nd ** in situations where a server is dropping requests. Therefore you can
1cc20a8827ff6056399d64e3106b44d31e8e0e53nd ** no longer compare results of AB as easily. Hence the inc of the version.
2893256d86dd891d5859ef01dec4d85bf6488b69nd ** They should be closer to the truth though. Sander & <dirkx@covalent.net>, End 2000.
1cc20a8827ff6056399d64e3106b44d31e8e0e53nd ** - Fixed proxy functionality, added median/mean statistics, added gnuplot
5383fa753e1bcd3a04ec34ba9810d671302380f2colm ** output option, added _experimental/rudimentary_ SSL support. Added
1cc20a8827ff6056399d64e3106b44d31e8e0e53nd ** confidence guestimators and warnings. Sander & <dirkx@covalent.net>, End 2000
1cc20a8827ff6056399d64e3106b44d31e8e0e53nd ** - Fixed serious int overflow issues which would cause realistic (longer
1cc20a8827ff6056399d64e3106b44d31e8e0e53nd ** than a few minutes) run's to have wrong (but believable) results. Added
1cc20a8827ff6056399d64e3106b44d31e8e0e53nd ** trapping of connection errors which influenced measurements.
1cc20a8827ff6056399d64e3106b44d31e8e0e53nd ** Contributed by Sander Temme - <sctemme@covalent.net>, Early 2001
1cc20a8827ff6056399d64e3106b44d31e8e0e53nd ** Version 1.3e
1cc20a8827ff6056399d64e3106b44d31e8e0e53nd ** - Changed timeout behavour during write to work whilst the sockets
1cc20a8827ff6056399d64e3106b44d31e8e0e53nd ** are filling up and apr_write() does writes a few - but not all.
1cc20a8827ff6056399d64e3106b44d31e8e0e53nd ** This will potentially change results. <dirkx@webweaving.org>, April 2001
1cc20a8827ff6056399d64e3106b44d31e8e0e53nd * - has various other poor buffer attacks related to the lazy parsing of
1cc20a8827ff6056399d64e3106b44d31e8e0e53nd * response headers from the server
1cc20a8827ff6056399d64e3106b44d31e8e0e53nd * - doesn't implement much of HTTP/1.x, only accepts certain forms of
1cc20a8827ff6056399d64e3106b44d31e8e0e53nd * responses
1cc20a8827ff6056399d64e3106b44d31e8e0e53nd * - (performance problem) heavy use of strstr shows up top in profile
1cc20a8827ff6056399d64e3106b44d31e8e0e53nd * only an issue for loopback usage
1cc20a8827ff6056399d64e3106b44d31e8e0e53nd/* -------------------------------------------------------------------- */
1cc20a8827ff6056399d64e3106b44d31e8e0e53nd/* Hmmm... This source code isn't being compiled in ASCII.
1cc20a8827ff6056399d64e3106b44d31e8e0e53nd * In order for data that flows over the network to make
2893256d86dd891d5859ef01dec4d85bf6488b69nd * sense, we need to translate to/from ASCII.
1cc20a8827ff6056399d64e3106b44d31e8e0e53nd/* affects include files on Solaris */
1cc20a8827ff6056399d64e3106b44d31e8e0e53nd/* Libraries on most systems.. */
1cc20a8827ff6056399d64e3106b44d31e8e0e53nd/* Libraries for RSAref and SYSSSL */
1cc20a8827ff6056399d64e3106b44d31e8e0e53nd/* ------------------- DEFINITIONS -------------------------- */
1cc20a8827ff6056399d64e3106b44d31e8e0e53nd/* maximum number of requests on a time limited test */
1cc20a8827ff6056399d64e3106b44d31e8e0e53nd/* good old state hostname */
1cc20a8827ff6056399d64e3106b44d31e8e0e53nd int rwrite, rwrote; /* keep pointers in what we write - across
1cc20a8827ff6056399d64e3106b44d31e8e0e53nd * EAGAINs */
2893256d86dd891d5859ef01dec4d85bf6488b69nd int length; /* Content-Length value used for keep-alive */
1cc20a8827ff6056399d64e3106b44d31e8e0e53nd char cbuff[CBUFFSIZE]; /* a buffer to store server response header */
1cc20a8827ff6056399d64e3106b44d31e8e0e53nd int gotheader; /* non-zero if we have the entire header in
1cc20a8827ff6056399d64e3106b44d31e8e0e53nd * cbuff */
1cc20a8827ff6056399d64e3106b44d31e8e0e53nd /* XXXX insert SSL timings */
1cc20a8827ff6056399d64e3106b44d31e8e0e53nd long starttime; /* start time of connection in seconds since
1cc20a8827ff6056399d64e3106b44d31e8e0e53nd * Jan. 1, 1970 */
829881b33014c4321c1e9ea5ec84826b177fe871humbedooh * response */
1cc20a8827ff6056399d64e3106b44d31e8e0e53nd#define ap_min(a,b) ((a)<(b))?(a):(b)
1cc20a8827ff6056399d64e3106b44d31e8e0e53nd#define ap_max(a,b) ((a)>(b))?(a):(b)
1cc20a8827ff6056399d64e3106b44d31e8e0e53nd/* --------------------- GLOBALS ---------------------------- */
bf7fcf0c216a914407c0877aa37894fd9aecc219nilgunint heartbeatres = 100; /* How often do we say we're alive */
f086b4b402fa9a2fefc7dda85de2a3cc1cd0a654rjungint concurrency = 1; /* Number of multiple requests to make */
0d0ba3a410038e179b695446bb149cce6264e0abndint confidence = 1; /* Show confidence estimator and warnings */
cc7e1025de9ac63bd4db6fe7f71c158b2cf09fe4humbedoohint keepalive = 0; /* try and do keepalive connections */
727872d18412fc021f03969b8641810d8896820bhumbedoohchar *host_field; /* value of "Host:" header field */
0d0ba3a410038e179b695446bb149cce6264e0abndchar postfile[1024]; /* name of file containing post data */
0d0ba3a410038e179b695446bb149cce6264e0abndchar *postdata; /* *buffer containing data from postfile */
ac082aefa89416cbdc9a1836eaf3bed9698201c8humbedoohapr_size_t postlen = 0; /* length of data to be POSTed */
0d0ba3a410038e179b695446bb149cce6264e0abndchar content_type[1024]; /* content type to put in POST header */
727872d18412fc021f03969b8641810d8896820bhumbedooh * authentification */
int isproxy = 0;
const char *tablestring;
const char *trstring;
const char *tdstring;
#ifdef USE_SSL
int ssl = 0;
int err_response = 0;
#ifdef NOT_ASCII
static void err(char *s)
apr_status_t e;
if (c->rwrite == 0) {
c->rwrote = 0;
if (posting)
close_connection(c);
if (l == c->rwrite)
if (e != APR_SUCCESS) {
if (!APR_STATUS_IS_EAGAIN(e)) {
epipe++;
close_connection(c);
c->rwrote += l;
c->rwrite -= l;
static void output_results(void)
long timetaken;
if (bad)
if (err_response)
if (keepalive)
if (posting > 0)
if (timetaken) {
if (posting > 0) {
if (requests) {
for (i = 0; i < requests; i++) {
for (i = 0; i < requests; i++) {
sdtot += a * a;
sdcon += a * a;
sdd += a * a;
sdwait += a * a;
if (gnuplot) {
if (!out) {
for (i = 0; i < requests; i++) {
(int (*) (const void *, const void *)) compradre);
(int (*) (const void *, const void *)) compri);
(int (*) (const void *, const void *)) comprando);
(int (*) (const void *, const void *)) compwait);
if (confidence) {
else if (d > sd ) \
for (i = 0; i < sizeof(percs) / sizeof(int); i++)
if (percs[i] <= 0)
if (csvperc) {
if (!out) {
static void output_html_results(void)
long timetaken;
if (bad)
if (err_response)
if (keepalive)
if (posting > 0)
if (timetaken) {
if (posting > 0) {
for (i = 0; i < requests; i++) {
c->read = 0;
c->bread = 0;
c->keepalive = 0;
c->cbx = 0;
c->gotheader = 0;
c->rwrite = 0;
!= APR_SUCCESS) {
c->rwrite = 0;
err_conn++;
start_connect(c);
started++;
write_request(c);
if (good)
bad++;
err_length++;
struct data s;
start_connect(c);
apr_size_t r;
char *part;
r = sizeof(buffer);
good++;
close_connection(c);
totalread += r;
if (c->read == 0) {
c->read += r;
if (!c->gotheader) {
#ifdef NOT_ASCII
if (space) {
err_response++;
start_connect(c);
if (!good) {
q = servername;
err_response++;
if (keepalive &&
char *cl;
if (!cl)
if (cl) {
c->bread += r;
totalbread += r;
good++;
doneka++;
bad++;
err_length++;
struct data s;
c->keepalive = 0;
c->length = 0;
c->gotheader = 0;
c->cbx = 0;
write_request(c);
static void test(void)
#ifdef NOT_ASCII
if (isproxy) {
if (!use_html) {
if (isproxy)
if (!posting) {
if (posting) {
#ifdef NOT_ASCII
for (i = 0; i < concurrency; i++) {
apr_int32_t n;
n = concurrency;
for (i = 0; i < concurrency; i++) {
bad++;
err_except++;
if (heartbeatres)
if (use_html)
static void copyright(void)
if (!use_html) {
printf(" This is ApacheBench, Version %s <i><%s></i> apache-2.0<br>\n", AB_VERSION, "$Revision: 1.63 $");
#if USE_SSL
#if USE_SSL
char *cp;
char *scope_id;
#if USE_SSL
return rv;
if (!postdata) {
return APR_ENOMEM;
return rv;
length);
return APR_EINVAL;
static void terminate(void)
const char *optarg;
#ifdef SIGPIPE
void *res;
#ifdef NOT_ASCII
if (status) {
if (status) {
if (status) {
#if USE_SSL
#if USE_SSL
if (!requests) {
heartbeatres = 0;
percentile = 0;
confidence = 0;
if (posting != 0)
else if (postdata) {
exit(r);
optarg++;
optarg++;
copyright();
heartbeatres = 0;
#ifdef USE_SSL
#if SIGPIPE
copyright();
test();