ab.c revision 16478631d2fd87116d7e41b3ed8748343b453d88
a530dde7009b0a808300c420def741354a4d13d2Martin Kühl/* ====================================================================
a530dde7009b0a808300c420def741354a4d13d2Martin Kühl * The Apache Software License, Version 1.1
a530dde7009b0a808300c420def741354a4d13d2Martin Kühl * Copyright (c) 2000-2001 The Apache Software Foundation. All rights
a530dde7009b0a808300c420def741354a4d13d2Martin Kühl * Redistribution and use in source and binary forms, with or without
a530dde7009b0a808300c420def741354a4d13d2Martin Kühl * modification, are permitted provided that the following conditions
a530dde7009b0a808300c420def741354a4d13d2Martin Kühl * 1. Redistributions of source code must retain the above copyright
a530dde7009b0a808300c420def741354a4d13d2Martin Kühl * notice, this list of conditions and the following disclaimer.
d72e314a1952b4418fb1c98b17dbab0d16bba585Adrián Riesco * 2. Redistributions in binary form must reproduce the above copyright
d72e314a1952b4418fb1c98b17dbab0d16bba585Adrián Riesco * notice, this list of conditions and the following disclaimer in
5318901bb69bf247e0f341312c800ba4ea87e46bAdrián Riesco * the documentation and/or other materials provided with the
5318901bb69bf247e0f341312c800ba4ea87e46bAdrián Riesco * distribution.
d72e314a1952b4418fb1c98b17dbab0d16bba585Adrián Riesco * 3. The end-user documentation included with the redistribution,
d72e314a1952b4418fb1c98b17dbab0d16bba585Adrián Riesco * if any, must include the following acknowledgment:
d72e314a1952b4418fb1c98b17dbab0d16bba585Adrián Riesco * "This product includes software developed by the
d72e314a1952b4418fb1c98b17dbab0d16bba585Adrián Riesco * Apache Software Foundation (http://www.apache.org/)."
d72e314a1952b4418fb1c98b17dbab0d16bba585Adrián Riesco * Alternately, this acknowledgment may appear in the software itself,
5318901bb69bf247e0f341312c800ba4ea87e46bAdrián Riesco * if and wherever such third-party acknowledgments normally appear.
5318901bb69bf247e0f341312c800ba4ea87e46bAdrián Riesco * 4. The names "Apache" and "Apache Software Foundation" must
d72e314a1952b4418fb1c98b17dbab0d16bba585Adrián Riesco * not be used to endorse or promote products derived from this
d72e314a1952b4418fb1c98b17dbab0d16bba585Adrián Riesco * software without prior written permission. For written
d72e314a1952b4418fb1c98b17dbab0d16bba585Adrián Riesco * permission, please contact apache@apache.org.
5318901bb69bf247e0f341312c800ba4ea87e46bAdrián Riesco * 5. Products derived from this software may not be called "Apache",
223be434693e8c97e2522ac19155a284b3536035Adrián Riesco * nor may "Apache" appear in their name, without prior written
d72e314a1952b4418fb1c98b17dbab0d16bba585Adrián Riesco * permission of the Apache Software Foundation.
d72e314a1952b4418fb1c98b17dbab0d16bba585Adrián Riesco * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
d72e314a1952b4418fb1c98b17dbab0d16bba585Adrián Riesco * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
b9840e4ee6fda6e42fa4ee9f337482ccc4839a39Adrián Riesco * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
d72e314a1952b4418fb1c98b17dbab0d16bba585Adrián Riesco * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
d72e314a1952b4418fb1c98b17dbab0d16bba585Adrián Riesco * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
223be434693e8c97e2522ac19155a284b3536035Adrián Riesco * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
223be434693e8c97e2522ac19155a284b3536035Adrián Riesco * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
223be434693e8c97e2522ac19155a284b3536035Adrián Riesco * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
223be434693e8c97e2522ac19155a284b3536035Adrián Riesco * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
223be434693e8c97e2522ac19155a284b3536035Adrián Riesco * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
223be434693e8c97e2522ac19155a284b3536035Adrián Riesco * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
223be434693e8c97e2522ac19155a284b3536035Adrián Riesco * SUCH DAMAGE.
223be434693e8c97e2522ac19155a284b3536035Adrián Riesco * ====================================================================
5318901bb69bf247e0f341312c800ba4ea87e46bAdrián Riesco * This software consists of voluntary contributions made by many
51c15129e8118fed5c33c334f8df82619ce98e7dAdrián Riesco * individuals on behalf of the Apache Software Foundation. For more
d72e314a1952b4418fb1c98b17dbab0d16bba585Adrián Riesco * information on the Apache Software Foundation, please see
0f35e410ce3d3202f6769e9d139ad26d1de69b8eAdrián Riesco * Portions of this software are based upon public domain software
5318901bb69bf247e0f341312c800ba4ea87e46bAdrián Riesco * originally written at the National Center for Supercomputing Applications,
5318901bb69bf247e0f341312c800ba4ea87e46bAdrián Riesco * University of Illinois, Urbana-Champaign.
5318901bb69bf247e0f341312c800ba4ea87e46bAdrián Riesco ** This program is based on ZeusBench V1.0 written by Adam Twiss
5318901bb69bf247e0f341312c800ba4ea87e46bAdrián Riesco ** which is Copyright (c) 1996 by Zeus Technology Ltd. http://www.zeustech.net/
5318901bb69bf247e0f341312c800ba4ea87e46bAdrián Riesco ** This software is provided "as is" and any express or implied waranties,
5318901bb69bf247e0f341312c800ba4ea87e46bAdrián Riesco ** including but not limited to, the implied warranties of merchantability and
5318901bb69bf247e0f341312c800ba4ea87e46bAdrián Riesco ** fitness for a particular purpose are disclaimed. In no event shall
5318901bb69bf247e0f341312c800ba4ea87e46bAdrián Riesco ** Zeus Technology Ltd. be liable for any direct, indirect, incidental, special,
aea9000fc94442cbfc92596f4264473c0fce51e4Adrián Riesco ** exemplary, or consequential damaged (including, but not limited to,
d72e314a1952b4418fb1c98b17dbab0d16bba585Adrián Riesco ** procurement of substitute good or services; loss of use, data, or profits;
5318901bb69bf247e0f341312c800ba4ea87e46bAdrián Riesco ** or business interruption) however caused and on theory of liability. Whether
5318901bb69bf247e0f341312c800ba4ea87e46bAdrián Riesco ** in contract, strict liability or tort (including negligence or otherwise)
5318901bb69bf247e0f341312c800ba4ea87e46bAdrián Riesco ** arising in any way out of the use of this software, even if advised of the
5318901bb69bf247e0f341312c800ba4ea87e46bAdrián Riesco ** possibility of such damage.
5318901bb69bf247e0f341312c800ba4ea87e46bAdrián Riesco ** - Originally written by Adam Twiss <adam@zeus.co.uk>, March 1996
5318901bb69bf247e0f341312c800ba4ea87e46bAdrián Riesco ** with input from Mike Belshe <mbelshe@netscape.com> and
7474965b2e6323002c96c0b39a59843cde201870Adrián Riesco ** Michael Campanella <campanella@stevms.enet.dec.com>
5318901bb69bf247e0f341312c800ba4ea87e46bAdrián Riesco ** - Enhanced by Dean Gaudet <dgaudet@apache.org>, November 1997
5318901bb69bf247e0f341312c800ba4ea87e46bAdrián Riesco ** - Cleaned up by Ralf S. Engelschall <rse@apache.org>, March 1998
5318901bb69bf247e0f341312c800ba4ea87e46bAdrián Riesco ** - POST and verbosity by Kurt Sussman <kls@merlot.com>, August 1998
5318901bb69bf247e0f341312c800ba4ea87e46bAdrián Riesco ** - HTML table output added by David N. Welton <davidw@prosa.it>, January 1999
5318901bb69bf247e0f341312c800ba4ea87e46bAdrián Riesco ** - Added Cookie, Arbitrary header and auth support. <dirkx@webweaving.org>, April 1999
5318901bb69bf247e0f341312c800ba4ea87e46bAdrián Riesco ** Version 1.3d
5318901bb69bf247e0f341312c800ba4ea87e46bAdrián Riesco ** - Increased version number - as some of the socket/error handling has
5318901bb69bf247e0f341312c800ba4ea87e46bAdrián Riesco ** fundamentally changed - and will give fundamentally different results
5318901bb69bf247e0f341312c800ba4ea87e46bAdrián Riesco ** in situations where a server is dropping requests. Therefore you can
6d498b6f56ed9f71cced898b6c42fb48f6e60583Adrián Riesco ** no longer compare results of AB as easily. Hence the inc of the version.
5318901bb69bf247e0f341312c800ba4ea87e46bAdrián Riesco ** They should be closer to the truth though. Sander & <dirkx@covalent.net>, End 2000.
7474965b2e6323002c96c0b39a59843cde201870Adrián Riesco ** - Fixed proxy functionality, added median/mean statistics, added gnuplot
5318901bb69bf247e0f341312c800ba4ea87e46bAdrián Riesco ** output option, added _experimental/rudimentary_ SSL support. Added
5318901bb69bf247e0f341312c800ba4ea87e46bAdrián Riesco ** confidence guestimators and warnings. Sander & <dirkx@covalent.net>, End 2000
5318901bb69bf247e0f341312c800ba4ea87e46bAdrián Riesco ** - Fixed serious int overflow issues which would cause realistic (longer
6d498b6f56ed9f71cced898b6c42fb48f6e60583Adrián Riesco ** than a few minutes) run's to have wrong (but believable) results. Added
5318901bb69bf247e0f341312c800ba4ea87e46bAdrián Riesco ** trapping of connection errors which influenced measurements.
5318901bb69bf247e0f341312c800ba4ea87e46bAdrián Riesco ** Contributed by Sander Temme - <sctemme@covalent.net>, Early 2001
5318901bb69bf247e0f341312c800ba4ea87e46bAdrián Riesco ** Version 1.3e
5318901bb69bf247e0f341312c800ba4ea87e46bAdrián Riesco ** - Changed timeout behavour during write to work whilst the sockets
5318901bb69bf247e0f341312c800ba4ea87e46bAdrián Riesco ** are filling up and apr_write() does writes a few - but not all.
5318901bb69bf247e0f341312c800ba4ea87e46bAdrián Riesco ** This will potentially change results. <dirkx@webweaving.org>, April 2001
5318901bb69bf247e0f341312c800ba4ea87e46bAdrián Riesco * - has various other poor buffer attacks related to the lazy parsing of
5318901bb69bf247e0f341312c800ba4ea87e46bAdrián Riesco * response headers from the server
5318901bb69bf247e0f341312c800ba4ea87e46bAdrián Riesco * - doesn't implement much of HTTP/1.x, only accepts certain forms of
5318901bb69bf247e0f341312c800ba4ea87e46bAdrián Riesco * - (performance problem) heavy use of strstr shows up top in profile
5318901bb69bf247e0f341312c800ba4ea87e46bAdrián Riesco * only an issue for loopback usage
5318901bb69bf247e0f341312c800ba4ea87e46bAdrián Riesco/* -------------------------------------------------------------------- */
5318901bb69bf247e0f341312c800ba4ea87e46bAdrián Riesco/* Hmmm... This source code isn't being compiled in ASCII.
6e121321775373fe11161d23c541437456df19b4Adrián Riesco * In order for data that flows over the network to make
6e121321775373fe11161d23c541437456df19b4Adrián Riesco * sense, we need to translate to/from ASCII.
6e121321775373fe11161d23c541437456df19b4Adrián Riesco/* affects include files on Solaris */
5318901bb69bf247e0f341312c800ba4ea87e46bAdrián Riesco/* Libraries on most systems.. */
5318901bb69bf247e0f341312c800ba4ea87e46bAdrián Riesco/* Libraries for RSAref and SYSSSL */
5318901bb69bf247e0f341312c800ba4ea87e46bAdrián Riesco/* ------------------- DEFINITIONS -------------------------- */
51c15129e8118fed5c33c334f8df82619ce98e7dAdrián Riesco/* maximum number of requests on a time limited test */
5318901bb69bf247e0f341312c800ba4ea87e46bAdrián Riesco/* good old state hostname */
5318901bb69bf247e0f341312c800ba4ea87e46bAdrián Riesco int rwrite, rwrote; /* keep pointers in what we write - across
fe5611d78ea0648e8719cb004a6a26e9a033429aAdrián Riesco int length; /* Content-Length value used for keep-alive */
6b2e3d60f2e2c230c9637bf0701d7024d289764dAdrián Riesco char cbuff[CBUFFSIZE]; /* a buffer to store server response header */
51c15129e8118fed5c33c334f8df82619ce98e7dAdrián Riesco int keepalive; /* non-zero if a keep-alive request */
51c15129e8118fed5c33c334f8df82619ce98e7dAdrián Riesco int gotheader; /* non-zero if we have the entire header in
51c15129e8118fed5c33c334f8df82619ce98e7dAdrián Riesco /* XXXX insert SSL timings */
6d498b6f56ed9f71cced898b6c42fb48f6e60583Adrián Riesco apr_time_t starttime; /* start time of connection in seconds since
6d498b6f56ed9f71cced898b6c42fb48f6e60583Adrián Riesco * Jan. 1, 1970 */
51c15129e8118fed5c33c334f8df82619ce98e7dAdrián Riesco apr_interval_time_t waittime; /* Between writing request and reading
51c15129e8118fed5c33c334f8df82619ce98e7dAdrián Riesco * response */
51c15129e8118fed5c33c334f8df82619ce98e7dAdrián Riesco apr_interval_time_t ctime; /* time in ms to connect */
51c15129e8118fed5c33c334f8df82619ce98e7dAdrián Riesco apr_interval_time_t time; /* time in ms for connection */
6b2e3d60f2e2c230c9637bf0701d7024d289764dAdrián Riesco#define ap_min(a,b) ((a)<(b))?(a):(b)
6b2e3d60f2e2c230c9637bf0701d7024d289764dAdrián Riesco#define ap_max(a,b) ((a)>(b))?(a):(b)
6b2e3d60f2e2c230c9637bf0701d7024d289764dAdrián Riesco/* --------------------- GLOBALS ---------------------------- */
6b2e3d60f2e2c230c9637bf0701d7024d289764dAdrián Riescoint verbosity = 0; /* no verbosity by default */
6b2e3d60f2e2c230c9637bf0701d7024d289764dAdrián Riescoint requests = 1; /* Number of requests to make */
6b2e3d60f2e2c230c9637bf0701d7024d289764dAdrián Riescoint heartbeatres = 100; /* How often do we say we're alive */
6b2e3d60f2e2c230c9637bf0701d7024d289764dAdrián Riescoint concurrency = 1; /* Number of multiple requests to make */
6b2e3d60f2e2c230c9637bf0701d7024d289764dAdrián Riescoint percentile = 1; /* Show percentile served */
6b2e3d60f2e2c230c9637bf0701d7024d289764dAdrián Riescoint confidence = 1; /* Show confidence estimator and warnings */
6b2e3d60f2e2c230c9637bf0701d7024d289764dAdrián Riescoint keepalive = 0; /* try and do keepalive connections */
6b2e3d60f2e2c230c9637bf0701d7024d289764dAdrián Riescochar servername[1024]; /* name that server reports */
6b2e3d60f2e2c230c9637bf0701d7024d289764dAdrián Riescochar *host_field; /* value of "Host:" header field */
6b2e3d60f2e2c230c9637bf0701d7024d289764dAdrián Riescochar postfile[1024]; /* name of file containing post data */
6b2e3d60f2e2c230c9637bf0701d7024d289764dAdrián Riescochar *postdata; /* *buffer containing data from postfile */
6b2e3d60f2e2c230c9637bf0701d7024d289764dAdrián Riescoapr_size_t postlen = 0; /* length of data to be POSTed */
6b2e3d60f2e2c230c9637bf0701d7024d289764dAdrián Riescochar content_type[1024]; /* content type to put in POST header */
6b2e3d60f2e2c230c9637bf0701d7024d289764dAdrián Riesco * authentification */
6b2e3d60f2e2c230c9637bf0701d7024d289764dAdrián Riescoapr_time_t aprtimeout = 30 * APR_USEC_PER_SEC; /* timeout value */
6b2e3d60f2e2c230c9637bf0701d7024d289764dAdrián Riesco * XXX - this is now a per read/write transact type of value
223be434693e8c97e2522ac19155a284b3536035Adrián Riescoint doclen = 0; /* the length the document should be */
223be434693e8c97e2522ac19155a284b3536035Adrián Riescolong started = 0; /* number of requests started, so no excess */
223be434693e8c97e2522ac19155a284b3536035Adrián Riescolong totalread = 0; /* total number of bytes read */
c1cf2f634a37116ff90e99ca710179a23115cbfbAdrián Riescolong totalbread = 0; /* totoal amount of entity body read */
c1cf2f634a37116ff90e99ca710179a23115cbfbAdrián Riescolong totalposted = 0; /* total number of bytes posted, inc. headers */
c1cf2f634a37116ff90e99ca710179a23115cbfbAdrián Riescolong done = 0; /* number of requests we have done */
c1cf2f634a37116ff90e99ca710179a23115cbfbAdrián Riescolong doneka = 0; /* number of keep alive connections done */
0f35e410ce3d3202f6769e9d139ad26d1de69b8eAdrián Riescolong good = 0, bad = 0; /* number of good and bad requests */
c1cf2f634a37116ff90e99ca710179a23115cbfbAdrián Riescolong epipe = 0; /* number of broken pipe writes */
c1cf2f634a37116ff90e99ca710179a23115cbfbAdrián Riesco/* store error cases */
223be434693e8c97e2522ac19155a284b3536035Adrián Riescoint err_length = 0, err_conn = 0, err_except = 0;
c1cf2f634a37116ff90e99ca710179a23115cbfbAdrián Riesco/* global request (and its length) */
223be434693e8c97e2522ac19155a284b3536035Adrián Riesco/* one global throw-away buffer to read stuff into */
0be63c5d4b5e66cc600a0003081ae2bf85be9615Adrián Riesco/* interesting percentiles */
fe5611d78ea0648e8719cb004a6a26e9a033429aAdrián Riescoint percs[] = {50, 66, 75, 80, 90, 95, 98, 99, 100};
fe5611d78ea0648e8719cb004a6a26e9a033429aAdrián Riescostruct data *stats; /* date for each request */
fe5611d78ea0648e8719cb004a6a26e9a033429aAdrián Riescostatic void close_connection(struct connection * c);
fe5611d78ea0648e8719cb004a6a26e9a033429aAdrián Riesco/* --------------------------------------------------------- */
223be434693e8c97e2522ac19155a284b3536035Adrián Riesco/* simple little function to write an error string and exit */
c1cf2f634a37116ff90e99ca710179a23115cbfbAdrián Riescostatic void err(char *s)
b9840e4ee6fda6e42fa4ee9f337482ccc4839a39Adrián Riesco/* simple little function to write an APR error string and exit */
aea9000fc94442cbfc92596f4264473c0fce51e4Adrián Riesco "%s: %s (%d)\n",
27aad79faa0eec8d0e7dda32bca710db95bd2d0aAdrián Riesco/* --------------------------------------------------------- */
27aad79faa0eec8d0e7dda32bca710db95bd2d0aAdrián Riesco/* write out request to a connection - assumes we can write
7fc57d0f02d0fec1192376ccebe2be0224cb9a55Adrián Riesco * (small) request out in one go into our new socket buffer
aea9000fc94442cbfc92596f4264473c0fce51e4Adrián Riescostatic void write_request(struct connection * c)
c1cf2f634a37116ff90e99ca710179a23115cbfbAdrián Riesco * First time round ?
223be434693e8c97e2522ac19155a284b3536035Adrián Riesco if (c->rwrite == 0) {
aea9000fc94442cbfc92596f4264473c0fce51e4Adrián Riesco apr_setsocketopt(c->aprsock, APR_SO_TIMEOUT, 0);
aea9000fc94442cbfc92596f4264473c0fce51e4Adrián Riesco e = apr_send(c->aprsock, request + c->rwrote, &l);
27aad79faa0eec8d0e7dda32bca710db95bd2d0aAdrián Riesco * Bail early on the most common case
aea9000fc94442cbfc92596f4264473c0fce51e4Adrián Riesco * Let's hope this traps EWOULDBLOCK too !
aea9000fc94442cbfc92596f4264473c0fce51e4Adrián Riesco apr_poll_socket_add(readbits, c->aprsock, APR_POLLIN);
aea9000fc94442cbfc92596f4264473c0fce51e4Adrián Riesco/* --------------------------------------------------------- */
27aad79faa0eec8d0e7dda32bca710db95bd2d0aAdrián Riesco/* calculate and output results */
aea9000fc94442cbfc92596f4264473c0fce51e4Adrián Riescostatic int compradre(struct data * a, struct data * b)
aea9000fc94442cbfc92596f4264473c0fce51e4Adrián Riescostatic int comprando(struct data * a, struct data * b)
7fc57d0f02d0fec1192376ccebe2be0224cb9a55Adrián Riescostatic int compri(struct data * a, struct data * b)
aea9000fc94442cbfc92596f4264473c0fce51e4Adrián Riescostatic int compwait(struct data * a, struct data * b)
aea9000fc94442cbfc92596f4264473c0fce51e4Adrián Riescostatic void output_results(void)
51c15129e8118fed5c33c334f8df82619ce98e7dAdrián Riesco timetaken = (float) timetakenusec / APR_USEC_PER_SEC;
c1cf2f634a37116ff90e99ca710179a23115cbfbAdrián Riesco printf("Document Length: %d bytes\n", doclen);
c1cf2f634a37116ff90e99ca710179a23115cbfbAdrián Riesco printf("Concurrency Level: %d\n", concurrency);
fecce42517d20490f893c4a9dee29b000e1653eaAdrián Riesco printf("Time taken for tests: %" APR_TIME_T_FMT ".%03" APR_TIME_T_FMT " seconds\n",
71410be62420b321abb02ef1ac2b7f2141b3bc7fAdrián Riesco (apr_interval_time_t) timetakenusec / APR_USEC_PER_SEC,
71410be62420b321abb02ef1ac2b7f2141b3bc7fAdrián Riesco (apr_interval_time_t) timetakenusec % APR_USEC_PER_SEC);
71410be62420b321abb02ef1ac2b7f2141b3bc7fAdrián Riesco printf(" (Connect: %d, Length: %d, Exceptions: %d)\n",
fecce42517d20490f893c4a9dee29b000e1653eaAdrián Riesco printf("Non-2xx responses: %d\n", err_response);
fecce42517d20490f893c4a9dee29b000e1653eaAdrián Riesco printf("Total transferred: %ld bytes\n", totalread);
5318901bb69bf247e0f341312c800ba4ea87e46bAdrián Riesco printf("HTML transferred: %ld bytes\n", totalbread);
5318901bb69bf247e0f341312c800ba4ea87e46bAdrián Riesco /* avoid divide by zero */
51c15129e8118fed5c33c334f8df82619ce98e7dAdrián Riesco printf("Requests per second: %.2f [#/sec] (mean)\n", done / timetaken);
7474965b2e6323002c96c0b39a59843cde201870Adrián Riesco printf("Time per request: %.3f [ms] (mean)\n", concurrency * timetaken / done);
6d498b6f56ed9f71cced898b6c42fb48f6e60583Adrián Riesco printf("Time per request: %.3f [ms] (mean, across all concurrent requests)\n",
51c15129e8118fed5c33c334f8df82619ce98e7dAdrián Riesco printf("Transfer rate: %.2f [Kbytes/sec] received\n",
5318901bb69bf247e0f341312c800ba4ea87e46bAdrián Riesco (float) (totalread + totalposted) / timetaken / 1024);
172f4dfb4b858440fab545bac00d3ec4abd0cbe4Adrián Riesco /* work out connection times */
172f4dfb4b858440fab545bac00d3ec4abd0cbe4Adrián Riesco double totalcon = 0, total = 0, totald = 0, totalwait = 0;
fecce42517d20490f893c4a9dee29b000e1653eaAdrián Riesco apr_interval_time_t mincon = AB_MAX, mintot = AB_MAX, mind = AB_MAX,
5318901bb69bf247e0f341312c800ba4ea87e46bAdrián Riesco apr_interval_time_t maxcon = 0, maxtot = 0, maxd = 0, maxwait = 0;
5318901bb69bf247e0f341312c800ba4ea87e46bAdrián Riesco apr_interval_time_t meancon = 0, meantot = 0, meand = 0, meanwait = 0;
5318901bb69bf247e0f341312c800ba4ea87e46bAdrián Riesco double sdtot = 0, sdcon = 0, sdd = 0, sdwait = 0;
27aad79faa0eec8d0e7dda32bca710db95bd2d0aAdrián Riesco for (i = 0; i < requests; i++) {
5318901bb69bf247e0f341312c800ba4ea87e46bAdrián Riesco for (i = 0; i < requests; i++) {
5318901bb69bf247e0f341312c800ba4ea87e46bAdrián Riesco sdtot = (requests > 1) ? sqrt(sdtot / (requests - 1)) : 0;
5318901bb69bf247e0f341312c800ba4ea87e46bAdrián Riesco sdcon = (requests > 1) ? sqrt(sdcon / (requests - 1)) : 0;
5318901bb69bf247e0f341312c800ba4ea87e46bAdrián Riesco sdd = (requests > 1) ? sqrt(sdd / (requests - 1)) : 0;
5318901bb69bf247e0f341312c800ba4ea87e46bAdrián Riesco sdwait = (requests > 1) ? sqrt(sdwait / (requests - 1)) : 0;
0f35e410ce3d3202f6769e9d139ad26d1de69b8eAdrián Riesco fprintf(out, "starttime\tseconds\tctime\tdtime\tttime\twait\n");
5318901bb69bf247e0f341312c800ba4ea87e46bAdrián Riesco for (i = 0; i < requests; i++) {
5318901bb69bf247e0f341312c800ba4ea87e46bAdrián Riesco tmstring[strlen(tmstring) - 1] = '\0'; /* ctime returns a
5318901bb69bf247e0f341312c800ba4ea87e46bAdrián Riesco * string with a
5318901bb69bf247e0f341312c800ba4ea87e46bAdrián Riesco * trailing newline */
5318901bb69bf247e0f341312c800ba4ea87e46bAdrián Riesco fprintf(out, "%s\t%" APR_TIME_T_FMT "\t%" APR_TIME_T_FMT "\t%" APR_TIME_T_FMT "\t%" APR_TIME_T_FMT "\t%" APR_TIME_T_FMT "\n",
5318901bb69bf247e0f341312c800ba4ea87e46bAdrián Riesco * XXX: what is better; this hideous cast of the copare function; or
5318901bb69bf247e0f341312c800ba4ea87e46bAdrián Riesco * the four warnings during compile ? dirkx just does not know and
5318901bb69bf247e0f341312c800ba4ea87e46bAdrián Riesco * hates both/
c1cf2f634a37116ff90e99ca710179a23115cbfbAdrián Riesco (int (*) (const void *, const void *)) compradre);
6f6549c13f912de12345850e4eb248ec358c1b43Adrián Riesco meancon = (stats[requests / 2].ctime + stats[requests / 2 + 1].ctime) / 2;
5318901bb69bf247e0f341312c800ba4ea87e46bAdrián Riesco (int (*) (const void *, const void *)) compri);
5318901bb69bf247e0f341312c800ba4ea87e46bAdrián Riesco meand = (stats[requests / 2].time + stats[requests / 2 + 1].time \
5318901bb69bf247e0f341312c800ba4ea87e46bAdrián Riesco -stats[requests / 2].ctime - stats[requests / 2 + 1].ctime) / 2;
d72e314a1952b4418fb1c98b17dbab0d16bba585Adrián Riesco meand = stats[requests / 2].time - stats[requests / 2].ctime;
5318901bb69bf247e0f341312c800ba4ea87e46bAdrián Riesco (int (*) (const void *, const void *)) compwait);
5318901bb69bf247e0f341312c800ba4ea87e46bAdrián Riesco meanwait = (stats[requests / 2].waittime + stats[requests / 2 + 1].waittime) / 2;
5318901bb69bf247e0f341312c800ba4ea87e46bAdrián Riesco (int (*) (const void *, const void *)) comprando);
5318901bb69bf247e0f341312c800ba4ea87e46bAdrián Riesco meantot = (stats[requests / 2].time + stats[requests / 2 + 1].time) / 2;
5318901bb69bf247e0f341312c800ba4ea87e46bAdrián Riesco#define CONF_FMT_STRING "%" APR_TIME_T_FMT " %5d %6.1f %" APR_TIME_T_FMT " %" APR_TIME_T_FMT "\n"
5318901bb69bf247e0f341312c800ba4ea87e46bAdrián Riesco mincon, (int) (totalcon + 0.5), sdcon, meancon, maxcon);
5318901bb69bf247e0f341312c800ba4ea87e46bAdrián Riesco mind, (int) (totald + 0.5), sdd, meand, maxd);
5318901bb69bf247e0f341312c800ba4ea87e46bAdrián Riesco minwait, (int) (totalwait + 0.5), sdwait, meanwait, maxwait);
5318901bb69bf247e0f341312c800ba4ea87e46bAdrián Riesco mintot, (int) (total + 0.5), sdtot, meantot, maxtot);
0f77efdcc159eee5682aabf2b9a3c178c467b466Adrián Riesco if (d < 0) d = -d; \
0f77efdcc159eee5682aabf2b9a3c178c467b466Adrián Riesco printf("ERROR: The median and mean for " what " are more than twice the standard\n" \
0f77efdcc159eee5682aabf2b9a3c178c467b466Adrián Riesco " deviation apart. These results are NOT reliable.\n"); \
5318901bb69bf247e0f341312c800ba4ea87e46bAdrián Riesco else if (d > sd ) \
5318901bb69bf247e0f341312c800ba4ea87e46bAdrián Riesco printf("WARING: The median and mean for " what " are not within a normal deviation\n" \
5318901bb69bf247e0f341312c800ba4ea87e46bAdrián Riesco " These results are propably not that reliable.\n"); \
fecce42517d20490f893c4a9dee29b000e1653eaAdrián Riesco SANE("the initial connection time", totalcon, meancon, sdcon);
fecce42517d20490f893c4a9dee29b000e1653eaAdrián Riesco SANE("the processing time", totald, meand, sdd);
fecce42517d20490f893c4a9dee29b000e1653eaAdrián Riesco SANE("the waiting time", totalwait, meanwait, sdwait);
fecce42517d20490f893c4a9dee29b000e1653eaAdrián Riesco SANE("the total time", total, meantot, sdtot);
0f77efdcc159eee5682aabf2b9a3c178c467b466Adrián Riesco#define CONF_FMT_STRING "%5" APR_TIME_T_FMT " %5e %5" APR_TIME_T_FMT "\n"
0f77efdcc159eee5682aabf2b9a3c178c467b466Adrián Riesco printf("Connect: " CONF_FMT_STRING, mincon, totalcon / requests,
0f77efdcc159eee5682aabf2b9a3c178c467b466Adrián Riesco printf("Processing: " CONF_FMT_STRING, mintot - mincon,
0f77efdcc159eee5682aabf2b9a3c178c467b466Adrián Riesco (total / requests) - (totalcon / requests), maxtot - maxcon);
0f77efdcc159eee5682aabf2b9a3c178c467b466Adrián Riesco printf("Total: " CONF_FMT_STRING, mintot, total / requests,
0f77efdcc159eee5682aabf2b9a3c178c467b466Adrián Riesco /* Sorted on total connect times */
5318901bb69bf247e0f341312c800ba4ea87e46bAdrián Riesco printf("\nPercentage of the requests served within a certain time (ms)\n");
5318901bb69bf247e0f341312c800ba4ea87e46bAdrián Riesco for (i = 0; i < sizeof(percs) / sizeof(int); i++)
0f77efdcc159eee5682aabf2b9a3c178c467b466Adrián Riesco printf(" 100%% %5" APR_TIME_T_FMT " (longest request)\n",
5318901bb69bf247e0f341312c800ba4ea87e46bAdrián Riesco percs[i], stats[(int) (requests * percs[i] / 100)].time);
5318901bb69bf247e0f341312c800ba4ea87e46bAdrián Riesco fprintf(out, "" "Percentage served" "," "Time in ms" "\n");
5318901bb69bf247e0f341312c800ba4ea87e46bAdrián Riesco for (i = 0; i < 100; i++) {
5318901bb69bf247e0f341312c800ba4ea87e46bAdrián Riesco else if (i == 100)
5318901bb69bf247e0f341312c800ba4ea87e46bAdrián Riesco d = stats[(int) (0.5 + requests * i / 100.0)].time;
5318901bb69bf247e0f341312c800ba4ea87e46bAdrián Riesco/* --------------------------------------------------------- */
5318901bb69bf247e0f341312c800ba4ea87e46bAdrián Riesco/* calculate and output results in HTML */
5318901bb69bf247e0f341312c800ba4ea87e46bAdrián Riescostatic void output_html_results(void)
5318901bb69bf247e0f341312c800ba4ea87e46bAdrián Riesco printf("<tr %s><th colspan=2 %s>Server Software:</th>"
5318901bb69bf247e0f341312c800ba4ea87e46bAdrián Riesco "<td colspan=2 %s>%s</td></tr>\n",
fecce42517d20490f893c4a9dee29b000e1653eaAdrián Riesco printf("<tr %s><th colspan=2 %s>Server Hostname:</th>"
fecce42517d20490f893c4a9dee29b000e1653eaAdrián Riesco "<td colspan=2 %s>%s</td></tr>\n",
fecce42517d20490f893c4a9dee29b000e1653eaAdrián Riesco printf("<tr %s><th colspan=2 %s>Server Port:</th>"
fecce42517d20490f893c4a9dee29b000e1653eaAdrián Riesco "<td colspan=2 %s>%hd</td></tr>\n",
fecce42517d20490f893c4a9dee29b000e1653eaAdrián Riesco printf("<tr %s><th colspan=2 %s>Document Path:</th>"
5318901bb69bf247e0f341312c800ba4ea87e46bAdrián Riesco "<td colspan=2 %s>%s</td></tr>\n",
5318901bb69bf247e0f341312c800ba4ea87e46bAdrián Riesco printf("<tr %s><th colspan=2 %s>Document Length:</th>"
5318901bb69bf247e0f341312c800ba4ea87e46bAdrián Riesco "<td colspan=2 %s>%d bytes</td></tr>\n",
5318901bb69bf247e0f341312c800ba4ea87e46bAdrián Riesco printf("<tr %s><th colspan=2 %s>Concurrency Level:</th>"
5318901bb69bf247e0f341312c800ba4ea87e46bAdrián Riesco "<td colspan=2 %s>%d</td></tr>\n",
0f77efdcc159eee5682aabf2b9a3c178c467b466Adrián Riesco printf("<tr %s><th colspan=2 %s>Time taken for tests:</th>"
0f77efdcc159eee5682aabf2b9a3c178c467b466Adrián Riesco "<td colspan=2 %s>%qd.%03qd seconds</td></tr>\n",
0f77efdcc159eee5682aabf2b9a3c178c467b466Adrián Riesco trstring, tdstring, tdstring, timetaken / APR_USEC_PER_SEC, timetaken % APR_USEC_PER_SEC);
0f77efdcc159eee5682aabf2b9a3c178c467b466Adrián Riesco printf("<tr %s><th colspan=2 %s>Complete requests:</th>"
0f77efdcc159eee5682aabf2b9a3c178c467b466Adrián Riesco "<td colspan=2 %s>%ld</td></tr>\n",
5318901bb69bf247e0f341312c800ba4ea87e46bAdrián Riesco printf("<tr %s><th colspan=2 %s>Failed requests:</th>"
5318901bb69bf247e0f341312c800ba4ea87e46bAdrián Riesco "<td colspan=2 %s>%ld</td></tr>\n",
27aad79faa0eec8d0e7dda32bca710db95bd2d0aAdrián Riesco printf("<tr %s><td colspan=4 %s > (Connect: %d, Length: %d, Exceptions: %d)</td></tr>\n",
51c15129e8118fed5c33c334f8df82619ce98e7dAdrián Riesco trstring, tdstring, err_conn, err_length, err_except);
5318901bb69bf247e0f341312c800ba4ea87e46bAdrián Riesco printf("<tr %s><th colspan=2 %s>Non-2xx responses:</th>"
27aad79faa0eec8d0e7dda32bca710db95bd2d0aAdrián Riesco "<td colspan=2 %s>%d</td></tr>\n",
5318901bb69bf247e0f341312c800ba4ea87e46bAdrián Riesco printf("<tr %s><th colspan=2 %s>Keep-Alive requests:</th>"
5318901bb69bf247e0f341312c800ba4ea87e46bAdrián Riesco "<td colspan=2 %s>%ld</td></tr>\n",
5318901bb69bf247e0f341312c800ba4ea87e46bAdrián Riesco printf("<tr %s><th colspan=2 %s>Total transferred:</th>"
51c15129e8118fed5c33c334f8df82619ce98e7dAdrián Riesco "<td colspan=2 %s>%ld bytes</td></tr>\n",
27aad79faa0eec8d0e7dda32bca710db95bd2d0aAdrián Riesco printf("<tr %s><th colspan=2 %s>Total POSTed:</th>"
27aad79faa0eec8d0e7dda32bca710db95bd2d0aAdrián Riesco "<td colspan=2 %s>%ld</td></tr>\n",
5318901bb69bf247e0f341312c800ba4ea87e46bAdrián Riesco printf("<tr %s><th colspan=2 %s>HTML transferred:</th>"
5318901bb69bf247e0f341312c800ba4ea87e46bAdrián Riesco "<td colspan=2 %s>%ld bytes</td></tr>\n",
7474965b2e6323002c96c0b39a59843cde201870Adrián Riesco /* avoid divide by zero */
27aad79faa0eec8d0e7dda32bca710db95bd2d0aAdrián Riesco printf("<tr %s><th colspan=2 %s>Requests per second:</th>"
27aad79faa0eec8d0e7dda32bca710db95bd2d0aAdrián Riesco "<td colspan=2 %s>%.2f</td></tr>\n",
5318901bb69bf247e0f341312c800ba4ea87e46bAdrián Riesco trstring, tdstring, tdstring, 1000 * (float) (done) / timetaken);
5318901bb69bf247e0f341312c800ba4ea87e46bAdrián Riesco printf("<tr %s><th colspan=2 %s>Transfer rate:</th>"
5318901bb69bf247e0f341312c800ba4ea87e46bAdrián Riesco "<td colspan=2 %s>%.2f kb/s received</td></tr>\n",
5318901bb69bf247e0f341312c800ba4ea87e46bAdrián Riesco trstring, tdstring, tdstring, (float) (totalread) / timetaken);
5318901bb69bf247e0f341312c800ba4ea87e46bAdrián Riesco "<td colspan=2 %s>%.2f kb/s sent</td></tr>\n",
5318901bb69bf247e0f341312c800ba4ea87e46bAdrián Riesco "<td colspan=2 %s>%.2f kb/s total</td></tr>\n",
5318901bb69bf247e0f341312c800ba4ea87e46bAdrián Riesco (float) (totalread + totalposted) / timetaken);
5318901bb69bf247e0f341312c800ba4ea87e46bAdrián Riesco /* work out connection times */
6f6549c13f912de12345850e4eb248ec358c1b43Adrián Riesco apr_interval_time_t mincon = AB_MAX, mintot = AB_MAX;
5318901bb69bf247e0f341312c800ba4ea87e46bAdrián Riesco for (i = 0; i < requests; i++) {
51c15129e8118fed5c33c334f8df82619ce98e7dAdrián Riesco if (requests > 0) { /* avoid division by zero (if 0 requests) */
51c15129e8118fed5c33c334f8df82619ce98e7dAdrián Riesco printf("<tr %s><th %s colspan=4>Connnection Times (ms)</th></tr>\n",
5318901bb69bf247e0f341312c800ba4ea87e46bAdrián Riesco printf("<tr %s><th %s> </th> <th %s>min</th> <th %s>avg</th> <th %s>max</th></tr>\n",
51c15129e8118fed5c33c334f8df82619ce98e7dAdrián Riesco trstring, tdstring, tdstring, tdstring, tdstring);
5318901bb69bf247e0f341312c800ba4ea87e46bAdrián Riesco trstring, tdstring, tdstring, mincon, tdstring, totalcon / requests, tdstring, maxcon);
27aad79faa0eec8d0e7dda32bca710db95bd2d0aAdrián Riesco trstring, tdstring, tdstring, mintot - mincon, tdstring,
51c15129e8118fed5c33c334f8df82619ce98e7dAdrián Riesco (total / requests) - (totalcon / requests), tdstring, maxtot - maxcon);
51c15129e8118fed5c33c334f8df82619ce98e7dAdrián Riesco trstring, tdstring, tdstring, mintot, tdstring, total / requests, tdstring, maxtot);
51c15129e8118fed5c33c334f8df82619ce98e7dAdrián Riesco/* --------------------------------------------------------- */
6e121321775373fe11161d23c541437456df19b4Adrián Riesco/* start asnchronous non-blocking connection */
27aad79faa0eec8d0e7dda32bca710db95bd2d0aAdrián Riescostatic void start_connect(struct connection * c)
aea9000fc94442cbfc92596f4264473c0fce51e4Adrián Riesco if ((rv = apr_sockaddr_info_get(&destsa, connecthost, APR_UNSPEC, connectport, 0, cntxt))
aea9000fc94442cbfc92596f4264473c0fce51e4Adrián Riesco "apr_sockaddr_info_get() for %s", connecthost);
aea9000fc94442cbfc92596f4264473c0fce51e4Adrián Riesco if ((rv = apr_socket_create(&c->aprsock, destsa->sa.sin.sin_family,
aea9000fc94442cbfc92596f4264473c0fce51e4Adrián Riesco if ((rv = apr_connect(c->aprsock, destsa)) != APR_SUCCESS) {
aea9000fc94442cbfc92596f4264473c0fce51e4Adrián Riesco apr_poll_socket_add(readbits, c->aprsock, APR_POLLOUT);
aea9000fc94442cbfc92596f4264473c0fce51e4Adrián Riesco "\nTest aborted after 10 failures\n\n");
d72e314a1952b4418fb1c98b17dbab0d16bba585Adrián Riesco /* connected first time */
d72e314a1952b4418fb1c98b17dbab0d16bba585Adrián Riesco/* --------------------------------------------------------- */
d72e314a1952b4418fb1c98b17dbab0d16bba585Adrián Riesco/* close down connection and save stats */
d72e314a1952b4418fb1c98b17dbab0d16bba585Adrián Riescostatic void close_connection(struct connection * c)
27aad79faa0eec8d0e7dda32bca710db95bd2d0aAdrián Riesco * server has legitimately shut down an idle keep alive request
d72e314a1952b4418fb1c98b17dbab0d16bba585Adrián Riesco /* first time here */
d72e314a1952b4418fb1c98b17dbab0d16bba585Adrián Riesco /* save out time */
d72e314a1952b4418fb1c98b17dbab0d16bba585Adrián Riesco if ((done) && heartbeatres && !(done % heartbeatres)) {
5318901bb69bf247e0f341312c800ba4ea87e46bAdrián Riesco fprintf(stderr, "Completed %ld requests\n", done);
5318901bb69bf247e0f341312c800ba4ea87e46bAdrián Riesco s.waittime = (c->beginread - c->endwrite) / 1000;
d72e314a1952b4418fb1c98b17dbab0d16bba585Adrián Riesco /* connect again */
b9840e4ee6fda6e42fa4ee9f337482ccc4839a39Adrián Riesco/* --------------------------------------------------------- */
5318901bb69bf247e0f341312c800ba4ea87e46bAdrián Riesco/* read data from connection */
5318901bb69bf247e0f341312c800ba4ea87e46bAdrián Riescostatic void read_connection(struct connection * c)
5318901bb69bf247e0f341312c800ba4ea87e46bAdrián Riesco apr_setsocketopt(c->aprsock, APR_SO_TIMEOUT, aprtimeout);
7fc57d0f02d0fec1192376ccebe2be0224cb9a55Adrián Riesco if (r == 0 || (status != APR_SUCCESS && !APR_STATUS_IS_EAGAIN(status))) {
5318901bb69bf247e0f341312c800ba4ea87e46bAdrián Riesco if (c->read == 0) {
5318901bb69bf247e0f341312c800ba4ea87e46bAdrián Riesco int space = CBUFFSIZE - c->cbx - 1; /* -1 to allow for 0
5318901bb69bf247e0f341312c800ba4ea87e46bAdrián Riesco * terminator */
5318901bb69bf247e0f341312c800ba4ea87e46bAdrián Riesco apr_size_t inbytes_left = space, outbytes_left = space;
0f35e410ce3d3202f6769e9d139ad26d1de69b8eAdrián Riesco status = apr_xlate_conv_buffer(from_ascii, buffer, &inbytes_left,
5318901bb69bf247e0f341312c800ba4ea87e46bAdrián Riesco if (status || inbytes_left || outbytes_left) {
5318901bb69bf247e0f341312c800ba4ea87e46bAdrián Riesco fprintf(stderr, "only simple translation is supported (%d/%u/%u)\n",
5318901bb69bf247e0f341312c800ba4ea87e46bAdrián Riesco#endif /* NOT_ASCII */
c1cf2f634a37116ff90e99ca710179a23115cbfbAdrián Riesco c->cbuff[c->cbx] = 0; /* terminate for benefit of strstr */
5318901bb69bf247e0f341312c800ba4ea87e46bAdrián Riesco printf("LOG: header received:\n%s\n", c->cbuff);
5318901bb69bf247e0f341312c800ba4ea87e46bAdrián Riesco * this next line is so that we talk to NCSA 1.5 which blatantly
5318901bb69bf247e0f341312c800ba4ea87e46bAdrián Riesco * breaks the http specifaction
5318901bb69bf247e0f341312c800ba4ea87e46bAdrián Riesco /* read rest next time */
5318901bb69bf247e0f341312c800ba4ea87e46bAdrián Riesco /* header is in invalid or too big - close connection */
5318901bb69bf247e0f341312c800ba4ea87e46bAdrián Riesco /* have full header */
5318901bb69bf247e0f341312c800ba4ea87e46bAdrián Riesco * this is first time, extract some interesting info
5318901bb69bf247e0f341312c800ba4ea87e46bAdrián Riesco while (*p > 32)
5318901bb69bf247e0f341312c800ba4ea87e46bAdrián Riesco * XXX: this parsing isn't even remotely HTTP compliant... but in
5318901bb69bf247e0f341312c800ba4ea87e46bAdrián Riesco * the interest of speed it doesn't totally have to be, it just
5318901bb69bf247e0f341312c800ba4ea87e46bAdrián Riesco * needs to be extended to handle whatever servers folks want to
5318901bb69bf247e0f341312c800ba4ea87e46bAdrián Riesco * test against. -djg
5318901bb69bf247e0f341312c800ba4ea87e46bAdrián Riesco /* check response code */
5318901bb69bf247e0f341312c800ba4ea87e46bAdrián Riesco part = strstr(c->cbuff, "HTTP"); /* really HTTP/1.x_ */
5318901bb69bf247e0f341312c800ba4ea87e46bAdrián Riesco strncpy(respcode, (part + strlen("HTTP/1.x_")), 3);
5318901bb69bf247e0f341312c800ba4ea87e46bAdrián Riesco printf("WARNING: Response code not 2xx (%s)\n", respcode);
5318901bb69bf247e0f341312c800ba4ea87e46bAdrián Riesco printf("LOG: Response code = %s\n", respcode);
aea9000fc94442cbfc92596f4264473c0fce51e4Adrián Riesco *s = 0; /* terminate at end of header */
fecce42517d20490f893c4a9dee29b000e1653eaAdrián Riesco || strstr(c->cbuff, "keep-alive"))) { /* for benefit of MSIIS */
fecce42517d20490f893c4a9dee29b000e1653eaAdrián Riesco /* handle NCSA, which sends Content-length: */
fecce42517d20490f893c4a9dee29b000e1653eaAdrián Riesco c->bread += c->cbx - (s + l - c->cbuff) + r - tocopy;
fecce42517d20490f893c4a9dee29b000e1653eaAdrián Riesco /* outside header, everything we have read is entity body */
b9840e4ee6fda6e42fa4ee9f337482ccc4839a39Adrián Riesco if (c->keepalive && (c->bread >= c->length)) {
b9840e4ee6fda6e42fa4ee9f337482ccc4839a39Adrián Riesco /* finished a keep-alive connection */
b9840e4ee6fda6e42fa4ee9f337482ccc4839a39Adrián Riesco /* save out time */
b9840e4ee6fda6e42fa4ee9f337482ccc4839a39Adrián Riesco /* first time here */
b9840e4ee6fda6e42fa4ee9f337482ccc4839a39Adrián Riesco if (done && heartbeatres && !(done % heartbeatres)) {
b9840e4ee6fda6e42fa4ee9f337482ccc4839a39Adrián Riesco fprintf(stderr, "Completed %ld requests\n", done);
223be434693e8c97e2522ac19155a284b3536035Adrián Riesco s.waittime = (c->beginread - c->endwrite) / 1000;
b9840e4ee6fda6e42fa4ee9f337482ccc4839a39Adrián Riesco c->start = c->connect; /* zero connect time with keep-alive */
b9840e4ee6fda6e42fa4ee9f337482ccc4839a39Adrián Riesco/* --------------------------------------------------------- */
b9840e4ee6fda6e42fa4ee9f337482ccc4839a39Adrián Riesco/* run the tests */
b9840e4ee6fda6e42fa4ee9f337482ccc4839a39Adrián Riescostatic void test(void)
c6a4f949f2a9da476c80399fb061020937255f87Adrián Riesco printf("[through %s:%d] ", proxyhost, proxyport);
c6a4f949f2a9da476c80399fb061020937255f87Adrián Riesco con = malloc(concurrency * sizeof(struct connection));
c6a4f949f2a9da476c80399fb061020937255f87Adrián Riesco memset(con, 0, concurrency * sizeof(struct connection));
c6a4f949f2a9da476c80399fb061020937255f87Adrián Riesco stats = malloc(requests * sizeof(struct data));
c6a4f949f2a9da476c80399fb061020937255f87Adrián Riesco apr_poll_setup(&readbits, concurrency, cntxt);
c6a4f949f2a9da476c80399fb061020937255f87Adrián Riesco /* setup request */
c6a4f949f2a9da476c80399fb061020937255f87Adrián Riesco "User-Agent: ApacheBench/%s\r\n"
c6a4f949f2a9da476c80399fb061020937255f87Adrián Riesco "%s" "%s" "%s"
c6a4f949f2a9da476c80399fb061020937255f87Adrián Riesco "Host: %s\r\n"
c6a4f949f2a9da476c80399fb061020937255f87Adrián Riesco "Accept: */*\r\n"
c6a4f949f2a9da476c80399fb061020937255f87Adrián Riesco keepalive ? "Connection: Keep-Alive\r\n" : "",
c6a4f949f2a9da476c80399fb061020937255f87Adrián Riesco "User-Agent: ApacheBench/%s\r\n"
c6a4f949f2a9da476c80399fb061020937255f87Adrián Riesco "%s" "%s" "%s"
c6a4f949f2a9da476c80399fb061020937255f87Adrián Riesco "Host: %s\r\n"
c6a4f949f2a9da476c80399fb061020937255f87Adrián Riesco "Accept: */*\r\n"
c6a4f949f2a9da476c80399fb061020937255f87Adrián Riesco "Content-type: %s\r\n"
0f35e410ce3d3202f6769e9d139ad26d1de69b8eAdrián Riesco keepalive ? "Connection: Keep-Alive\r\n" : "",
0f35e410ce3d3202f6769e9d139ad26d1de69b8eAdrián Riesco (content_type[0]) ? content_type : "text/plain", hdrs);
0f35e410ce3d3202f6769e9d139ad26d1de69b8eAdrián Riesco printf("INFO: POST header == \n---\n%s\n---\n", request);
0f35e410ce3d3202f6769e9d139ad26d1de69b8eAdrián Riesco * Combine headers and (optional) post file into one contineous buffer
0f35e410ce3d3202f6769e9d139ad26d1de69b8eAdrián Riesco char *buff = (char *) malloc(postlen + reqlen + 1);
0f35e410ce3d3202f6769e9d139ad26d1de69b8eAdrián Riesco status = apr_xlate_conv_buffer(to_ascii, request, &inbytes_left,
0f35e410ce3d3202f6769e9d139ad26d1de69b8eAdrián Riesco if (status || inbytes_left || outbytes_left) {
0f35e410ce3d3202f6769e9d139ad26d1de69b8eAdrián Riesco fprintf(stderr, "only simple translation is supported (%d/%u/%u)\n",
0f35e410ce3d3202f6769e9d139ad26d1de69b8eAdrián Riesco#endif /* NOT_ASCII */
0f35e410ce3d3202f6769e9d139ad26d1de69b8eAdrián Riesco /* ok - lets start */
0f35e410ce3d3202f6769e9d139ad26d1de69b8eAdrián Riesco /* initialise lots of requests */
0f35e410ce3d3202f6769e9d139ad26d1de69b8eAdrián Riesco for (i = 0; i < concurrency; i++) {
0f35e410ce3d3202f6769e9d139ad26d1de69b8eAdrián Riesco /* check for time limit expiry */
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.72 $");
#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;
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();