/* Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License.
*/
/* ** This program is based on ZeusBench V1.0 written by Adam Twiss ** which is Copyright (c) 1996 by Zeus Technology Ltd. http://www.zeustech.net/ ** ** This software is provided "as is" and any express or implied warranties, ** including but not limited to, the implied warranties of merchantability and ** fitness for a particular purpose are disclaimed. In no event shall ** Zeus Technology Ltd. be liable for any direct, indirect, incidental, special, ** exemplary, or consequential damaged (including, but not limited to, ** procurement of substitute good or services; loss of use, data, or profits; ** or business interruption) however caused and on theory of liability. Whether ** in contract, strict liability or tort (including negligence or otherwise) ** arising in any way out of the use of this software, even if advised of the ** possibility of such damage. **
*/
/* ** HISTORY: ** - Originally written by Adam Twiss <adam@zeus.co.uk>, March 1996 ** with input from Mike Belshe <mbelshe@netscape.com> and ** Michael Campanella <campanella@stevms.enet.dec.com> ** - Enhanced by Dean Gaudet <dgaudet@apache.org>, November 1997 ** - Cleaned up by Ralf S. Engelschall <rse@apache.org>, March 1998 ** - POST and verbosity by Kurt Sussman <kls@merlot.com>, August 1998 ** - HTML table output added by David N. Welton <davidw@prosa.it>, January 1999 ** - Added Cookie, Arbitrary header and auth support. <dirkx@webweaving.org>, April 1999 ** Version 1.3d ** - Increased version number - as some of the socket/error handling has ** fundamentally changed - and will give fundamentally different results ** in situations where a server is dropping requests. Therefore you can ** no longer compare results of AB as easily. Hence the inc of the version. ** They should be closer to the truth though. Sander & <dirkx@covalent.net>, End 2000. ** - Fixed proxy functionality, added median/mean statistics, added gnuplot ** output option, added _experimental/rudimentary_ SSL support. Added ** confidence guestimators and warnings. Sander & <dirkx@covalent.net>, End 2000 ** - Fixed serious int overflow issues which would cause realistic (longer ** than a few minutes) run's to have wrong (but believable) results. Added ** trapping of connection errors which influenced measurements. ** Contributed by Sander Temme, Early 2001 ** Version 1.3e ** - Changed timeout behavior during write to work whilst the sockets ** are filling up and apr_write() does writes a few - but not all. ** This will potentially change results. <dirkx@webweaving.org>, April 2001 ** Version 2.0.36-dev ** Improvements to concurrent processing: ** - Enabled non-blocking connect()s. ** - Prevent blocking calls to apr_socket_recv() (thereby allowing AB to ** manage its entire set of socket descriptors). ** - Any error returned from apr_socket_recv() that is not EAGAIN or EOF ** is now treated as fatal. ** Contributed by Aaron Bannert, April 24, 2002 ** ** Version 2.0.36-2 ** Internalized the version string - this string is part ** of the Agent: header and the result output. ** ** Version 2.0.37-dev ** Adopted SSL code by Madhu Mathihalli <madhusudan_mathihalli@hp.com> ** [PATCH] ab with SSL support Posted Wed, 15 Aug 2001 20:55:06 GMT ** Introduces four 'if (int == value)' tests per non-ssl request. ** ** Version 2.0.40-dev ** Switched to the new abstract pollset API, allowing ab to ** take advantage of future apr_pollset_t scalability improvements. ** Contributed by Brian Pane, August 31, 2002 ** ** Version 2.3 ** SIGINT now triggers output_results(). ** Contributed by colm, March 30, 2006
**/
/* Note: this version string should start with \d+[\d\.]* and be a valid * string for an HTTP Agent: header when prefixed with 'ApacheBench/'. * It should reflect the version of AB - and not that of the apache server * it happens to accompany. And it should be updated or changed whenever * the results are no longer fundamentally comparable to the results of * a previous version of ab. Either due to a change in the logic of * ab - or to due to a change in the distribution it is compiled with * (such as an APR change in for example blocking).
*/ #define AP_AB_BASEREVISION "2.3"
/* * BUGS: * * - uses strcpy/etc. * - has various other poor buffer attacks related to the lazy parsing of * response headers from the server * - doesn't implement much of HTTP/1.x, only accepts certain forms of * responses * - (performance problem) heavy use of strstr shows up top in profile * only an issue for loopback usage
*/
#if'A' != 0x41 /* Hmmm... This source code isn't being compiled in ASCII. * In order for data that flows over the network to make * sense, we need to translate to/from ASCII.
*/ #define NOT_ASCII #endif
/* affects include files on Solaris */ #define BSD_COMP
#ifdefined(_MSC_VER) && !defined(LIBRESSL_VERSION_NUMBER) /* The following logic ensures we correctly glue FILE* within one CRT used * by the OpenSSL library build to another CRT used by the ab.exe build. * This became especially problematic with Visual Studio 2015.
*/ #include <openssl/applink.c> #endif
/* maximum number of requests on a time limited test */ #define MAX_REQUESTS (INT_MAX > 50000 ? 50000 : INT_MAX)
/* connection state * don't add enums or rearrange or otherwise change values without * visiting set_conn_state()
*/ typedefenum {
STATE_UNCONNECTED = 0,
STATE_CONNECTING, /* TCP connect initiated, but we don't * know if it worked yet
*/
STATE_CONNECTED, /* we know TCP connect completed */
STATE_READ
} connect_state_e;
#define CBUFFSIZE (8192)
struct connection {
apr_pool_t *ctx;
apr_socket_t *aprsock;
apr_pollfd_t pollfd; int state;
apr_size_t read; /* amount of bytes read */
apr_size_t bread; /* amount of body read */
apr_size_t rwrite, rwrote; /* keep pointers in what we write - across
* EAGAINs */
apr_size_t length; /* Content-Length value used for keep-alive */ char cbuff[CBUFFSIZE]; /* a buffer to store server response header */ int cbx; /* offset in cbuffer */ int keepalive; /* non-zero if a keep-alive request */ int gotheader; /* non-zero if we have the entire header in
* cbuff */
apr_time_t start, /* Start of connection */
connect, /* Connected, start writing */
endwrite, /* Request written */
beginread, /* First byte of input */
done; /* Connection closed */
int socknum; #ifdef USE_SSL
SSL *ssl; #endif
};
struct data {
apr_time_t starttime; /* start time of connection */
apr_interval_time_t waittime; /* between request and reading response */
apr_interval_time_t ctime; /* time to connect */
apr_interval_time_t time; /* time for connection */
};
int verbosity = 0; /* no verbosity by default */ int recverrok = 0; /* ok to proceed after socket receive errors */ enum {NO_METH = 0, GET, HEAD, PUT, POST, CUSTOM_METHOD} method = NO_METH; constchar *method_str[] = {"bug", "GET", "HEAD", "PUT", "POST", ""}; int send_body = 0; /* non-zero if sending body with request */ int requests = 1; /* Number of requests to make */ int heartbeatres = 100; /* How often do we say we're alive */ int concurrency = 1; /* Number of multiple requests to make */ int percentile = 1; /* Show percentile served */ int nolength = 0; /* Accept variable document length */ int confidence = 1; /* Show confidence estimator and warnings */ int tlimit = 0; /* time limit in secs */ int keepalive = 0; /* try and do keepalive connections */ int windowsize = 0; /* we use the OS default window size */ char servername[1024]; /* name that server reports */ char *hostname; /* host name from URL */ constchar *host_field; /* value of "Host:" header field */ constchar *path; /* path name */ char *postdata; /* *buffer containing data from postfile */
apr_size_t postlen = 0; /* length of data to be POSTed */ char *content_type = NULL; /* content type to put in POST header */ constchar *cookie, /* optional cookie line */
*auth, /* optional (basic/uuencoded) auhentication */
*hdrs; /* optional arbitrary headers */
apr_port_t port; /* port number */ char *proxyhost = NULL; /* proxy host name */ int proxyport = 0; /* proxy port */ constchar *connecthost; constchar *myhost;
apr_port_t connectport; constchar *gnuplot; /* GNUplot file */ constchar *csvperc; /* CSV Percentile file */ constchar *fullurl; constchar *colonhost; int isproxy = 0;
apr_interval_time_t aprtimeout = apr_time_from_sec(30); /* timeout value */
/* overrides for ab-generated common headers */ constchar *opt_host; /* which optional "Host:" header specified, if any */ int opt_useragent = 0; /* was an optional "User-Agent:" header specified? */ int opt_accept = 0; /* was an optional "Accept:" header specified? */ /* * XXX - this is now a per read/write transact type of value
*/
int use_html = 0; /* use html in the report */ constchar *tablestring; constchar *trstring; constchar *tdstring;
apr_size_t doclen = 0; /* the length the document should be */
apr_int64_t totalread = 0; /* total number of bytes read */
apr_int64_t totalbread = 0; /* totoal amount of entity body read */
apr_int64_t totalposted = 0; /* total number of bytes posted, inc. headers */ int started = 0; /* number of requests started, so no excess */ int done = 0; /* number of requests we have done */ int doneka = 0; /* number of keep alive connections done */ int good = 0, bad = 0; /* number of good and bad requests */ int epipe = 0; /* number of broken pipe writes */ int err_length = 0; /* requests failed due to response length */ int err_conn = 0; /* requests failed due to connection drop */ int err_recv = 0; /* requests failed due to broken read */ int err_except = 0; /* requests failed due to exception */ int err_response = 0; /* requests with invalid or non-200 response */
#ifdef USE_SSL int is_ssl;
SSL_CTX *ssl_ctx; char *ssl_cipher = NULL; char *ssl_info = NULL; char *ssl_cert = NULL; #if OPENSSL_VERSION_NUMBER >= 0x10002000L char *ssl_tmp_key = NULL; #endif
BIO *bio_out,*bio_err; #ifdef HAVE_TLSEXT int tls_use_sni = 1; /* used by default, -I disables it */ constchar *tls_sni = NULL; /* 'opt_host' if any, 'hostname' otherwise */ #endif #endif
apr_time_t start, lasttime, stoptime;
/* global request (and its length) */ char _request[8192]; char *request = _request;
apr_size_t reqlen; int requests_initialized = 0;
/* one global throw-away buffer to read stuff into */ char buffer[8192];
/* * Similar to standard strstr() but we ignore case in this version. * Copied from ap_strcasestr().
*/ staticchar *xstrcasestr(constchar *s1, constchar *s2)
{ char *p1, *p2; if (*s2 == '\0') { /* an empty s2 */ return((char *)s1);
} while(1) { for ( ; (*s1 != '\0') && (apr_tolower(*s1) != apr_tolower(*s2)); s1++); if (*s1 == '\0') { return(NULL);
} /* found first character of s2, see if the rest matches */
p1 = (char *)s1;
p2 = (char *)s2; for (++p1, ++p2; apr_tolower(*p1) == apr_tolower(*p2); ++p1, ++p2) { if (*p1 == '\0') { /* both strings ended together */ return((char *)s1);
}
} if (*p2 == '\0') { /* second string ended, a match */ break;
} /* didn't find a match here, try starting at next character in s1 */
s1++;
} return((char *)s1);
}
/* pool abort function */ staticint abort_on_oom(int retcode)
{
fprintf(stderr, "Could not allocate memory\n"); exit(1); /* not reached */ return retcode;
}
staticvoid set_conn_state(struct connection *c, connect_state_e new_state)
{
apr_int16_t events_by_state[] = {
0, /* for STATE_UNCONNECTED */
APR_POLLOUT, /* for STATE_CONNECTING */
APR_POLLIN, /* for STATE_CONNECTED; we don't poll in this state, * so prepare for polling in the following state -- * STATE_READ
*/
APR_POLLIN /* for STATE_READ */
};
/* --------------------------------------------------------- */ /* write out request to a connection - assumes we can write * (small) request out in one go into our new socket buffer *
*/ #ifdef USE_SSL #if OPENSSL_VERSION_NUMBER >= 0x30000000L staticlong ssl_print_cb(BIO *bio, int cmd, constchar *argp,
size_t len, int argi, long argl, int ret,
size_t *processed) #else staticlong ssl_print_cb(BIO *bio, int cmd, constchar *argp, int argi, long argl, long ret) #endif
{
BIO *out; #if OPENSSL_VERSION_NUMBER >= 0x30000000L
(void)len;
(void)processed; #endif
out=(BIO *)BIO_get_callback_arg(bio); if (out == NULL) return(ret);
staticvoid ssl_state_cb(const SSL *s, int w, int r)
{ if (w & SSL_CB_ALERT) {
BIO_printf(bio_err, "SSL/TLS Alert [%s] %s:%s\n",
(w & SSL_CB_READ ? "read" : "write"),
SSL_alert_type_string_long(r),
SSL_alert_desc_string_long(r));
} elseif (w & SSL_CB_LOOP) {
BIO_printf(bio_err, "SSL/TLS State [%s] %s\n",
(SSL_in_connect_init((SSL*)s) ? "connect" : "-"),
SSL_state_string_long(s));
} elseif (w & (SSL_CB_HANDSHAKE_START|SSL_CB_HANDSHAKE_DONE)) {
BIO_printf(bio_err, "SSL/TLS Handshake [%s] %s\n",
(w & SSL_CB_HANDSHAKE_START ? "Start" : "Done"),
SSL_state_string_long(s));
}
}
#ifndef RAND_MAX #define RAND_MAX INT_MAX #endif
staticint ssl_rand_choosenum(int l, int h)
{ int i; char buf[50];
srand((unsignedint)time(NULL));
apr_snprintf(buf, sizeof(buf), "%.0f",
(((double)(rand()%RAND_MAX)/RAND_MAX)*(h-l)));
i = atoi(buf)+1; if (i < l) i = l; if (i > h) i = h; return i;
}
staticvoid ssl_rand_seed(void)
{ int n, l;
time_t t;
pid_t pid; unsignedchar stackdata[256];
/* * seed in the current time (usually just 4 bytes)
*/
t = time(NULL);
l = sizeof(time_t);
RAND_seed((unsignedchar *)&t, l);
/* * seed in the current process id (usually just 4 bytes)
*/
pid = getpid();
l = sizeof(pid_t);
RAND_seed((unsignedchar *)&pid, l);
/* * seed in some current state of the run-time stack (128 bytes)
*/
n = ssl_rand_choosenum(0, sizeof(stackdata)-128-1);
RAND_seed(stackdata+n, 128);
}
c = SSL_get_current_cipher(ssl);
BIO_printf(bio,"Cipher Suite Protocol :%s\n", SSL_CIPHER_get_version(c));
BIO_printf(bio,"Cipher Suite Name :%s\n",SSL_CIPHER_get_name(c));
bits = SSL_CIPHER_get_bits(c,&alg_bits);
BIO_printf(bio,"Cipher Suite Cipher Bits:%d (%d)\n",bits,alg_bits);
staticint compradre(struct data * a, struct data * b)
{ if ((a->ctime) < (b->ctime)) return -1; if ((a->ctime) > (b->ctime)) return +1; return 0;
}
staticint comprando(struct data * a, struct data * b)
{ if ((a->time) < (b->time)) return -1; if ((a->time) > (b->time)) return +1; return 0;
}
staticint compri(struct data * a, struct data * b)
{
apr_interval_time_t p = a->time - a->ctime;
apr_interval_time_t q = b->time - b->ctime; if (p < q) return -1; if (p > q) return +1; return 0;
}
staticint compwait(struct data * a, struct data * b)
{ if ((a->waittime) < (b->waittime)) return -1; if ((a->waittime) > (b->waittime)) return 1; return 0;
}
/* calculating the sample variance: the sum of the squared deviations, divided by n-1 */ for (i = 0; i < done; i++) { struct data *s = &stats[i]; double a;
a = ((double)s->time - meantot);
sdtot += a * a;
a = ((double)s->ctime - meancon);
sdcon += a * a;
a = ((double)s->time - (double)s->ctime - meand);
sdd += a * a;
a = ((double)s->waittime - meanwait);
sdwait += a * a;
}
/* * XXX: what is better; this hideous cast of the compradre function; or * the four warnings during compile ? dirkx just does not know and * hates both/
*/
qsort(stats, done, sizeof(struct data),
(int (*) (constvoid *, constvoid *)) compradre); if ((done > 1) && (done % 2))
mediancon = (stats[done / 2].ctime + stats[done / 2 + 1].ctime) / 2; else
mediancon = stats[done / 2].ctime;
#define SANE(what,mean,median,sd) \
{ \ double d = (double)mean - median; \ if (d < 0) d = -d; \ if (d > 2 * sd ) \
printf("ERROR: The median and mean for " what " are more than twice the standard\n" \ " deviation apart. These results are NOT reliable.\n"); \ elseif (d > sd ) \
printf("WARNING: The median and mean for " what " are not within a normal deviation\n" \ " These results are probably not that reliable.\n"); \
}
SANE("the initial connection time", meancon, mediancon, sdcon);
SANE("the processing time", meand, mediand, sdd);
SANE("the waiting time", meanwait, medianwait, sdwait);
SANE("the total time", meantot, mediantot, sdtot);
} else {
printf(" min avg max\n"); #define CONF_FMT_STRING "%5" APR_TIME_T_FMT " %5" APR_TIME_T_FMT "%5" APR_TIME_T_FMT "\n"
printf("Connect: " CONF_FMT_STRING, mincon, meancon, maxcon);
printf("Processing: " CONF_FMT_STRING, mind, meand, maxd);
printf("Waiting: " CONF_FMT_STRING, minwait, meanwait, maxwait);
printf("Total: " CONF_FMT_STRING, mintot, meantot, maxtot); #undef CONF_FMT_STRING
}
/* Sorted on total connect times */ if (percentile && (done > 1)) {
printf("\nPercentage of the requests served within a certain time (ms)\n"); for (i = 0; i < sizeof(percs) / sizeof(int); i++) { if (percs[i] <= 0)
printf(" 0%% <0> (never)\n"); elseif (percs[i] >= 100)
printf(" 100%% %5" APR_TIME_T_FMT " (longest request)\n",
ap_round_ms(stats[done - 1].time)); else
printf(" %d%% %5" APR_TIME_T_FMT "\n", percs[i],
ap_round_ms(stats[(unsignedlong)done * percs[i] / 100].time));
}
} if (csvperc) {
FILE *out = fopen(csvperc, "w"); if (!out) {
perror("Cannot open CSV output file"); exit(1);
}
fprintf(out, """Percentage served"",""Time in ms""\n"); for (i = 0; i <= 100; i++) { double t; if (i == 0)
t = ap_double_ms(stats[0].time); elseif (i == 100)
t = ap_double_ms(stats[done - 1].time); else
t = ap_double_ms(stats[(unsignedlong) (0.5 + (double)done * i / 100.0)].time);
fprintf(out, "%d,%.3f\n", i, t);
}
fclose(out);
} if (gnuplot) {
FILE *out = fopen(gnuplot, "w"); char tmstring[APR_CTIME_LEN]; if (!out) {
perror("Cannot open gnuplot output file"); exit(1);
}
fprintf(out, "starttime\tseconds\tctime\tdtime\tttime\twait\n"); for (i = 0; i < done; i++) {
(void) apr_ctime(tmstring, stats[i].starttime);
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", tmstring,
apr_time_sec(stats[i].starttime),
ap_round_ms(stats[i].ctime),
ap_round_ms(stats[i].time - stats[i].ctime),
ap_round_ms(stats[i].time),
ap_round_ms(stats[i].waittime));
}
fclose(out);
}
}
staticvoid read_connection(struct connection * c)
{
apr_size_t r;
apr_status_t status; char *part; char respcode[4]; /* 3 digits and null */ int i;
r = sizeof(buffer);
read_more: #ifdef USE_SSL if (c->ssl) {
status = SSL_read(c->ssl, buffer, r); if (status <= 0) { int scode = SSL_get_error(c->ssl, status);
if (scode == SSL_ERROR_ZERO_RETURN) { /* connection closed cleanly: */
good++;
close_connection(c);
} elseif (scode == SSL_ERROR_SYSCALL
&& status == 0
&& c->read != 0) { /* connection closed, but in violation of the protocol, after * some data has already been read; this commonly happens, so * let the length check catch any response errors
*/
good++;
close_connection(c);
} elseif (scode == SSL_ERROR_SYSCALL
&& c->read == 0
&& destsa->next
&& c->state == STATE_CONNECTING
&& good == 0) { return;
} elseif (scode == SSL_ERROR_WANT_READ) {
set_polled_events(c, APR_POLLIN);
} elseif (scode == SSL_ERROR_WANT_WRITE) {
set_polled_events(c, APR_POLLOUT);
} else { /* some fatal error: */
c->read = 0;
BIO_printf(bio_err, "SSL read failed (%d) - closing connection\n", scode);
ERR_print_errors(bio_err);
close_connection(c);
} return;
}
r = status;
} else #endif
{
status = apr_socket_recv(c->aprsock, buffer, &r); if (APR_STATUS_IS_EAGAIN(status)) return; elseif (r == 0 && APR_STATUS_IS_EOF(status)) {
good++;
close_connection(c); return;
} /* catch legitimate fatal apr_socket_recv errors */ elseif (status != APR_SUCCESS) { if (recverrok) {
err_recv++;
bad++;
close_connection(c); if (verbosity >= 1) { char buf[120];
fprintf(stderr,"%s: %s (%d)\n", "apr_socket_recv", apr_strerror(status, buf, sizeof buf), status);
} return;
} elseif (destsa->next && c->state == STATE_CONNECTING
&& c->read == 0 && good == 0) { return;
} else {
err_recv++;
apr_err("apr_socket_recv", status);
}
}
}
if (!c->gotheader) { char *s; int l = 4;
apr_size_t space = CBUFFSIZE - c->cbx - 1; /* -1 allows for \0 term */ int tocopy = (space < r) ? space : r; #ifdef NOT_ASCII
apr_size_t inbytes_left = space, outbytes_left = space;
status = apr_xlate_conv_buffer(from_ascii, buffer, &inbytes_left,
c->cbuff + c->cbx, &outbytes_left); if (status || inbytes_left || outbytes_left) {
fprintf(stderr, "only simple translation is supported (%d/%" APR_SIZE_T_FMT "/%" APR_SIZE_T_FMT ")\n", status, inbytes_left, outbytes_left); exit(1);
} #else
memcpy(c->cbuff + c->cbx, buffer, space); #endif/* NOT_ASCII */
c->cbx += tocopy;
space -= tocopy;
c->cbuff[c->cbx] = 0; /* terminate for benefit of strstr */ if (verbosity >= 2) {
printf("LOG: header received:\n%s\n", c->cbuff);
}
s = strstr(c->cbuff, "\r\n\r\n"); /* * this next line is so that we talk to NCSA 1.5 which blatantly * breaks the http specifaction
*/ if (!s) {
s = strstr(c->cbuff, "\n\n");
l = 2;
}
if (!s) { /* read rest next time */ if (space) { return;
} else { /* header is in invalid or too big - close connection */
set_conn_state(c, STATE_UNCONNECTED);
apr_socket_close(c->aprsock);
err_response++; if (bad++ > 10) {
err("\nTest aborted after 10 failures\n\n");
}
start_connect(c);
}
} else { /* have full header */ if (!good) { /* * this is first time, extract some interesting info
*/ char *p, *q;
size_t len = 0;
p = xstrcasestr(c->cbuff, "Server:");
q = servername; if (p) {
p += 8; /* -1 to not overwrite last '\0' byte */ while (*p > 32 && len++ < sizeof(servername) - 1)
*q++ = *p++;
}
*q = 0;
} /* * XXX: this parsing isn't even remotely HTTP compliant... but in * the interest of speed it doesn't totally have to be, it just * needs to be extended to handle whatever servers folks want to * test against. -djg
*/
if (respcode[0] != '2') {
err_response++; if (verbosity >= 2)
printf("WARNING: Response code not 2xx (%s)\n", respcode);
} elseif (verbosity >= 3) {
printf("LOG: Response code = %s\n", respcode);
}
c->gotheader = 1;
*s = 0; /* terminate at end of header */ if (keepalive && xstrcasestr(c->cbuff, "Keep-Alive")) { char *cl;
c->keepalive = 1;
cl = xstrcasestr(c->cbuff, "Content-Length:"); if (cl && method != HEAD) { /* response to HEAD doesn't have entity body */
c->length = atoi(cl + 16);
} else {
c->length = 0;
}
}
c->bread += c->cbx - (s + l - c->cbuff) + r - tocopy;
totalbread += c->bread;
/* We have received the header, so we know this destination socket
* address is working, so initialize all remaining requests. */ if (!requests_initialized) { for (i = 1; i < concurrency; i++) {
con[i].socknum = i;
start_connect(&con[i]);
}
requests_initialized = 1;
}
}
} else { /* outside header, everything we have read is entity body */
c->bread += r;
totalbread += r;
} if (r == sizeof(buffer) && c->bread < c->length) { /* read was full, try more immediately (nonblocking already) */ goto read_more;
}
if (c->keepalive && (c->bread >= c->length)) { /* finished a keep-alive connection */
good++; /* save out time */ if (good == 1) { /* first time here */
doclen = c->bread;
} elseif ((c->bread != doclen) && !nolength) {
bad++;
err_length++;
} if (done < requests) { struct data *s = &stats[done++];
doneka++;
c->done = apr_time_now();
s->starttime = c->start;
s->ctime = ap_max(0, c->connect - c->start);
s->time = ap_max(0, c->done - c->start);
s->waittime = ap_max(0, c->beginread - c->endwrite); if (heartbeatres && !(done % heartbeatres)) {
fprintf(stderr, "Completed %d requests\n", done);
fflush(stderr);
}
}
c->keepalive = 0;
c->length = 0;
c->gotheader = 0;
c->cbx = 0;
c->read = c->bread = 0; /* zero connect time with keep-alive */
c->start = c->connect = lasttime = apr_time_now();
set_conn_state(c, STATE_CONNECTED);
write_request(c);
}
}
/* add default headers if necessary */ if (!opt_host) { /* Host: header not overridden, add default value to hdrs */
hdrs = apr_pstrcat(cntxt, hdrs, "Host: ", host_field, colonhost, "\r\n", NULL);
} else { /* Header overridden, no need to add, as it is already in hdrs */
}
#ifdef HAVE_TLSEXT if (is_ssl && tls_use_sni) {
apr_ipsubnet_t *ip; if (((tls_sni = opt_host) || (tls_sni = hostname)) &&
(!*tls_sni || apr_ipsubnet_create(&ip, tls_sni, NULL,
cntxt) == APR_SUCCESS)) { /* IP not allowed in TLS SNI extension */
tls_sni = NULL;
}
} #endif
if (!opt_useragent) { /* User-Agent: header not overridden, add default value to hdrs */
hdrs = apr_pstrcat(cntxt, hdrs, "User-Agent: ApacheBench/", AP_AB_BASEREVISION, "\r\n", NULL);
} else { /* Header overridden, no need to add, as it is already in hdrs */
}
if (!opt_accept) { /* Accept: header not overridden, add default value to hdrs */
hdrs = apr_pstrcat(cntxt, hdrs, "Accept: */*\r\n", NULL);
} else { /* Header overridden, no need to add, as it is already in hdrs */
}
if (myhost) { /* This only needs to be done once */ if ((rv = apr_sockaddr_info_get(&mysa, myhost, APR_UNSPEC, 0, 0, cntxt)) != APR_SUCCESS) { char buf[120];
apr_snprintf(buf, sizeof(buf), "apr_sockaddr_info_get() for %s", myhost);
apr_err(buf, rv);
}
}
/* This too */ if ((rv = apr_sockaddr_info_get(&destsa, connecthost,
myhost ? mysa->family : APR_UNSPEC,
connectport, 0, cntxt))
!= APR_SUCCESS) { char buf[120];
apr_snprintf(buf, sizeof(buf), "apr_sockaddr_info_get() for %s", connecthost);
apr_err(buf, rv);
}
#ifdef SIGINT /* Output the results if the user terminates the run early. */
apr_signal(SIGINT, output_results); #endif
/* initialise first connection to determine destination socket address
* which should be used for next connections. */
con[0].socknum = 0;
start_connect(&con[0]);
do {
apr_int32_t n; const apr_pollfd_t *pollresults, *pollfd;
n = concurrency; do {
status = apr_pollset_poll(readbits, aprtimeout, &n, &pollresults);
} while (APR_STATUS_IS_EINTR(status)); if (status != APR_SUCCESS)
apr_err("apr_pollset_poll", status);
for (i = 0, pollfd = pollresults; i < n; i++, pollfd++) { struct connection *c;
c = pollfd->client_data;
/* * If the connection isn't connected how can we check it?
*/ if (c->state == STATE_UNCONNECTED) continue;
/* * Notes: APR_POLLHUP is set after FIN is received on some * systems, so treat that like APR_POLLIN so that we try to read * again. * * Some systems return APR_POLLERR with APR_POLLHUP. We need to * call read_connection() for APR_POLLHUP, so check for * APR_POLLHUP first so that a closed connection isn't treated * like an I/O error. If it is, we never figure out that the * connection is done and we loop here endlessly calling * apr_poll().
*/ if ((rtnev & APR_POLLIN) || (rtnev & APR_POLLPRI) || (rtnev & APR_POLLHUP))
read_connection(c); if ((rtnev & APR_POLLERR) || (rtnev & APR_POLLNVAL)) { if (destsa->next && c->state == STATE_CONNECTING && good == 0) {
destsa = destsa->next;
start_connect(c);
} else {
bad++;
err_except++; /* avoid apr_poll/EINPROGRESS loop on HP-UX, let recv discover ECONNREFUSED */ if (c->state == STATE_CONNECTING) {
read_connection(c);
} else {
start_connect(c);
}
} continue;
} if (rtnev & APR_POLLOUT) { if (c->state == STATE_CONNECTING) { /* call connect() again to detect errors */
rv = apr_socket_connect(c->aprsock, destsa); if (rv != APR_SUCCESS) {
set_conn_state(c, STATE_UNCONNECTED);
apr_socket_close(c->aprsock);
err_conn++; if (bad++ > 10) {
fprintf(stderr, "\nTest aborted after 10 failures\n\n");
apr_err("apr_socket_connect()", rv);
}
start_connect(c); continue;
} else {
set_conn_state(c, STATE_CONNECTED); #ifdef USE_SSL if (c->ssl)
ssl_proceed_handshake(c); else #endif
write_request(c);
}
} else { /* POLLOUT is one shot */
set_polled_events(c, APR_POLLIN); if (c->state == STATE_READ) {
read_connection(c);
} else {
write_request(c);
}
}
}
}
} while (lasttime < stoptime && done < requests);
if (heartbeatres)
fprintf(stderr, "Finished %d requests\n", done); else
printf("..done\n");
if (use_html)
output_html_results(); else
output_results(0);
}
/* display copyright information */ staticvoid copyright(void)
{ if (!use_html) {
printf("This is ApacheBench, Version %s\n", AP_AB_BASEREVISION " <$Revision: 1923142 $>");
printf("Copyright 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/\n");
printf("Licensed to The Apache Software Foundation, http://www.apache.org/\n");
printf("\n");
} else {
printf("<p>\n");
printf(" This is ApacheBench, Version %s <i><%s></i><br>\n", AP_AB_BASEREVISION, "$Revision: 1923142 $");
printf(" Copyright 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/<br>\n");
printf(" Licensed to The Apache Software Foundation, http://www.apache.org/<br>\n");
printf("</p>\n<p>\n");
}
}
/* display usage information */ staticvoid usage(constchar *progname)
{
fprintf(stderr, "Usage: %s [options] [http" #ifdef USE_SSL "[s]" #endif "://]hostname[:port]/path\n", progname); /* 80 column ruler: ********************************************************************************
*/
fprintf(stderr, "Options are:\n");
fprintf(stderr, " -n requests Number of requests to perform\n");
fprintf(stderr, " -c concurrency Number of multiple requests to make at a time\n");
fprintf(stderr, " -t timelimit Seconds to max. to spend on benchmarking\n");
fprintf(stderr, " This implies -n 50000\n");
fprintf(stderr, " -s timeout Seconds to max. wait for each response\n");
fprintf(stderr, " Default is 30 seconds\n");
fprintf(stderr, " -b windowsize Size of TCP send/receive buffer, in bytes\n");
fprintf(stderr, " -B address Address to bind to when making outgoing connections\n");
fprintf(stderr, " -p postfile File containing data to POST. Remember also to set -T\n");
fprintf(stderr, " -u putfile File containing data to PUT. Remember also to set -T\n");
fprintf(stderr, " -T content-type Content-type header to use for POST/PUT data, eg.\n");
fprintf(stderr, " 'application/x-www-form-urlencoded'\n");
fprintf(stderr, " Default is 'text/plain'\n");
fprintf(stderr, " -v verbosity How much troubleshooting info to print\n");
fprintf(stderr, " -w Print out results in HTML tables\n");
fprintf(stderr, " -i Use HEAD instead of GET\n");
fprintf(stderr, " -x attributes String to insert as table attributes\n");
fprintf(stderr, " -y attributes String to insert as tr attributes\n");
fprintf(stderr, " -z attributes String to insert as td or th attributes\n");
fprintf(stderr, " -C attribute Add cookie, eg. 'Apache=1234'. (repeatable)\n");
fprintf(stderr, " -H attribute Add Arbitrary header line, eg. 'Accept-Encoding: gzip'\n");
fprintf(stderr, " Inserted after all normal header lines. (repeatable)\n");
fprintf(stderr, " -A attribute Add Basic WWW Authentication, the attributes\n");
fprintf(stderr, " are a colon separated username and password.\n");
fprintf(stderr, " -P attribute Add Basic Proxy Authentication, the attributes\n");
fprintf(stderr, " are a colon separated username and password.\n");
fprintf(stderr, " -X proxy:port Proxyserver and port number to use\n");
fprintf(stderr, " -V Print version number and exit\n");
fprintf(stderr, " -k Use HTTP KeepAlive feature\n");
fprintf(stderr, " -d Do not show percentiles served table.\n");
fprintf(stderr, " -S Do not show confidence estimators and warnings.\n");
fprintf(stderr, " -q Do not show progress when doing more than 150 requests\n");
fprintf(stderr, " -l Accept variable document length (use this for dynamic pages)\n");
fprintf(stderr, " -g filename Output collected data to gnuplot format file.\n");
fprintf(stderr, " -e filename Output CSV file with percentages served\n");
fprintf(stderr, " -r Don't exit on socket receive errors.\n");
fprintf(stderr, " -m method Method name\n");
fprintf(stderr, " -h Display usage information (this message)\n"); #ifdef USE_SSL
rv = apr_file_open(&postfd, pfile, APR_READ, APR_OS_DEFAULT, cntxt); if (rv != APR_SUCCESS) {
fprintf(stderr, "ab: Could not open POST data file (%s): %s\n", pfile,
apr_strerror(rv, errmsg, sizeof errmsg)); return rv;
}
rv = apr_file_info_get(&finfo, APR_FINFO_NORM, postfd); if (rv != APR_SUCCESS) {
fprintf(stderr, "ab: Could not stat POST data file (%s): %s\n", pfile,
apr_strerror(rv, errmsg, sizeof errmsg)); return rv;
}
postlen = (apr_size_t)finfo.size;
postdata = xmalloc(postlen);
rv = apr_file_read_full(postfd, postdata, postlen, NULL); if (rv != APR_SUCCESS) {
fprintf(stderr, "ab: Could not read POST data file: %s\n",
apr_strerror(rv, errmsg, sizeof errmsg)); return rv;
}
apr_file_close(postfd); return APR_SUCCESS;
}
if (concurrency > requests) {
fprintf(stderr, "%s: Cannot use concurrency level greater than " "total number of requests\n", argv[0]);
usage(argv[0]);
}
if ((heartbeatres) && (requests > 150)) {
heartbeatres = requests / 10; /* Print line every 10% of requests */ if (heartbeatres < 100)
heartbeatres = 100; /* but never more often than once every 100
* connections. */
} else
heartbeatres = 0;
if (!(ssl_ctx = SSL_CTX_new(meth))) {
BIO_printf(bio_err, "Could not initialize SSL Context.\n");
ERR_print_errors(bio_err); exit(1);
}
SSL_CTX_set_options(ssl_ctx, SSL_OP_ALL); #if OPENSSL_VERSION_NUMBER >= 0x10100000L
SSL_CTX_set_max_proto_version(ssl_ctx, max_prot);
SSL_CTX_set_min_proto_version(ssl_ctx, min_prot); #endif #ifdef SSL_MODE_RELEASE_BUFFERS /* Keep memory usage as low as possible */
SSL_CTX_set_mode (ssl_ctx, SSL_MODE_RELEASE_BUFFERS); #endif
if (ssl_cipher != NULL) { int ok; #if OPENSSL_VERSION_NUMBER >= 0x10101000L && defined(TLS1_3_VERSION) if (min_prot >= TLS1_3_VERSION)
ok = SSL_CTX_set_ciphersuites(ssl_ctx, ssl_cipher); else #endif
ok = SSL_CTX_set_cipher_list(ssl_ctx, ssl_cipher); if (!ok) {
BIO_printf(bio_err, "error setting ciphersuite list [%s]\n",
ssl_cipher);
ERR_print_errors(bio_err); exit(1);
}
}
if (verbosity >= 3) {
SSL_CTX_set_info_callback(ssl_ctx, ssl_state_cb);
} if (ssl_cert != NULL) { if (SSL_CTX_use_certificate_chain_file(ssl_ctx, ssl_cert) <= 0) {
BIO_printf(bio_err, "unable to get certificate from '%s'\n",
ssl_cert);
ERR_print_errors(bio_err); exit(1);
} if (SSL_CTX_use_PrivateKey_file(ssl_ctx, ssl_cert, SSL_FILETYPE_PEM) <= 0) {
BIO_printf(bio_err, "unable to get private key from '%s'\n",
ssl_cert);
ERR_print_errors(bio_err); exit(1);
} if (!SSL_CTX_check_private_key(ssl_ctx)) {
BIO_printf(bio_err, "private key does not match the certificate public key in %s\n", ssl_cert); exit(1);
}
}
#endif #ifdef SIGPIPE
apr_signal(SIGPIPE, SIG_IGN); /* Ignore writes to connections that
* have been closed at the other end. */ #endif
copyright();
test();
apr_pool_destroy(cntxt);
return 0;
}
Messung V0.5 in Prozent
¤ Dauer der Verarbeitung: 0.43 Sekunden
(vorverarbeitet am 2026-04-25)
¤
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.