ab.c revision 75955a79840ee0134d58addf0dd6733f7f71a99e
902bfaac7e88afebb6684fe1f2414ae2efbc7edfChristian Maeder/* ====================================================================
902bfaac7e88afebb6684fe1f2414ae2efbc7edfChristian Maeder * The Apache Software License, Version 1.1
3d13c5135e7bab987599acf23afe9c59df49b06fGeorgel Calin * Copyright (c) 2000 The Apache Software Foundation. All rights
3d13c5135e7bab987599acf23afe9c59df49b06fGeorgel Calin * Redistribution and use in source and binary forms, with or without
902bfaac7e88afebb6684fe1f2414ae2efbc7edfChristian Maeder * modification, are permitted provided that the following conditions
3d13c5135e7bab987599acf23afe9c59df49b06fGeorgel Calin * 1. Redistributions of source code must retain the above copyright
3d13c5135e7bab987599acf23afe9c59df49b06fGeorgel Calin * notice, this list of conditions and the following disclaimer.
902bfaac7e88afebb6684fe1f2414ae2efbc7edfChristian Maeder * 2. Redistributions in binary form must reproduce the above copyright
3d13c5135e7bab987599acf23afe9c59df49b06fGeorgel Calin * notice, this list of conditions and the following disclaimer in
3d13c5135e7bab987599acf23afe9c59df49b06fGeorgel Calin * the documentation and/or other materials provided with the
902bfaac7e88afebb6684fe1f2414ae2efbc7edfChristian Maeder * distribution.
902bfaac7e88afebb6684fe1f2414ae2efbc7edfChristian Maeder * 3. The end-user documentation included with the redistribution,
3d13c5135e7bab987599acf23afe9c59df49b06fGeorgel Calin * if any, must include the following acknowledgment:
3d13c5135e7bab987599acf23afe9c59df49b06fGeorgel Calin * "This product includes software developed by the
3d13c5135e7bab987599acf23afe9c59df49b06fGeorgel Calin * Apache Software Foundation (http://www.apache.org/)."
3d13c5135e7bab987599acf23afe9c59df49b06fGeorgel Calin * Alternately, this acknowledgment may appear in the software itself,
3d13c5135e7bab987599acf23afe9c59df49b06fGeorgel Calin * if and wherever such third-party acknowledgments normally appear.
3d13c5135e7bab987599acf23afe9c59df49b06fGeorgel Calin * 4. The names "Apache" and "Apache Software Foundation" must
3d13c5135e7bab987599acf23afe9c59df49b06fGeorgel Calin * not be used to endorse or promote products derived from this
902bfaac7e88afebb6684fe1f2414ae2efbc7edfChristian Maeder * software without prior written permission. For written
3d13c5135e7bab987599acf23afe9c59df49b06fGeorgel Calin * permission, please contact apache@apache.org.
3d13c5135e7bab987599acf23afe9c59df49b06fGeorgel Calin * 5. Products derived from this software may not be called "Apache",
3d13c5135e7bab987599acf23afe9c59df49b06fGeorgel Calin * nor may "Apache" appear in their name, without prior written
902bfaac7e88afebb6684fe1f2414ae2efbc7edfChristian Maeder * permission of the Apache Software Foundation.
3d13c5135e7bab987599acf23afe9c59df49b06fGeorgel Calin * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
3d13c5135e7bab987599acf23afe9c59df49b06fGeorgel Calin * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
3d13c5135e7bab987599acf23afe9c59df49b06fGeorgel Calin * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
902bfaac7e88afebb6684fe1f2414ae2efbc7edfChristian Maeder * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
3d13c5135e7bab987599acf23afe9c59df49b06fGeorgel Calin * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
902bfaac7e88afebb6684fe1f2414ae2efbc7edfChristian Maeder * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
902bfaac7e88afebb6684fe1f2414ae2efbc7edfChristian Maeder * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
3d13c5135e7bab987599acf23afe9c59df49b06fGeorgel Calin * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
3d13c5135e7bab987599acf23afe9c59df49b06fGeorgel Calin * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
3d13c5135e7bab987599acf23afe9c59df49b06fGeorgel Calin * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
3d13c5135e7bab987599acf23afe9c59df49b06fGeorgel Calin * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
3d13c5135e7bab987599acf23afe9c59df49b06fGeorgel Calin * SUCH DAMAGE.
3d13c5135e7bab987599acf23afe9c59df49b06fGeorgel Calin * ====================================================================
3d13c5135e7bab987599acf23afe9c59df49b06fGeorgel Calin * This software consists of voluntary contributions made by many
3d13c5135e7bab987599acf23afe9c59df49b06fGeorgel Calin * individuals on behalf of the Apache Software Foundation. For more
3d13c5135e7bab987599acf23afe9c59df49b06fGeorgel Calin * information on the Apache Software Foundation, please see
3d13c5135e7bab987599acf23afe9c59df49b06fGeorgel Calin * Portions of this software are based upon public domain software
3d13c5135e7bab987599acf23afe9c59df49b06fGeorgel Calin * originally written at the National Center for Supercomputing Applications,
3d13c5135e7bab987599acf23afe9c59df49b06fGeorgel Calin * University of Illinois, Urbana-Champaign.
3d13c5135e7bab987599acf23afe9c59df49b06fGeorgel Calin ** This program is based on ZeusBench V1.0 written by Adam Twiss
3d13c5135e7bab987599acf23afe9c59df49b06fGeorgel Calin ** which is Copyright (c) 1996 by Zeus Technology Ltd. http://www.zeustech.net/
3d13c5135e7bab987599acf23afe9c59df49b06fGeorgel Calin ** This software is provided "as is" and any express or implied waranties,
3d13c5135e7bab987599acf23afe9c59df49b06fGeorgel Calin ** including but not limited to, the implied warranties of merchantability and
3d13c5135e7bab987599acf23afe9c59df49b06fGeorgel Calin ** fitness for a particular purpose are disclaimed. In no event shall
3d13c5135e7bab987599acf23afe9c59df49b06fGeorgel Calin ** Zeus Technology Ltd. be liable for any direct, indirect, incidental, special,
3d13c5135e7bab987599acf23afe9c59df49b06fGeorgel Calin ** exemplary, or consequential damaged (including, but not limited to,
3d13c5135e7bab987599acf23afe9c59df49b06fGeorgel Calin ** procurement of substitute good or services; loss of use, data, or profits;
3d13c5135e7bab987599acf23afe9c59df49b06fGeorgel Calin ** or business interruption) however caused and on theory of liability. Whether
3d13c5135e7bab987599acf23afe9c59df49b06fGeorgel Calin ** in contract, strict liability or tort (including negligence or otherwise)
3d13c5135e7bab987599acf23afe9c59df49b06fGeorgel Calin ** arising in any way out of the use of this software, even if advised of the
3d13c5135e7bab987599acf23afe9c59df49b06fGeorgel Calin ** possibility of such damage.
3d13c5135e7bab987599acf23afe9c59df49b06fGeorgel Calin ** - Originally written by Adam Twiss <adam@zeus.co.uk>, March 1996
3d13c5135e7bab987599acf23afe9c59df49b06fGeorgel Calin ** with input from Mike Belshe <mbelshe@netscape.com> and
902bfaac7e88afebb6684fe1f2414ae2efbc7edfChristian Maeder ** Michael Campanella <campanella@stevms.enet.dec.com>
3d13c5135e7bab987599acf23afe9c59df49b06fGeorgel Calin ** - Enhanced by Dean Gaudet <dgaudet@apache.org>, November 1997
3d13c5135e7bab987599acf23afe9c59df49b06fGeorgel Calin ** - Cleaned up by Ralf S. Engelschall <rse@apache.org>, March 1998
3d13c5135e7bab987599acf23afe9c59df49b06fGeorgel Calin ** - POST and verbosity by Kurt Sussman <kls@merlot.com>, August 1998
3d13c5135e7bab987599acf23afe9c59df49b06fGeorgel Calin ** - HTML table output added by David N. Welton <davidw@prosa.it>, January 1999
3d13c5135e7bab987599acf23afe9c59df49b06fGeorgel Calin ** - Added Cookie, Arbitrary header and auth support. <dirkx@webweaving.org>, April 1999
3d13c5135e7bab987599acf23afe9c59df49b06fGeorgel Calin * - has various other poor buffer attacks related to the lazy parsing of
3d13c5135e7bab987599acf23afe9c59df49b06fGeorgel Calin * response headers from the server
3d13c5135e7bab987599acf23afe9c59df49b06fGeorgel Calin * - doesn't implement much of HTTP/1.x, only accepts certain forms of
902bfaac7e88afebb6684fe1f2414ae2efbc7edfChristian Maeder * - (performance problem) heavy use of strstr shows up top in profile
3d13c5135e7bab987599acf23afe9c59df49b06fGeorgel Calin * only an issue for loopback usage
3d13c5135e7bab987599acf23afe9c59df49b06fGeorgel Calin/* -------------------------------------------------------------------- */
3d13c5135e7bab987599acf23afe9c59df49b06fGeorgel Calin/* Hmmm... This source code isn't being compiled in ASCII.
902bfaac7e88afebb6684fe1f2414ae2efbc7edfChristian Maeder * In order for data that flows over the network to make
3d13c5135e7bab987599acf23afe9c59df49b06fGeorgel Calin * sense, we need to translate to/from ASCII.
3d13c5135e7bab987599acf23afe9c59df49b06fGeorgel Calin/* affects include files on Solaris */
3d13c5135e7bab987599acf23afe9c59df49b06fGeorgel Calin/* ------------------- DEFINITIONS -------------------------- */
3d13c5135e7bab987599acf23afe9c59df49b06fGeorgel Calin/* maximum number of requests on a time limited test */
3d13c5135e7bab987599acf23afe9c59df49b06fGeorgel Calin/* good old state hostname */
3d13c5135e7bab987599acf23afe9c59df49b06fGeorgel Calin int length; /* Content-Length value used for keep-alive */
3d13c5135e7bab987599acf23afe9c59df49b06fGeorgel Calin char cbuff[CBUFFSIZE]; /* a buffer to store server response header */
3d13c5135e7bab987599acf23afe9c59df49b06fGeorgel Calin int keepalive; /* non-zero if a keep-alive request */
3d13c5135e7bab987599acf23afe9c59df49b06fGeorgel Calin int gotheader; /* non-zero if we have the entire header in
3d13c5135e7bab987599acf23afe9c59df49b06fGeorgel Calin#define ap_min(a,b) ((a)<(b))?(a):(b)
3d13c5135e7bab987599acf23afe9c59df49b06fGeorgel Calin#define ap_max(a,b) ((a)>(b))?(a):(b)
3d13c5135e7bab987599acf23afe9c59df49b06fGeorgel Calin/* --------------------- GLOBALS ---------------------------- */
3d13c5135e7bab987599acf23afe9c59df49b06fGeorgel Calinint verbosity = 0; /* no verbosity by default */
902bfaac7e88afebb6684fe1f2414ae2efbc7edfChristian Maederint requests = 1; /* Number of requests to make */
3d13c5135e7bab987599acf23afe9c59df49b06fGeorgel Calinint concurrency = 1; /* Number of multiple requests to make */
3d13c5135e7bab987599acf23afe9c59df49b06fGeorgel Calinint keepalive = 0; /* try and do keepalive connections */
3d13c5135e7bab987599acf23afe9c59df49b06fGeorgel Calinchar servername[1024]; /* name that server reports */
char *tablestring;
char *trstring;
char *tdstring;
int err_response = 0;
#ifdef NOT_ASCII
static void err(char *s)
if (errno) {
perror(s);
if (posting) {
static void output_results(void)
int timetaken;
if (bad)
if (err_response)
if (keepalive)
if (posting)
if (timetaken) {
if (posting>0) {
for (i = 0; i < requests; i++) {
static void output_html_results(void)
int 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;
err_conn++;
start_connect(c);
write_request(c);
bad ++;
err_length++;
struct data s;
start_connect(c);
ap_ssize_t r;
char *part;
r = sizeof(buffer);
good++;
close_connection(c);
c->read += r;
totalread += 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 (!use_html) {
if (!posting) {
path,
path,
#ifdef NOT_ASCII
for (i = 0; i < concurrency; i++) {
ap_int32_t n;
n = concurrency;
for (i = 0; i < concurrency; i++) {
bad++;
err_except++;
if (use_html)
static void copyright(void)
if (!use_html) {
printf(" This is ApacheBench, Version %s <i><%s></i> apache-2.0<br>\n", VERSION, "$Revision: 1.16 $");
char *cp;
h = url;
p = cp;
if (p != NULL)
return errno;
if (!postdata) {
return ENOMEM;
return EIO;
#ifdef NOT_ASCII
#ifdef NOT_ASCII
if (status) {
if (status) {
if (status) {
if (!requests) {
if (posting != 0)
else if (postdata) {
exit(r);
ap_optarg++;
ap_optarg++;
copyright();
copyright();
test();