ab.c revision ac45eb1602bbff4cdd88441c8dbe593a5f69b602
03831d35f7499c87d51205817c93e9a8d42c4baestevel/* ====================================================================
03831d35f7499c87d51205817c93e9a8d42c4baestevel * The Apache Software License, Version 1.1
03831d35f7499c87d51205817c93e9a8d42c4baestevel * Copyright (c) 2000-2001 The Apache Software Foundation. All rights
03831d35f7499c87d51205817c93e9a8d42c4baestevel * reserved.
03831d35f7499c87d51205817c93e9a8d42c4baestevel * Redistribution and use in source and binary forms, with or without
03831d35f7499c87d51205817c93e9a8d42c4baestevel * modification, are permitted provided that the following conditions
03831d35f7499c87d51205817c93e9a8d42c4baestevel * 1. Redistributions of source code must retain the above copyright
03831d35f7499c87d51205817c93e9a8d42c4baestevel * notice, this list of conditions and the following disclaimer.
03831d35f7499c87d51205817c93e9a8d42c4baestevel * 2. Redistributions in binary form must reproduce the above copyright
03831d35f7499c87d51205817c93e9a8d42c4baestevel * notice, this list of conditions and the following disclaimer in
03831d35f7499c87d51205817c93e9a8d42c4baestevel * the documentation and/or other materials provided with the
03831d35f7499c87d51205817c93e9a8d42c4baestevel * distribution.
03831d35f7499c87d51205817c93e9a8d42c4baestevel * 3. The end-user documentation included with the redistribution,
03831d35f7499c87d51205817c93e9a8d42c4baestevel * if any, must include the following acknowledgment:
03831d35f7499c87d51205817c93e9a8d42c4baestevel * "This product includes software developed by the
03831d35f7499c87d51205817c93e9a8d42c4baestevel * Apache Software Foundation (http://www.apache.org/)."
03831d35f7499c87d51205817c93e9a8d42c4baestevel * Alternately, this acknowledgment may appear in the software itself,
03831d35f7499c87d51205817c93e9a8d42c4baestevel * if and wherever such third-party acknowledgments normally appear.
03831d35f7499c87d51205817c93e9a8d42c4baestevel * 4. The names "Apache" and "Apache Software Foundation" must
03831d35f7499c87d51205817c93e9a8d42c4baestevel * not be used to endorse or promote products derived from this
03831d35f7499c87d51205817c93e9a8d42c4baestevel * software without prior written permission. For written
03831d35f7499c87d51205817c93e9a8d42c4baestevel * permission, please contact apache@apache.org.
03831d35f7499c87d51205817c93e9a8d42c4baestevel * 5. Products derived from this software may not be called "Apache",
03831d35f7499c87d51205817c93e9a8d42c4baestevel * nor may "Apache" appear in their name, without prior written
03831d35f7499c87d51205817c93e9a8d42c4baestevel * permission of the Apache Software Foundation.
03831d35f7499c87d51205817c93e9a8d42c4baestevel * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
03831d35f7499c87d51205817c93e9a8d42c4baestevel * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
03831d35f7499c87d51205817c93e9a8d42c4baestevel * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
03831d35f7499c87d51205817c93e9a8d42c4baestevel * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
03831d35f7499c87d51205817c93e9a8d42c4baestevel * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
03831d35f7499c87d51205817c93e9a8d42c4baestevel * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
03831d35f7499c87d51205817c93e9a8d42c4baestevel * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
03831d35f7499c87d51205817c93e9a8d42c4baestevel * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
03831d35f7499c87d51205817c93e9a8d42c4baestevel * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
03831d35f7499c87d51205817c93e9a8d42c4baestevel * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
03831d35f7499c87d51205817c93e9a8d42c4baestevel * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
03831d35f7499c87d51205817c93e9a8d42c4baestevel * SUCH DAMAGE.
03831d35f7499c87d51205817c93e9a8d42c4baestevel * ====================================================================
03831d35f7499c87d51205817c93e9a8d42c4baestevel * This software consists of voluntary contributions made by many
03831d35f7499c87d51205817c93e9a8d42c4baestevel * individuals on behalf of the Apache Software Foundation. For more
03831d35f7499c87d51205817c93e9a8d42c4baestevel * information on the Apache Software Foundation, please see
03831d35f7499c87d51205817c93e9a8d42c4baestevel * Portions of this software are based upon public domain software
03831d35f7499c87d51205817c93e9a8d42c4baestevel * originally written at the National Center for Supercomputing Applications,
03831d35f7499c87d51205817c93e9a8d42c4baestevel * University of Illinois, Urbana-Champaign.
03831d35f7499c87d51205817c93e9a8d42c4baestevel ** This program is based on ZeusBench V1.0 written by Adam Twiss
03831d35f7499c87d51205817c93e9a8d42c4baestevel ** which is Copyright (c) 1996 by Zeus Technology Ltd. http://www.zeustech.net/
03831d35f7499c87d51205817c93e9a8d42c4baestevel ** This software is provided "as is" and any express or implied waranties,
03831d35f7499c87d51205817c93e9a8d42c4baestevel ** including but not limited to, the implied warranties of merchantability and
03831d35f7499c87d51205817c93e9a8d42c4baestevel ** fitness for a particular purpose are disclaimed. In no event shall
03831d35f7499c87d51205817c93e9a8d42c4baestevel ** Zeus Technology Ltd. be liable for any direct, indirect, incidental, special,
03831d35f7499c87d51205817c93e9a8d42c4baestevel ** exemplary, or consequential damaged (including, but not limited to,
03831d35f7499c87d51205817c93e9a8d42c4baestevel ** procurement of substitute good or services; loss of use, data, or profits;
03831d35f7499c87d51205817c93e9a8d42c4baestevel ** or business interruption) however caused and on theory of liability. Whether
03831d35f7499c87d51205817c93e9a8d42c4baestevel ** in contract, strict liability or tort (including negligence or otherwise)
03831d35f7499c87d51205817c93e9a8d42c4baestevel ** arising in any way out of the use of this software, even if advised of the
03831d35f7499c87d51205817c93e9a8d42c4baestevel ** possibility of such damage.
03831d35f7499c87d51205817c93e9a8d42c4baestevel ** HISTORY:
03831d35f7499c87d51205817c93e9a8d42c4baestevel ** - Originally written by Adam Twiss <adam@zeus.co.uk>, March 1996
03831d35f7499c87d51205817c93e9a8d42c4baestevel ** with input from Mike Belshe <mbelshe@netscape.com> and
03831d35f7499c87d51205817c93e9a8d42c4baestevel ** Michael Campanella <campanella@stevms.enet.dec.com>
03831d35f7499c87d51205817c93e9a8d42c4baestevel ** - Enhanced by Dean Gaudet <dgaudet@apache.org>, November 1997
03831d35f7499c87d51205817c93e9a8d42c4baestevel ** - Cleaned up by Ralf S. Engelschall <rse@apache.org>, March 1998
03831d35f7499c87d51205817c93e9a8d42c4baestevel ** - POST and verbosity by Kurt Sussman <kls@merlot.com>, August 1998
03831d35f7499c87d51205817c93e9a8d42c4baestevel ** - HTML table output added by David N. Welton <davidw@prosa.it>, January 1999
03831d35f7499c87d51205817c93e9a8d42c4baestevel ** - Added Cookie, Arbitrary header and auth support. <dirkx@webweaving.org>, April 1999
03831d35f7499c87d51205817c93e9a8d42c4baestevel ** Version 1.3d
03831d35f7499c87d51205817c93e9a8d42c4baestevel ** - Increased version number - as some of the socket/error handling has
03831d35f7499c87d51205817c93e9a8d42c4baestevel ** fundamentally changed - and will give fundamentally different results
03831d35f7499c87d51205817c93e9a8d42c4baestevel ** in situations where a server is dropping requests. Therefore you can
03831d35f7499c87d51205817c93e9a8d42c4baestevel ** no longer compare results of AB as easily. Hence the inc of the version.
03831d35f7499c87d51205817c93e9a8d42c4baestevel ** They should be closer to the truth though. Sander & <dirkx@covalent.net>, End 2000.
03831d35f7499c87d51205817c93e9a8d42c4baestevel ** - Fixed proxy functionality, added median/mean statistics, added gnuplot
03831d35f7499c87d51205817c93e9a8d42c4baestevel ** output option, added _experimental/rudimentary_ SSL support. Added
03831d35f7499c87d51205817c93e9a8d42c4baestevel ** confidence guestimators and warnings. Sander & <dirkx@covalent.net>, End 2000
03831d35f7499c87d51205817c93e9a8d42c4baestevel ** - Fixed serious int overflow issues which would cause realistic (longer
03831d35f7499c87d51205817c93e9a8d42c4baestevel ** than a few minutes) run's to have wrong (but believable) results. Added
03831d35f7499c87d51205817c93e9a8d42c4baestevel ** trapping of connection errors which influenced measurements.
03831d35f7499c87d51205817c93e9a8d42c4baestevel ** Contributed by Sander Temme - <sctemme@covalent.net>, Early 2001
03831d35f7499c87d51205817c93e9a8d42c4baestevel ** Version 1.3e
03831d35f7499c87d51205817c93e9a8d42c4baestevel ** - Changed timeout behavour during write to work whilst the sockets
03831d35f7499c87d51205817c93e9a8d42c4baestevel ** are filling up and apr_write() does writes a few - but not all.
03831d35f7499c87d51205817c93e9a8d42c4baestevel ** This will potentially change results. <dirkx@webweaving.org>, April 2001
#define NOT_ASCII
#define BSD_COMP
#include "apr.h"
#include "apr_strings.h"
#include "apr_network_io.h"
#include "apr_file_io.h"
#include "apr_time.h"
#include "apr_getopt.h"
#include "apr_general.h"
#include <signal.h>
#include "apr_lib.h"
#if APR_HAVE_STDIO_H
#include <stdlib.h>
#include "apr_base64.h"
#ifdef NOT_ASCII
#include "apr_xlate.h"
#if APR_HAVE_STDIO_H
#include <stdio.h>
#include <stdlib.h>
#ifdef USE_SSL
#include <rsa.h>
#include <crypto.h>
#include <x509.h>
#include <pem.h>
#include <err.h>
#include <ssl.h>
#include <math.h>
#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) {
long sttime;
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 *)) compwait);
(int (*) (const void *, const void *)) comprando);
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.68 $");
#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 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();