ab.c revision 3a36c0105198c15925b69c40ff0fc8f83dc34af2
1ac39787115a288f5e848344b1b1e8dccb1c58f1nd/* ====================================================================
1ac39787115a288f5e848344b1b1e8dccb1c58f1nd * The Apache Software License, Version 1.1
fd9abdda70912b99b24e3bf1a38f26fde908a74cnd * Copyright (c) 2000-2001 The Apache Software Foundation. All rights
fd9abdda70912b99b24e3bf1a38f26fde908a74cnd * reserved.
1ac39787115a288f5e848344b1b1e8dccb1c58f1nd * Redistribution and use in source and binary forms, with or without
1ac39787115a288f5e848344b1b1e8dccb1c58f1nd * modification, are permitted provided that the following conditions
1ac39787115a288f5e848344b1b1e8dccb1c58f1nd * are met:
1ac39787115a288f5e848344b1b1e8dccb1c58f1nd * 1. Redistributions of source code must retain the above copyright
1ac39787115a288f5e848344b1b1e8dccb1c58f1nd * 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
1ac39787115a288f5e848344b1b1e8dccb1c58f1nd * distribution.
af33a4994ae2ff15bc67d19ff1a7feb906745bf8rbowen * 3. The end-user documentation included with the redistribution,
3f08db06526d6901aa08c110b5bc7dde6bc39905nd * if any, must include the following acknowledgment:
1ac39787115a288f5e848344b1b1e8dccb1c58f1nd * "This product includes software developed by the
1ac39787115a288f5e848344b1b1e8dccb1c58f1nd * Apache Software Foundation (http://www.apache.org/)."
1ac39787115a288f5e848344b1b1e8dccb1c58f1nd * Alternately, this acknowledgment may appear in the software itself,
3f08db06526d6901aa08c110b5bc7dde6bc39905nd * if and wherever such third-party acknowledgments normally appear.
1ac39787115a288f5e848344b1b1e8dccb1c58f1nd * 4. The names "Apache" and "Apache Software Foundation" must
1ac39787115a288f5e848344b1b1e8dccb1c58f1nd * not be used to endorse or promote products derived from this
1ac39787115a288f5e848344b1b1e8dccb1c58f1nd * software without prior written permission. For written
1ac39787115a288f5e848344b1b1e8dccb1c58f1nd * permission, please contact apache@apache.org.
d474d8ef01ec5c2a09341cd148851ed383c3287crbowen * 5. Products derived from this software may not be called "Apache",
d474d8ef01ec5c2a09341cd148851ed383c3287crbowen * nor may "Apache" appear in their name, without prior written
1ac39787115a288f5e848344b1b1e8dccb1c58f1nd * permission of the Apache Software Foundation.
1ac39787115a288f5e848344b1b1e8dccb1c58f1nd * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
1ac39787115a288f5e848344b1b1e8dccb1c58f1nd * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
1ac39787115a288f5e848344b1b1e8dccb1c58f1nd * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
1ac39787115a288f5e848344b1b1e8dccb1c58f1nd * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
1ac39787115a288f5e848344b1b1e8dccb1c58f1nd * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
1ac39787115a288f5e848344b1b1e8dccb1c58f1nd * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
30471a4650391f57975f60bbb6e4a90be7b284bfhumbedooh * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
1ac39787115a288f5e848344b1b1e8dccb1c58f1nd * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
1ac39787115a288f5e848344b1b1e8dccb1c58f1nd * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
1ac39787115a288f5e848344b1b1e8dccb1c58f1nd * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
1ac39787115a288f5e848344b1b1e8dccb1c58f1nd * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
1ac39787115a288f5e848344b1b1e8dccb1c58f1nd * SUCH DAMAGE.
1ac39787115a288f5e848344b1b1e8dccb1c58f1nd * ====================================================================
1ac39787115a288f5e848344b1b1e8dccb1c58f1nd * This software consists of voluntary contributions made by many
1ac39787115a288f5e848344b1b1e8dccb1c58f1nd * individuals on behalf of the Apache Software Foundation. For more
1ac39787115a288f5e848344b1b1e8dccb1c58f1nd * information on the Apache Software Foundation, please see
1ac39787115a288f5e848344b1b1e8dccb1c58f1nd * Portions of this software are based upon public domain software
1ac39787115a288f5e848344b1b1e8dccb1c58f1nd * originally written at the National Center for Supercomputing Applications,
1ac39787115a288f5e848344b1b1e8dccb1c58f1nd * University of Illinois, Urbana-Champaign.
1ac39787115a288f5e848344b1b1e8dccb1c58f1nd ** This program is based on ZeusBench V1.0 written by Adam Twiss
1ac39787115a288f5e848344b1b1e8dccb1c58f1nd ** which is Copyright (c) 1996 by Zeus Technology Ltd. http://www.zeustech.net/
1ac39787115a288f5e848344b1b1e8dccb1c58f1nd ** This software is provided "as is" and any express or implied waranties,
1ac39787115a288f5e848344b1b1e8dccb1c58f1nd ** including but not limited to, the implied warranties of merchantability and
1ac39787115a288f5e848344b1b1e8dccb1c58f1nd ** fitness for a particular purpose are disclaimed. In no event shall
1ac39787115a288f5e848344b1b1e8dccb1c58f1nd ** Zeus Technology Ltd. be liable for any direct, indirect, incidental, special,
1ac39787115a288f5e848344b1b1e8dccb1c58f1nd ** exemplary, or consequential damaged (including, but not limited to,
1ac39787115a288f5e848344b1b1e8dccb1c58f1nd ** procurement of substitute good or services; loss of use, data, or profits;
1ac39787115a288f5e848344b1b1e8dccb1c58f1nd ** or business interruption) however caused and on theory of liability. Whether
1ac39787115a288f5e848344b1b1e8dccb1c58f1nd ** in contract, strict liability or tort (including negligence or otherwise)
1ac39787115a288f5e848344b1b1e8dccb1c58f1nd ** arising in any way out of the use of this software, even if advised of the
1ac39787115a288f5e848344b1b1e8dccb1c58f1nd ** possibility of such damage.
1ac39787115a288f5e848344b1b1e8dccb1c58f1nd ** HISTORY:
1ac39787115a288f5e848344b1b1e8dccb1c58f1nd ** - Originally written by Adam Twiss <adam@zeus.co.uk>, March 1996
1ac39787115a288f5e848344b1b1e8dccb1c58f1nd ** with input from Mike Belshe <mbelshe@netscape.com> and
1ac39787115a288f5e848344b1b1e8dccb1c58f1nd ** Michael Campanella <campanella@stevms.enet.dec.com>
1ac39787115a288f5e848344b1b1e8dccb1c58f1nd ** - Enhanced by Dean Gaudet <dgaudet@apache.org>, November 1997
1ac39787115a288f5e848344b1b1e8dccb1c58f1nd ** - Cleaned up by Ralf S. Engelschall <rse@apache.org>, March 1998
1ac39787115a288f5e848344b1b1e8dccb1c58f1nd ** - POST and verbosity by Kurt Sussman <kls@merlot.com>, August 1998
1ac39787115a288f5e848344b1b1e8dccb1c58f1nd ** - HTML table output added by David N. Welton <davidw@prosa.it>, January 1999
1ac39787115a288f5e848344b1b1e8dccb1c58f1nd ** - Added Cookie, Arbitrary header and auth support. <dirkx@webweaving.org>, April 1999
1ac39787115a288f5e848344b1b1e8dccb1c58f1nd ** Version 1.3d
1ac39787115a288f5e848344b1b1e8dccb1c58f1nd ** - Increased version number - as some of the socket/error handling has
1ac39787115a288f5e848344b1b1e8dccb1c58f1nd ** fundamentally changed - and will give fundamentally different results
1ac39787115a288f5e848344b1b1e8dccb1c58f1nd ** in situations where a server is dropping requests. Therefore you can
1ac39787115a288f5e848344b1b1e8dccb1c58f1nd ** no longer compare results of AB as easily. Hence the inc of the version.
1ac39787115a288f5e848344b1b1e8dccb1c58f1nd ** They should be closer to the truth though. Sander & <dirkx@covalent.net>, End 2000.
1ac39787115a288f5e848344b1b1e8dccb1c58f1nd ** - Fixed proxy functionality, added median/mean statistics, added gnuplot
1ac39787115a288f5e848344b1b1e8dccb1c58f1nd ** output option, added _experimental/rudimentary_ SSL support. Added
1ac39787115a288f5e848344b1b1e8dccb1c58f1nd ** confidence guestimators and warnings. Sander & <dirkx@covalent.net>, End 2000
1ac39787115a288f5e848344b1b1e8dccb1c58f1nd ** - Fixed serious int overflow issues which would cause realistic (longer
1ac39787115a288f5e848344b1b1e8dccb1c58f1nd ** than a few minutes) run's to have wrong (but believable) results. Added
1ac39787115a288f5e848344b1b1e8dccb1c58f1nd ** trapping of connection errors which influenced measurements.
1ac39787115a288f5e848344b1b1e8dccb1c58f1nd ** Contributed by Sander Temme - <sctemme@covalent.net>, Early 2001
1ac39787115a288f5e848344b1b1e8dccb1c58f1nd ** Version 1.3e
1ac39787115a288f5e848344b1b1e8dccb1c58f1nd ** - Changed timeout behavour during write to work whilst the sockets
1ac39787115a288f5e848344b1b1e8dccb1c58f1nd ** are filling up and apr_write() does writes a few - but not all.
1ac39787115a288f5e848344b1b1e8dccb1c58f1nd ** This will potentially change results. <dirkx@webweaving.org>, April 2001
1ac39787115a288f5e848344b1b1e8dccb1c58f1nd * - has various other poor buffer attacks related to the lazy parsing of
1ac39787115a288f5e848344b1b1e8dccb1c58f1nd * response headers from the server
1ac39787115a288f5e848344b1b1e8dccb1c58f1nd * - doesn't implement much of HTTP/1.x, only accepts certain forms of
1ac39787115a288f5e848344b1b1e8dccb1c58f1nd * responses
1ac39787115a288f5e848344b1b1e8dccb1c58f1nd * - (performance problem) heavy use of strstr shows up top in profile
1ac39787115a288f5e848344b1b1e8dccb1c58f1nd * only an issue for loopback usage
1ac39787115a288f5e848344b1b1e8dccb1c58f1nd/* -------------------------------------------------------------------- */
1ac39787115a288f5e848344b1b1e8dccb1c58f1nd/* Hmmm... This source code isn't being compiled in ASCII.
1ac39787115a288f5e848344b1b1e8dccb1c58f1nd * In order for data that flows over the network to make
1ac39787115a288f5e848344b1b1e8dccb1c58f1nd * sense, we need to translate to/from ASCII.
1ac39787115a288f5e848344b1b1e8dccb1c58f1nd/* affects include files on Solaris */
727872d18412fc021f03969b8641810d8896820bhumbedooh/* Libraries on most systems.. */
727872d18412fc021f03969b8641810d8896820bhumbedooh/* Libraries for RSAref and SYSSSL */
#if APR_HAVE_CTYPE_H
#include <ctype.h>
#define STATE_UNCONNECTED 0
struct connection {
int state;
int socknum;
#ifdef USE_SSL
struct data {
#ifdef USE_SSL
#define ap_min(a,b) ((a)<(b))?(a):(b)
#define ap_max(a,b) ((a)>(b))?(a):(b)
int connectport;
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.62 $");
#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();