1 /* Licensed to the Apache Software Foundation (ASF) under one or more
2 * contributor license agreements. See the NOTICE file distributed with
3 * this work for additional information regarding copyright ownership.
4 * The ASF licenses this file to You under the Apache License, Version 2.0
5 * (the "License"); you may not use this file except in compliance with
6 * the License. You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
18 ** This program is based on ZeusBench V1.0 written by Adam Twiss
19 ** which is Copyright (c) 1996 by Zeus Technology Ltd. http://www.zeustech.net/
21 ** This software is provided "as is" and any express or implied waranties,
22 ** including but not limited to, the implied warranties of merchantability and
23 ** fitness for a particular purpose are disclaimed. In no event shall
24 ** Zeus Technology Ltd. be liable for any direct, indirect, incidental, special,
25 ** exemplary, or consequential damaged (including, but not limited to,
26 ** procurement of substitute good or services; loss of use, data, or profits;
27 ** or business interruption) however caused and on theory of liability. Whether
28 ** in contract, strict liability or tort (including negligence or otherwise)
29 ** arising in any way out of the use of this software, even if advised of the
30 ** possibility of such damage.
36 ** - Originally written by Adam Twiss <adam@zeus.co.uk>, March 1996
37 ** with input from Mike Belshe <mbelshe@netscape.com> and
38 ** Michael Campanella <campanella@stevms.enet.dec.com>
39 ** - Enhanced by Dean Gaudet <dgaudet@apache.org>, November 1997
40 ** - Cleaned up by Ralf S. Engelschall <rse@apache.org>, March 1998
41 ** - POST and verbosity by Kurt Sussman <kls@merlot.com>, August 1998
42 ** - HTML table output added by David N. Welton <davidw@prosa.it>, January 1999
43 ** - Added Cookie, Arbitrary header and auth support. <dirkx@webweaving.org>, April 1999
45 ** - Increased version number - as some of the socket/error handling has
46 ** fundamentally changed - and will give fundamentally different results
47 ** in situations where a server is dropping requests. Therefore you can
48 ** no longer compare results of AB as easily. Hence the inc of the version.
49 ** They should be closer to the truth though. Sander & <dirkx@covalent.net>, End 2000.
50 ** - Fixed proxy functionality, added median/mean statistics, added gnuplot
51 ** output option, added _experimental/rudimentary_ SSL support. Added
52 ** confidence guestimators and warnings. Sander & <dirkx@covalent.net>, End 2000
53 ** - Fixed serious int overflow issues which would cause realistic (longer
54 ** than a few minutes) run's to have wrong (but believable) results. Added
55 ** trapping of connection errors which influenced measurements.
56 ** Contributed by Sander Temme, Early 2001
58 ** - Changed timeout behavour during write to work whilst the sockets
59 ** are filling up and apr_write() does writes a few - but not all.
60 ** This will potentially change results. <dirkx@webweaving.org>, April 2001
62 ** Improvements to concurrent processing:
63 ** - Enabled non-blocking connect()s.
64 ** - Prevent blocking calls to apr_socket_recv() (thereby allowing AB to
65 ** manage its entire set of socket descriptors).
66 ** - Any error returned from apr_socket_recv() that is not EAGAIN or EOF
67 ** is now treated as fatal.
68 ** Contributed by Aaron Bannert, April 24, 2002
71 ** Internalized the version string - this string is part
72 ** of the Agent: header and the result output.
75 ** Adopted SSL code by Madhu Mathihalli <madhusudan_mathihalli@hp.com>
76 ** [PATCH] ab with SSL support Posted Wed, 15 Aug 2001 20:55:06 GMT
77 ** Introduces four 'if (int == value)' tests per non-ssl request.
80 ** Switched to the new abstract pollset API, allowing ab to
81 ** take advantage of future apr_pollset_t scalability improvements.
82 ** Contributed by Brian Pane, August 31, 2002
85 ** SIGINT now triggers output_results().
86 ** Contributed by colm, March 30, 2006
89 /* Note: this version string should start with \d+[\d\.]* and be a valid
90 * string for an HTTP Agent: header when prefixed with 'ApacheBench/'.
91 * It should reflect the version of AB - and not that of the apache server
92 * it happens to accompany. And it should be updated or changed whenever
93 * the results are no longer fundamentally comparable to the results of
94 * a previous version of ab. Either due to a change in the logic of
95 * ab - or to due to a change in the distribution it is compiled with
96 * (such as an APR change in for example blocking).
98 #define AP_AB_BASEREVISION "2.3"
104 * - has various other poor buffer attacks related to the lazy parsing of
105 * response headers from the server
106 * - doesn't implement much of HTTP/1.x, only accepts certain forms of
108 * - (performance problem) heavy use of strstr shows up top in profile
109 * only an issue for loopback usage
112 /* -------------------------------------------------------------------- */
115 /* Hmmm... This source code isn't being compiled in ASCII.
116 * In order for data that flows over the network to make
117 * sense, we need to translate to/from ASCII.
122 /* affects include files on Solaris */
126 #include "apr_signal.h"
127 #include "apr_strings.h"
128 #include "apr_network_io.h"
129 #include "apr_file_io.h"
130 #include "apr_time.h"
131 #include "apr_getopt.h"
132 #include "apr_general.h"
134 #include "apr_portable.h"
135 #include "ap_release.h"
136 #include "apr_poll.h"
138 #define APR_WANT_STRFUNC
139 #include "apr_want.h"
141 #include "apr_base64.h"
143 #include "apr_xlate.h"
148 #if APR_HAVE_STDLIB_H
151 #if APR_HAVE_UNISTD_H
152 #include <unistd.h> /* for getpid() */
155 #if !defined(WIN32) && !defined(NETWARE)
156 #include "ap_config_auto.h"
159 #if defined(HAVE_OPENSSL)
161 #include <openssl/rsa.h>
162 #include <openssl/crypto.h>
163 #include <openssl/x509.h>
164 #include <openssl/pem.h>
165 #include <openssl/err.h>
166 #include <openssl/ssl.h>
167 #include <openssl/rand.h>
169 #define SK_NUM(x) sk_X509_num(x)
170 #define SK_VALUE(x,y) sk_X509_value(x,y)
171 typedef STACK_OF(X509) X509_STACK_TYPE;
173 #if defined(_MSC_VER)
174 /* The following logic ensures we correctly glue FILE* within one CRT used
175 * by the OpenSSL library build to another CRT used by the ab.exe build.
176 * This became especially problematic with Visual Studio 2015.
178 #include <openssl/applink.c>
184 #if (OPENSSL_VERSION_NUMBER >= 0x00909000)
185 #define AB_SSL_METHOD_CONST const
187 #define AB_SSL_METHOD_CONST
189 #if (OPENSSL_VERSION_NUMBER >= 0x0090707f)
190 #define AB_SSL_CIPHER_CONST const
192 #define AB_SSL_CIPHER_CONST
194 #ifdef SSL_OP_NO_TLSv1_2
197 #if !defined(OPENSSL_NO_TLSEXT) && defined(SSL_set_tlsext_host_name)
200 #if defined(LIBRESSL_VERSION_NUMBER) && LIBRESSL_VERSION_NUMBER < 0x2060000f
201 #define SSL_CTRL_SET_MIN_PROTO_VERSION 123
202 #define SSL_CTRL_SET_MAX_PROTO_VERSION 124
203 #define SSL_CTX_set_min_proto_version(ctx, version) \
204 SSL_CTX_ctrl(ctx, SSL_CTRL_SET_MIN_PROTO_VERSION, version, NULL)
205 #define SSL_CTX_set_max_proto_version(ctx, version) \
206 SSL_CTX_ctrl(ctx, SSL_CTRL_SET_MAX_PROTO_VERSION, version, NULL)
214 #if APR_HAVE_LIMITS_H
218 /* ------------------- DEFINITIONS -------------------------- */
221 #define AB_MAX APR_INT64_C(0x7fffffffffffffff)
223 #define AB_MAX LLONG_MAX
226 /* maximum number of requests on a time limited test */
227 #define MAX_REQUESTS (INT_MAX > 50000 ? 50000 : INT_MAX)
230 * don't add enums or rearrange or otherwise change values without
231 * visiting set_conn_state()
234 STATE_UNCONNECTED = 0,
235 STATE_CONNECTING, /* TCP connect initiated, but we don't
236 * know if it worked yet
238 STATE_CONNECTED, /* we know TCP connect completed */
242 #define CBUFFSIZE (8192)
246 apr_socket_t *aprsock;
249 apr_size_t read; /* amount of bytes read */
250 apr_size_t bread; /* amount of body read */
251 apr_size_t rwrite, rwrote; /* keep pointers in what we write - across
253 apr_size_t length; /* Content-Length value used for keep-alive */
254 char cbuff[CBUFFSIZE]; /* a buffer to store server response header */
255 int cbx; /* offset in cbuffer */
256 int keepalive; /* non-zero if a keep-alive request */
257 int gotheader; /* non-zero if we have the entire header in
259 apr_time_t start, /* Start of connection */
260 connect, /* Connected, start writing */
261 endwrite, /* Request written */
262 beginread, /* First byte of input */
263 done; /* Connection closed */
272 apr_time_t starttime; /* start time of connection */
273 apr_interval_time_t waittime; /* between request and reading response */
274 apr_interval_time_t ctime; /* time to connect */
275 apr_interval_time_t time; /* time for connection */
278 #define ap_min(a,b) (((a)<(b))?(a):(b))
279 #define ap_max(a,b) (((a)>(b))?(a):(b))
280 #define ap_round_ms(a) ((apr_time_t)((a) + 500)/1000)
281 #define ap_double_ms(a) ((double)(a)/1000.0)
282 #define MAX_CONCURRENCY 20000
284 /* --------------------- GLOBALS ---------------------------- */
286 int verbosity = 0; /* no verbosity by default */
287 int recverrok = 0; /* ok to proceed after socket receive errors */
288 enum {NO_METH = 0, GET, HEAD, PUT, POST, CUSTOM_METHOD} method = NO_METH;
289 const char *method_str[] = {"bug", "GET", "HEAD", "PUT", "POST", ""};
290 int send_body = 0; /* non-zero if sending body with request */
291 int requests = 1; /* Number of requests to make */
292 int heartbeatres = 100; /* How often do we say we're alive */
293 int concurrency = 1; /* Number of multiple requests to make */
294 int percentile = 1; /* Show percentile served */
295 int nolength = 0; /* Accept variable document length */
296 int confidence = 1; /* Show confidence estimator and warnings */
297 int tlimit = 0; /* time limit in secs */
298 int keepalive = 0; /* try and do keepalive connections */
299 int windowsize = 0; /* we use the OS default window size */
300 char servername[1024]; /* name that server reports */
301 char *hostname; /* host name from URL */
302 const char *host_field; /* value of "Host:" header field */
303 const char *path; /* path name */
304 char *postdata; /* *buffer containing data from postfile */
305 apr_size_t postlen = 0; /* length of data to be POSTed */
306 char *content_type = NULL; /* content type to put in POST header */
307 const char *cookie, /* optional cookie line */
308 *auth, /* optional (basic/uuencoded) auhentication */
309 *hdrs; /* optional arbitrary headers */
310 apr_port_t port; /* port number */
311 char *proxyhost = NULL; /* proxy host name */
312 int proxyport = 0; /* proxy port */
313 const char *connecthost;
315 apr_port_t connectport;
316 const char *gnuplot; /* GNUplot file */
317 const char *csvperc; /* CSV Percentile file */
319 const char *colonhost;
321 apr_interval_time_t aprtimeout = apr_time_from_sec(30); /* timeout value */
323 /* overrides for ab-generated common headers */
324 const char *opt_host; /* which optional "Host:" header specified, if any */
325 int opt_useragent = 0; /* was an optional "User-Agent:" header specified? */
326 int opt_accept = 0; /* was an optional "Accept:" header specified? */
328 * XXX - this is now a per read/write transact type of value
331 int use_html = 0; /* use html in the report */
332 const char *tablestring;
333 const char *trstring;
334 const char *tdstring;
336 apr_size_t doclen = 0; /* the length the document should be */
337 apr_int64_t totalread = 0; /* total number of bytes read */
338 apr_int64_t totalbread = 0; /* totoal amount of entity body read */
339 apr_int64_t totalposted = 0; /* total number of bytes posted, inc. headers */
340 int started = 0; /* number of requests started, so no excess */
341 int done = 0; /* number of requests we have done */
342 int doneka = 0; /* number of keep alive connections done */
343 int good = 0, bad = 0; /* number of good and bad requests */
344 int epipe = 0; /* number of broken pipe writes */
345 int err_length = 0; /* requests failed due to response length */
346 int err_conn = 0; /* requests failed due to connection drop */
347 int err_recv = 0; /* requests failed due to broken read */
348 int err_except = 0; /* requests failed due to exception */
349 int err_response = 0; /* requests with invalid or non-200 response */
354 char *ssl_cipher = NULL;
355 char *ssl_info = NULL;
356 char *ssl_tmp_key = NULL;
357 BIO *bio_out,*bio_err;
359 int tls_use_sni = 1; /* used by default, -I disables it */
360 const char *tls_sni = NULL; /* 'opt_host' if any, 'hostname' otherwise */
364 apr_time_t start, lasttime, stoptime;
366 /* global request (and its length) */
368 char *request = _request;
370 int requests_initialized = 0;
372 /* one global throw-away buffer to read stuff into */
375 /* interesting percentiles */
376 int percs[] = {50, 66, 75, 80, 90, 95, 98, 99, 100};
378 struct connection *con; /* connection array */
379 struct data *stats; /* data for each request */
382 apr_pollset_t *readbits;
384 apr_sockaddr_t *mysa;
385 apr_sockaddr_t *destsa;
388 apr_xlate_t *from_ascii, *to_ascii;
391 static void write_request(struct connection * c);
392 static void close_connection(struct connection * c);
394 /* --------------------------------------------------------- */
396 /* simple little function to write an error string and exit */
398 static void err(const char *s)
400 fprintf(stderr, "%s\n", s);
402 printf("Total of %d requests completed\n" , done);
406 /* simple little function to write an APR error string and exit */
408 static void apr_err(const char *s, apr_status_t rv)
414 s, apr_strerror(rv, buf, sizeof buf), rv);
416 printf("Total of %d requests completed\n" , done);
420 static void *xmalloc(size_t size)
422 void *ret = malloc(size);
424 fprintf(stderr, "Could not allocate memory (%"
425 APR_SIZE_T_FMT" bytes)\n", size);
431 static void *xcalloc(size_t num, size_t size)
433 void *ret = calloc(num, size);
435 fprintf(stderr, "Could not allocate memory (%"
436 APR_SIZE_T_FMT" bytes)\n", size*num);
442 static char *xstrdup(const char *s)
444 char *ret = strdup(s);
446 fprintf(stderr, "Could not allocate memory (%"
447 APR_SIZE_T_FMT " bytes)\n", strlen(s));
454 * Similar to standard strstr() but we ignore case in this version.
455 * Copied from ap_strcasestr().
457 static char *xstrcasestr(const char *s1, const char *s2)
465 for ( ; (*s1 != '\0') && (apr_tolower(*s1) != apr_tolower(*s2)); s1++);
469 /* found first character of s2, see if the rest matches */
472 for (++p1, ++p2; apr_tolower(*p1) == apr_tolower(*p2); ++p1, ++p2) {
474 /* both strings ended together */
479 /* second string ended, a match */
482 /* didn't find a match here, try starting at next character in s1 */
488 /* pool abort function */
489 static int abort_on_oom(int retcode)
491 fprintf(stderr, "Could not allocate memory\n");
497 static void set_polled_events(struct connection *c, apr_int16_t new_reqevents)
501 if (c->pollfd.reqevents != new_reqevents) {
502 if (c->pollfd.reqevents != 0) {
503 rv = apr_pollset_remove(readbits, &c->pollfd);
504 if (rv != APR_SUCCESS) {
505 apr_err("apr_pollset_remove()", rv);
509 if (new_reqevents != 0) {
510 c->pollfd.reqevents = new_reqevents;
511 rv = apr_pollset_add(readbits, &c->pollfd);
512 if (rv != APR_SUCCESS) {
513 apr_err("apr_pollset_add()", rv);
519 static void set_conn_state(struct connection *c, connect_state_e new_state)
521 apr_int16_t events_by_state[] = {
522 0, /* for STATE_UNCONNECTED */
523 APR_POLLOUT, /* for STATE_CONNECTING */
524 APR_POLLIN, /* for STATE_CONNECTED; we don't poll in this state,
525 * so prepare for polling in the following state --
528 APR_POLLIN /* for STATE_READ */
531 c->state = new_state;
533 set_polled_events(c, events_by_state[new_state]);
536 /* --------------------------------------------------------- */
537 /* write out request to a connection - assumes we can write
538 * (small) request out in one go into our new socket buffer
542 static long ssl_print_cb(BIO *bio,int cmd,const char *argp,int argi,long argl,long ret)
546 out=(BIO *)BIO_get_callback_arg(bio);
547 if (out == NULL) return(ret);
549 if (cmd == (BIO_CB_READ|BIO_CB_RETURN)) {
550 BIO_printf(out,"read from %p [%p] (%d bytes => %ld (0x%lX))\n",
551 bio, argp, argi, ret, ret);
552 BIO_dump(out,(char *)argp,(int)ret);
555 else if (cmd == (BIO_CB_WRITE|BIO_CB_RETURN)) {
556 BIO_printf(out,"write to %p [%p] (%d bytes => %ld (0x%lX))\n",
557 bio, argp, argi, ret, ret);
558 BIO_dump(out,(char *)argp,(int)ret);
563 static void ssl_state_cb(const SSL *s, int w, int r)
565 if (w & SSL_CB_ALERT) {
566 BIO_printf(bio_err, "SSL/TLS Alert [%s] %s:%s\n",
567 (w & SSL_CB_READ ? "read" : "write"),
568 SSL_alert_type_string_long(r),
569 SSL_alert_desc_string_long(r));
570 } else if (w & SSL_CB_LOOP) {
571 BIO_printf(bio_err, "SSL/TLS State [%s] %s\n",
572 (SSL_in_connect_init((SSL*)s) ? "connect" : "-"),
573 SSL_state_string_long(s));
574 } else if (w & (SSL_CB_HANDSHAKE_START|SSL_CB_HANDSHAKE_DONE)) {
575 BIO_printf(bio_err, "SSL/TLS Handshake [%s] %s\n",
576 (w & SSL_CB_HANDSHAKE_START ? "Start" : "Done"),
577 SSL_state_string_long(s));
582 #define RAND_MAX INT_MAX
585 static int ssl_rand_choosenum(int l, int h)
590 srand((unsigned int)time(NULL));
591 apr_snprintf(buf, sizeof(buf), "%.0f",
592 (((double)(rand()%RAND_MAX)/RAND_MAX)*(h-l)));
599 static void ssl_rand_seed(void)
604 unsigned char stackdata[256];
607 * seed in the current time (usually just 4 bytes)
611 RAND_seed((unsigned char *)&t, l);
614 * seed in the current process id (usually just 4 bytes)
618 RAND_seed((unsigned char *)&pid, l);
621 * seed in some current state of the run-time stack (128 bytes)
623 n = ssl_rand_choosenum(0, sizeof(stackdata)-128-1);
624 RAND_seed(stackdata+n, 128);
627 static int ssl_print_connection_info(BIO *bio, SSL *ssl)
629 AB_SSL_CIPHER_CONST SSL_CIPHER *c;
632 BIO_printf(bio,"Transport Protocol :%s\n", SSL_get_version(ssl));
634 c = SSL_get_current_cipher(ssl);
635 BIO_printf(bio,"Cipher Suite Protocol :%s\n", SSL_CIPHER_get_version(c));
636 BIO_printf(bio,"Cipher Suite Name :%s\n",SSL_CIPHER_get_name(c));
638 bits = SSL_CIPHER_get_bits(c,&alg_bits);
639 BIO_printf(bio,"Cipher Suite Cipher Bits:%d (%d)\n",bits,alg_bits);
644 static void ssl_print_cert_info(BIO *bio, X509 *cert)
650 BIO_printf(bio, "Certificate version: %ld\n", X509_get_version(cert)+1);
651 BIO_printf(bio,"Valid from: ");
652 ASN1_UTCTIME_print(bio, X509_get_notBefore(cert));
653 BIO_printf(bio,"\n");
655 BIO_printf(bio,"Valid to : ");
656 ASN1_UTCTIME_print(bio, X509_get_notAfter(cert));
657 BIO_printf(bio,"\n");
659 pk = X509_get_pubkey(cert);
660 BIO_printf(bio,"Public key is %d bits\n",
664 dn = X509_get_issuer_name(cert);
665 X509_NAME_oneline(dn, buf, sizeof(buf));
666 BIO_printf(bio,"The issuer name is %s\n", buf);
668 dn=X509_get_subject_name(cert);
669 X509_NAME_oneline(dn, buf, sizeof(buf));
670 BIO_printf(bio,"The subject name is %s\n", buf);
672 /* dump the extension list too */
673 BIO_printf(bio, "Extension Count: %d\n", X509_get_ext_count(cert));
676 static void ssl_print_info(struct connection *c)
682 BIO_printf(bio_err, "\n");
683 sk = SSL_get_peer_cert_chain(c->ssl);
684 if ((count = SK_NUM(sk)) > 0) {
686 for (i=1; i<count; i++) {
687 cert = (X509 *)SK_VALUE(sk, i);
688 ssl_print_cert_info(bio_out, cert);
691 cert = SSL_get_peer_certificate(c->ssl);
693 BIO_printf(bio_out, "Anon DH\n");
695 BIO_printf(bio_out, "Peer certificate\n");
696 ssl_print_cert_info(bio_out, cert);
699 ssl_print_connection_info(bio_err,c->ssl);
700 SSL_SESSION_print(bio_err, SSL_get_session(c->ssl));
703 static void ssl_proceed_handshake(struct connection *c)
710 ret = SSL_do_handshake(c->ssl);
711 ecode = SSL_get_error(c->ssl, ret);
717 if (ssl_info == NULL) {
718 AB_SSL_CIPHER_CONST SSL_CIPHER *ci;
720 int sk_bits, pk_bits, swork;
722 ci = SSL_get_current_cipher(c->ssl);
723 sk_bits = SSL_CIPHER_get_bits(ci, &swork);
724 cert = SSL_get_peer_certificate(c->ssl);
726 pk_bits = EVP_PKEY_bits(X509_get_pubkey(cert));
728 pk_bits = 0; /* Anon DH */
730 ssl_info = xmalloc(128);
731 apr_snprintf(ssl_info, 128, "%s,%s,%d,%d",
732 SSL_get_version(c->ssl),
733 SSL_CIPHER_get_name(ci),
736 if (ssl_tmp_key == NULL) {
738 if (SSL_get_server_tmp_key(c->ssl, &key)) {
739 ssl_tmp_key = xmalloc(128);
740 switch (EVP_PKEY_id(key)) {
742 apr_snprintf(ssl_tmp_key, 128, "RSA %d bits",
746 apr_snprintf(ssl_tmp_key, 128, "DH %d bits",
749 #ifndef OPENSSL_NO_EC
751 const char *cname = NULL;
752 EC_KEY *ec = EVP_PKEY_get1_EC_KEY(key);
753 int nid = EC_GROUP_get_curve_name(EC_KEY_get0_group(ec));
755 #if OPENSSL_VERSION_NUMBER >= 0x10002000L
756 cname = EC_curve_nid2nist(nid);
759 cname = OBJ_nid2sn(nid);
761 apr_snprintf(ssl_tmp_key, 128, "ECDH %s %d bits",
774 case SSL_ERROR_WANT_READ:
775 set_polled_events(c, APR_POLLIN);
778 case SSL_ERROR_WANT_WRITE:
779 set_polled_events(c, APR_POLLOUT);
782 case SSL_ERROR_WANT_CONNECT:
784 case SSL_ERROR_SYSCALL:
785 /* Unexpected result */
786 BIO_printf(bio_err, "SSL handshake failed (%d).\n", ecode);
787 ERR_print_errors(bio_err);
797 static void write_request(struct connection * c)
799 if (started >= requests) {
805 apr_size_t l = c->rwrite;
806 apr_status_t e = APR_SUCCESS; /* prevent gcc warning */
808 tnow = lasttime = apr_time_now();
813 if (c->rwrite == 0) {
814 apr_socket_timeout_set(c->aprsock, 0);
819 c->rwrite += postlen;
822 else if (tnow > c->connect + aprtimeout) {
823 printf("Send request timed out!\n");
830 e = SSL_write(c->ssl, request + c->rwrote, l);
832 switch (SSL_get_error(c->ssl, e)) {
833 case SSL_ERROR_WANT_READ:
834 set_polled_events(c, APR_POLLIN);
836 case SSL_ERROR_WANT_WRITE:
837 set_polled_events(c, APR_POLLOUT);
840 BIO_printf(bio_err, "SSL write failed - closing connection\n");
841 ERR_print_errors(bio_err);
842 close_connection (c);
853 e = apr_socket_send(c->aprsock, request + c->rwrote, &l);
854 if (e != APR_SUCCESS) {
855 if (!APR_STATUS_IS_EAGAIN(e)) {
857 printf("Send request failed!\n");
862 set_polled_events(c, APR_POLLOUT);
872 c->endwrite = lasttime = apr_time_now();
874 set_conn_state(c, STATE_READ);
877 /* --------------------------------------------------------- */
879 /* calculate and output results */
881 static int compradre(struct data * a, struct data * b)
883 if ((a->ctime) < (b->ctime))
885 if ((a->ctime) > (b->ctime))
890 static int comprando(struct data * a, struct data * b)
892 if ((a->time) < (b->time))
894 if ((a->time) > (b->time))
899 static int compri(struct data * a, struct data * b)
901 apr_interval_time_t p = a->time - a->ctime;
902 apr_interval_time_t q = b->time - b->ctime;
910 static int compwait(struct data * a, struct data * b)
912 if ((a->waittime) < (b->waittime))
914 if ((a->waittime) > (b->waittime))
919 static void output_results(int sig)
924 lasttime = apr_time_now(); /* record final time if interrupted */
926 timetaken = (double) (lasttime - start) / APR_USEC_PER_SEC;
929 printf("Server Software: %s\n", servername);
930 printf("Server Hostname: %s\n", hostname);
931 printf("Server Port: %hu\n", port);
933 if (is_ssl && ssl_info) {
934 printf("SSL/TLS Protocol: %s\n", ssl_info);
936 if (is_ssl && ssl_tmp_key) {
937 printf("Server Temp Key: %s\n", ssl_tmp_key);
940 if (is_ssl && tls_sni) {
941 printf("TLS Server Name: %s\n", tls_sni);
946 printf("Document Path: %s\n", path);
948 printf("Document Length: Variable\n");
950 printf("Document Length: %" APR_SIZE_T_FMT " bytes\n", doclen);
952 printf("Concurrency Level: %d\n", concurrency);
953 printf("Time taken for tests: %.3f seconds\n", timetaken);
954 printf("Complete requests: %d\n", done);
955 printf("Failed requests: %d\n", bad);
957 printf(" (Connect: %d, Receive: %d, Length: %d, Exceptions: %d)\n",
958 err_conn, err_recv, err_length, err_except);
960 printf("Write errors: %d\n", epipe);
962 printf("Non-2xx responses: %d\n", err_response);
964 printf("Keep-Alive requests: %d\n", doneka);
965 printf("Total transferred: %" APR_INT64_T_FMT " bytes\n", totalread);
967 printf("Total body sent: %" APR_INT64_T_FMT "\n",
969 printf("HTML transferred: %" APR_INT64_T_FMT " bytes\n", totalbread);
971 /* avoid divide by zero */
972 if (timetaken && done) {
973 printf("Requests per second: %.2f [#/sec] (mean)\n",
974 (double) done / timetaken);
975 printf("Time per request: %.3f [ms] (mean)\n",
976 (double) concurrency * timetaken * 1000 / done);
977 printf("Time per request: %.3f [ms] (mean, across all concurrent requests)\n",
978 (double) timetaken * 1000 / done);
979 printf("Transfer rate: %.2f [Kbytes/sec] received\n",
980 (double) totalread / 1024 / timetaken);
982 printf(" %.2f kb/s sent\n",
983 (double) totalposted / 1024 / timetaken);
984 printf(" %.2f kb/s total\n",
985 (double) (totalread + totalposted) / 1024 / timetaken);
990 /* work out connection times */
992 apr_time_t totalcon = 0, total = 0, totald = 0, totalwait = 0;
993 apr_time_t meancon, meantot, meand, meanwait;
994 apr_interval_time_t mincon = AB_MAX, mintot = AB_MAX, mind = AB_MAX,
996 apr_interval_time_t maxcon = 0, maxtot = 0, maxd = 0, maxwait = 0;
997 apr_interval_time_t mediancon = 0, mediantot = 0, mediand = 0, medianwait = 0;
998 double sdtot = 0, sdcon = 0, sdd = 0, sdwait = 0;
1000 for (i = 0; i < done; i++) {
1001 struct data *s = &stats[i];
1002 mincon = ap_min(mincon, s->ctime);
1003 mintot = ap_min(mintot, s->time);
1004 mind = ap_min(mind, s->time - s->ctime);
1005 minwait = ap_min(minwait, s->waittime);
1007 maxcon = ap_max(maxcon, s->ctime);
1008 maxtot = ap_max(maxtot, s->time);
1009 maxd = ap_max(maxd, s->time - s->ctime);
1010 maxwait = ap_max(maxwait, s->waittime);
1012 totalcon += s->ctime;
1014 totald += s->time - s->ctime;
1015 totalwait += s->waittime;
1017 meancon = totalcon / done;
1018 meantot = total / done;
1019 meand = totald / done;
1020 meanwait = totalwait / done;
1022 /* calculating the sample variance: the sum of the squared deviations, divided by n-1 */
1023 for (i = 0; i < done; i++) {
1024 struct data *s = &stats[i];
1026 a = ((double)s->time - meantot);
1028 a = ((double)s->ctime - meancon);
1030 a = ((double)s->time - (double)s->ctime - meand);
1032 a = ((double)s->waittime - meanwait);
1036 sdtot = (done > 1) ? sqrt(sdtot / (done - 1)) : 0;
1037 sdcon = (done > 1) ? sqrt(sdcon / (done - 1)) : 0;
1038 sdd = (done > 1) ? sqrt(sdd / (done - 1)) : 0;
1039 sdwait = (done > 1) ? sqrt(sdwait / (done - 1)) : 0;
1042 * XXX: what is better; this hideous cast of the compradre function; or
1043 * the four warnings during compile ? dirkx just does not know and
1046 qsort(stats, done, sizeof(struct data),
1047 (int (*) (const void *, const void *)) compradre);
1048 if ((done > 1) && (done % 2))
1049 mediancon = (stats[done / 2].ctime + stats[done / 2 + 1].ctime) / 2;
1051 mediancon = stats[done / 2].ctime;
1053 qsort(stats, done, sizeof(struct data),
1054 (int (*) (const void *, const void *)) compri);
1055 if ((done > 1) && (done % 2))
1056 mediand = (stats[done / 2].time + stats[done / 2 + 1].time \
1057 -stats[done / 2].ctime - stats[done / 2 + 1].ctime) / 2;
1059 mediand = stats[done / 2].time - stats[done / 2].ctime;
1061 qsort(stats, done, sizeof(struct data),
1062 (int (*) (const void *, const void *)) compwait);
1063 if ((done > 1) && (done % 2))
1064 medianwait = (stats[done / 2].waittime + stats[done / 2 + 1].waittime) / 2;
1066 medianwait = stats[done / 2].waittime;
1068 qsort(stats, done, sizeof(struct data),
1069 (int (*) (const void *, const void *)) comprando);
1070 if ((done > 1) && (done % 2))
1071 mediantot = (stats[done / 2].time + stats[done / 2 + 1].time) / 2;
1073 mediantot = stats[done / 2].time;
1075 printf("\nConnection Times (ms)\n");
1077 * Reduce stats from apr time to milliseconds
1079 mincon = ap_round_ms(mincon);
1080 mind = ap_round_ms(mind);
1081 minwait = ap_round_ms(minwait);
1082 mintot = ap_round_ms(mintot);
1083 meancon = ap_round_ms(meancon);
1084 meand = ap_round_ms(meand);
1085 meanwait = ap_round_ms(meanwait);
1086 meantot = ap_round_ms(meantot);
1087 mediancon = ap_round_ms(mediancon);
1088 mediand = ap_round_ms(mediand);
1089 medianwait = ap_round_ms(medianwait);
1090 mediantot = ap_round_ms(mediantot);
1091 maxcon = ap_round_ms(maxcon);
1092 maxd = ap_round_ms(maxd);
1093 maxwait = ap_round_ms(maxwait);
1094 maxtot = ap_round_ms(maxtot);
1095 sdcon = ap_double_ms(sdcon);
1096 sdd = ap_double_ms(sdd);
1097 sdwait = ap_double_ms(sdwait);
1098 sdtot = ap_double_ms(sdtot);
1101 #define CONF_FMT_STRING "%5" APR_TIME_T_FMT " %4" APR_TIME_T_FMT " %5.1f %6" APR_TIME_T_FMT " %7" APR_TIME_T_FMT "\n"
1102 printf(" min mean[+/-sd] median max\n");
1103 printf("Connect: " CONF_FMT_STRING,
1104 mincon, meancon, sdcon, mediancon, maxcon);
1105 printf("Processing: " CONF_FMT_STRING,
1106 mind, meand, sdd, mediand, maxd);
1107 printf("Waiting: " CONF_FMT_STRING,
1108 minwait, meanwait, sdwait, medianwait, maxwait);
1109 printf("Total: " CONF_FMT_STRING,
1110 mintot, meantot, sdtot, mediantot, maxtot);
1111 #undef CONF_FMT_STRING
1113 #define SANE(what,mean,median,sd) \
1115 double d = (double)mean - median; \
1116 if (d < 0) d = -d; \
1118 printf("ERROR: The median and mean for " what " are more than twice the standard\n" \
1119 " deviation apart. These results are NOT reliable.\n"); \
1121 printf("WARNING: The median and mean for " what " are not within a normal deviation\n" \
1122 " These results are probably not that reliable.\n"); \
1124 SANE("the initial connection time", meancon, mediancon, sdcon);
1125 SANE("the processing time", meand, mediand, sdd);
1126 SANE("the waiting time", meanwait, medianwait, sdwait);
1127 SANE("the total time", meantot, mediantot, sdtot);
1130 printf(" min avg max\n");
1131 #define CONF_FMT_STRING "%5" APR_TIME_T_FMT " %5" APR_TIME_T_FMT "%5" APR_TIME_T_FMT "\n"
1132 printf("Connect: " CONF_FMT_STRING, mincon, meancon, maxcon);
1133 printf("Processing: " CONF_FMT_STRING, mind, meand, maxd);
1134 printf("Waiting: " CONF_FMT_STRING, minwait, meanwait, maxwait);
1135 printf("Total: " CONF_FMT_STRING, mintot, meantot, maxtot);
1136 #undef CONF_FMT_STRING
1140 /* Sorted on total connect times */
1141 if (percentile && (done > 1)) {
1142 printf("\nPercentage of the requests served within a certain time (ms)\n");
1143 for (i = 0; i < sizeof(percs) / sizeof(int); i++) {
1145 printf(" 0%% <0> (never)\n");
1146 else if (percs[i] >= 100)
1147 printf(" 100%% %5" APR_TIME_T_FMT " (longest request)\n",
1148 ap_round_ms(stats[done - 1].time));
1150 printf(" %d%% %5" APR_TIME_T_FMT "\n", percs[i],
1151 ap_round_ms(stats[(unsigned long)done * percs[i] / 100].time));
1155 FILE *out = fopen(csvperc, "w");
1157 perror("Cannot open CSV output file");
1160 fprintf(out, "" "Percentage served" "," "Time in ms" "\n");
1161 for (i = 0; i <= 100; i++) {
1164 t = ap_double_ms(stats[0].time);
1166 t = ap_double_ms(stats[done - 1].time);
1168 t = ap_double_ms(stats[(unsigned long) (0.5 + (double)done * i / 100.0)].time);
1169 fprintf(out, "%d,%.3f\n", i, t);
1174 FILE *out = fopen(gnuplot, "w");
1175 char tmstring[APR_CTIME_LEN];
1177 perror("Cannot open gnuplot output file");
1180 fprintf(out, "starttime\tseconds\tctime\tdtime\tttime\twait\n");
1181 for (i = 0; i < done; i++) {
1182 (void) apr_ctime(tmstring, stats[i].starttime);
1183 fprintf(out, "%s\t%" APR_TIME_T_FMT "\t%" APR_TIME_T_FMT
1184 "\t%" APR_TIME_T_FMT "\t%" APR_TIME_T_FMT
1185 "\t%" APR_TIME_T_FMT "\n", tmstring,
1186 apr_time_sec(stats[i].starttime),
1187 ap_round_ms(stats[i].ctime),
1188 ap_round_ms(stats[i].time - stats[i].ctime),
1189 ap_round_ms(stats[i].time),
1190 ap_round_ms(stats[i].waittime));
1201 /* --------------------------------------------------------- */
1203 /* calculate and output results in HTML */
1205 static void output_html_results(void)
1207 double timetaken = (double) (lasttime - start) / APR_USEC_PER_SEC;
1209 printf("\n\n<table %s>\n", tablestring);
1210 printf("<tr %s><th colspan=2 %s>Server Software:</th>"
1211 "<td colspan=2 %s>%s</td></tr>\n",
1212 trstring, tdstring, tdstring, servername);
1213 printf("<tr %s><th colspan=2 %s>Server Hostname:</th>"
1214 "<td colspan=2 %s>%s</td></tr>\n",
1215 trstring, tdstring, tdstring, hostname);
1216 printf("<tr %s><th colspan=2 %s>Server Port:</th>"
1217 "<td colspan=2 %s>%hu</td></tr>\n",
1218 trstring, tdstring, tdstring, port);
1219 printf("<tr %s><th colspan=2 %s>Document Path:</th>"
1220 "<td colspan=2 %s>%s</td></tr>\n",
1221 trstring, tdstring, tdstring, path);
1223 printf("<tr %s><th colspan=2 %s>Document Length:</th>"
1224 "<td colspan=2 %s>Variable</td></tr>\n",
1225 trstring, tdstring, tdstring);
1227 printf("<tr %s><th colspan=2 %s>Document Length:</th>"
1228 "<td colspan=2 %s>%" APR_SIZE_T_FMT " bytes</td></tr>\n",
1229 trstring, tdstring, tdstring, doclen);
1230 printf("<tr %s><th colspan=2 %s>Concurrency Level:</th>"
1231 "<td colspan=2 %s>%d</td></tr>\n",
1232 trstring, tdstring, tdstring, concurrency);
1233 printf("<tr %s><th colspan=2 %s>Time taken for tests:</th>"
1234 "<td colspan=2 %s>%.3f seconds</td></tr>\n",
1235 trstring, tdstring, tdstring, timetaken);
1236 printf("<tr %s><th colspan=2 %s>Complete requests:</th>"
1237 "<td colspan=2 %s>%d</td></tr>\n",
1238 trstring, tdstring, tdstring, done);
1239 printf("<tr %s><th colspan=2 %s>Failed requests:</th>"
1240 "<td colspan=2 %s>%d</td></tr>\n",
1241 trstring, tdstring, tdstring, bad);
1243 printf("<tr %s><td colspan=4 %s > (Connect: %d, Length: %d, Exceptions: %d)</td></tr>\n",
1244 trstring, tdstring, err_conn, err_length, err_except);
1246 printf("<tr %s><th colspan=2 %s>Non-2xx responses:</th>"
1247 "<td colspan=2 %s>%d</td></tr>\n",
1248 trstring, tdstring, tdstring, err_response);
1250 printf("<tr %s><th colspan=2 %s>Keep-Alive requests:</th>"
1251 "<td colspan=2 %s>%d</td></tr>\n",
1252 trstring, tdstring, tdstring, doneka);
1253 printf("<tr %s><th colspan=2 %s>Total transferred:</th>"
1254 "<td colspan=2 %s>%" APR_INT64_T_FMT " bytes</td></tr>\n",
1255 trstring, tdstring, tdstring, totalread);
1257 printf("<tr %s><th colspan=2 %s>Total body sent:</th>"
1258 "<td colspan=2 %s>%" APR_INT64_T_FMT "</td></tr>\n",
1260 tdstring, totalposted);
1261 printf("<tr %s><th colspan=2 %s>HTML transferred:</th>"
1262 "<td colspan=2 %s>%" APR_INT64_T_FMT " bytes</td></tr>\n",
1263 trstring, tdstring, tdstring, totalbread);
1265 /* avoid divide by zero */
1267 printf("<tr %s><th colspan=2 %s>Requests per second:</th>"
1268 "<td colspan=2 %s>%.2f</td></tr>\n",
1269 trstring, tdstring, tdstring, (double) done / timetaken);
1270 printf("<tr %s><th colspan=2 %s>Transfer rate:</th>"
1271 "<td colspan=2 %s>%.2f kb/s received</td></tr>\n",
1272 trstring, tdstring, tdstring, (double) totalread / 1024 / timetaken);
1274 printf("<tr %s><td colspan=2 %s> </td>"
1275 "<td colspan=2 %s>%.2f kb/s sent</td></tr>\n",
1276 trstring, tdstring, tdstring,
1277 (double) totalposted / 1024 / timetaken);
1278 printf("<tr %s><td colspan=2 %s> </td>"
1279 "<td colspan=2 %s>%.2f kb/s total</td></tr>\n",
1280 trstring, tdstring, tdstring,
1281 (double) (totalread + totalposted) / 1024 / timetaken);
1285 /* work out connection times */
1287 apr_interval_time_t totalcon = 0, total = 0;
1288 apr_interval_time_t mincon = AB_MAX, mintot = AB_MAX;
1289 apr_interval_time_t maxcon = 0, maxtot = 0;
1291 for (i = 0; i < done; i++) {
1292 struct data *s = &stats[i];
1293 mincon = ap_min(mincon, s->ctime);
1294 mintot = ap_min(mintot, s->time);
1295 maxcon = ap_max(maxcon, s->ctime);
1296 maxtot = ap_max(maxtot, s->time);
1297 totalcon += s->ctime;
1301 * Reduce stats from apr time to milliseconds
1303 mincon = ap_round_ms(mincon);
1304 mintot = ap_round_ms(mintot);
1305 maxcon = ap_round_ms(maxcon);
1306 maxtot = ap_round_ms(maxtot);
1307 totalcon = ap_round_ms(totalcon);
1308 total = ap_round_ms(total);
1310 if (done > 0) { /* avoid division by zero (if 0 done) */
1311 printf("<tr %s><th %s colspan=4>Connnection Times (ms)</th></tr>\n",
1312 trstring, tdstring);
1313 printf("<tr %s><th %s> </th> <th %s>min</th> <th %s>avg</th> <th %s>max</th></tr>\n",
1314 trstring, tdstring, tdstring, tdstring, tdstring);
1315 printf("<tr %s><th %s>Connect:</th>"
1316 "<td %s>%5" APR_TIME_T_FMT "</td>"
1317 "<td %s>%5" APR_TIME_T_FMT "</td>"
1318 "<td %s>%5" APR_TIME_T_FMT "</td></tr>\n",
1319 trstring, tdstring, tdstring, mincon, tdstring, totalcon / done, tdstring, maxcon);
1320 printf("<tr %s><th %s>Processing:</th>"
1321 "<td %s>%5" APR_TIME_T_FMT "</td>"
1322 "<td %s>%5" APR_TIME_T_FMT "</td>"
1323 "<td %s>%5" APR_TIME_T_FMT "</td></tr>\n",
1324 trstring, tdstring, tdstring, mintot - mincon, tdstring,
1325 (total / done) - (totalcon / done), tdstring, maxtot - maxcon);
1326 printf("<tr %s><th %s>Total:</th>"
1327 "<td %s>%5" APR_TIME_T_FMT "</td>"
1328 "<td %s>%5" APR_TIME_T_FMT "</td>"
1329 "<td %s>%5" APR_TIME_T_FMT "</td></tr>\n",
1330 trstring, tdstring, tdstring, mintot, tdstring, total / done, tdstring, maxtot);
1332 printf("</table>\n");
1336 /* --------------------------------------------------------- */
1338 /* start asnchronous non-blocking connection */
1340 static void start_connect(struct connection * c)
1344 if (!(started < requests))
1354 apr_pool_clear(c->ctx);
1356 apr_pool_create(&c->ctx, cntxt);
1358 if ((rv = apr_socket_create(&c->aprsock, destsa->family,
1359 SOCK_STREAM, 0, c->ctx)) != APR_SUCCESS) {
1360 apr_err("socket", rv);
1364 if ((rv = apr_socket_bind(c->aprsock, mysa)) != APR_SUCCESS) {
1365 apr_err("bind", rv);
1369 c->pollfd.desc_type = APR_POLL_SOCKET;
1370 c->pollfd.desc.s = c->aprsock;
1371 c->pollfd.reqevents = 0;
1372 c->pollfd.client_data = c;
1374 if ((rv = apr_socket_opt_set(c->aprsock, APR_SO_NONBLOCK, 1))
1376 apr_err("socket nonblock", rv);
1379 if (windowsize != 0) {
1380 rv = apr_socket_opt_set(c->aprsock, APR_SO_SNDBUF,
1382 if (rv != APR_SUCCESS && rv != APR_ENOTIMPL) {
1383 apr_err("socket send buffer", rv);
1385 rv = apr_socket_opt_set(c->aprsock, APR_SO_RCVBUF,
1387 if (rv != APR_SUCCESS && rv != APR_ENOTIMPL) {
1388 apr_err("socket receive buffer", rv);
1392 c->start = lasttime = apr_time_now();
1398 if ((c->ssl = SSL_new(ssl_ctx)) == NULL) {
1399 BIO_printf(bio_err, "SSL_new failed.\n");
1400 ERR_print_errors(bio_err);
1404 apr_os_sock_get(&fd, c->aprsock);
1405 bio = BIO_new_socket(fd, BIO_NOCLOSE);
1406 BIO_set_nbio(bio, 1);
1407 SSL_set_bio(c->ssl, bio, bio);
1408 SSL_set_connect_state(c->ssl);
1409 if (verbosity >= 4) {
1410 BIO_set_callback(bio, ssl_print_cb);
1411 BIO_set_callback_arg(bio, (void *)bio_err);
1415 SSL_set_tlsext_host_name(c->ssl, tls_sni);
1422 if ((rv = apr_socket_connect(c->aprsock, destsa)) != APR_SUCCESS) {
1423 if (APR_STATUS_IS_EINPROGRESS(rv)) {
1424 set_conn_state(c, STATE_CONNECTING);
1429 set_conn_state(c, STATE_UNCONNECTED);
1430 apr_socket_close(c->aprsock);
1431 if (good == 0 && destsa->next) {
1432 destsa = destsa->next;
1435 else if (bad++ > 10) {
1437 "\nTest aborted after 10 failures\n\n");
1438 apr_err("apr_socket_connect()", rv);
1449 /* connected first time */
1450 set_conn_state(c, STATE_CONNECTED);
1453 ssl_proceed_handshake(c);
1461 /* --------------------------------------------------------- */
1463 /* close down connection and save stats */
1465 static void close_connection(struct connection * c)
1467 if (c->read == 0 && c->keepalive) {
1469 * server has legitimately shut down an idle keep alive request
1472 good--; /* connection never happened */
1476 /* first time here */
1479 else if ((c->bread != doclen) && !nolength) {
1484 if (done < requests) {
1485 struct data *s = &stats[done++];
1486 c->done = lasttime = apr_time_now();
1487 s->starttime = c->start;
1488 s->ctime = ap_max(0, c->connect - c->start);
1489 s->time = ap_max(0, c->done - c->start);
1490 s->waittime = ap_max(0, c->beginread - c->endwrite);
1491 if (heartbeatres && !(done % heartbeatres)) {
1492 fprintf(stderr, "Completed %d requests\n", done);
1498 set_conn_state(c, STATE_UNCONNECTED);
1501 SSL_shutdown(c->ssl);
1506 apr_socket_close(c->aprsock);
1513 /* --------------------------------------------------------- */
1515 /* read data from connection */
1517 static void read_connection(struct connection * c)
1520 apr_status_t status;
1522 char respcode[4]; /* 3 digits and null */
1529 status = SSL_read(c->ssl, buffer, r);
1531 int scode = SSL_get_error(c->ssl, status);
1533 if (scode == SSL_ERROR_ZERO_RETURN) {
1534 /* connection closed cleanly: */
1536 close_connection(c);
1538 else if (scode == SSL_ERROR_SYSCALL
1541 /* connection closed, but in violation of the protocol, after
1542 * some data has already been read; this commonly happens, so
1543 * let the length check catch any response errors
1546 close_connection(c);
1548 else if (scode == SSL_ERROR_SYSCALL
1551 && c->state == STATE_CONNECTING
1555 else if (scode == SSL_ERROR_WANT_READ) {
1556 set_polled_events(c, APR_POLLIN);
1558 else if (scode == SSL_ERROR_WANT_WRITE) {
1559 set_polled_events(c, APR_POLLOUT);
1562 /* some fatal error: */
1564 BIO_printf(bio_err, "SSL read failed (%d) - closing connection\n", scode);
1565 ERR_print_errors(bio_err);
1566 close_connection(c);
1575 status = apr_socket_recv(c->aprsock, buffer, &r);
1576 if (APR_STATUS_IS_EAGAIN(status))
1578 else if (r == 0 && APR_STATUS_IS_EOF(status)) {
1580 close_connection(c);
1583 /* catch legitimate fatal apr_socket_recv errors */
1584 else if (status != APR_SUCCESS) {
1588 close_connection(c);
1589 if (verbosity >= 1) {
1591 fprintf(stderr,"%s: %s (%d)\n", "apr_socket_recv", apr_strerror(status, buf, sizeof buf), status);
1594 } else if (destsa->next && c->state == STATE_CONNECTING
1595 && c->read == 0 && good == 0) {
1600 apr_err("apr_socket_recv", status);
1607 c->beginread = apr_time_now();
1612 if (!c->gotheader) {
1615 apr_size_t space = CBUFFSIZE - c->cbx - 1; /* -1 allows for \0 term */
1616 int tocopy = (space < r) ? space : r;
1618 apr_size_t inbytes_left = space, outbytes_left = space;
1620 status = apr_xlate_conv_buffer(from_ascii, buffer, &inbytes_left,
1621 c->cbuff + c->cbx, &outbytes_left);
1622 if (status || inbytes_left || outbytes_left) {
1623 fprintf(stderr, "only simple translation is supported (%d/%" APR_SIZE_T_FMT
1624 "/%" APR_SIZE_T_FMT ")\n", status, inbytes_left, outbytes_left);
1628 memcpy(c->cbuff + c->cbx, buffer, space);
1629 #endif /* NOT_ASCII */
1632 c->cbuff[c->cbx] = 0; /* terminate for benefit of strstr */
1633 if (verbosity >= 2) {
1634 printf("LOG: header received:\n%s\n", c->cbuff);
1636 s = strstr(c->cbuff, "\r\n\r\n");
1638 * this next line is so that we talk to NCSA 1.5 which blatantly
1639 * breaks the http specifaction
1642 s = strstr(c->cbuff, "\n\n");
1647 /* read rest next time */
1652 /* header is in invalid or too big - close connection */
1653 set_conn_state(c, STATE_UNCONNECTED);
1654 apr_socket_close(c->aprsock);
1657 err("\nTest aborted after 10 failures\n\n");
1663 /* have full header */
1666 * this is first time, extract some interesting info
1670 p = xstrcasestr(c->cbuff, "Server:");
1674 /* -1 to not overwrite last '\0' byte */
1675 while (*p > 32 && len++ < sizeof(servername) - 1)
1681 * XXX: this parsing isn't even remotely HTTP compliant... but in
1682 * the interest of speed it doesn't totally have to be, it just
1683 * needs to be extended to handle whatever servers folks want to
1684 * test against. -djg
1687 /* check response code */
1688 part = strstr(c->cbuff, "HTTP"); /* really HTTP/1.x_ */
1689 if (part && strlen(part) > strlen("HTTP/1.x_")) {
1690 strncpy(respcode, (part + strlen("HTTP/1.x_")), 3);
1694 strcpy(respcode, "500");
1697 if (respcode[0] != '2') {
1700 printf("WARNING: Response code not 2xx (%s)\n", respcode);
1702 else if (verbosity >= 3) {
1703 printf("LOG: Response code = %s\n", respcode);
1706 *s = 0; /* terminate at end of header */
1707 if (keepalive && xstrcasestr(c->cbuff, "Keep-Alive")) {
1710 cl = xstrcasestr(c->cbuff, "Content-Length:");
1711 if (cl && method != HEAD) {
1712 /* response to HEAD doesn't have entity body */
1713 c->length = atoi(cl + 16);
1719 c->bread += c->cbx - (s + l - c->cbuff) + r - tocopy;
1720 totalbread += c->bread;
1722 /* We have received the header, so we know this destination socket
1723 * address is working, so initialize all remaining requests. */
1724 if (!requests_initialized) {
1725 for (i = 1; i < concurrency; i++) {
1727 start_connect(&con[i]);
1729 requests_initialized = 1;
1734 /* outside header, everything we have read is entity body */
1738 if (r == sizeof(buffer) && c->bread < c->length) {
1739 /* read was full, try more immediately (nonblocking already) */
1743 if (c->keepalive && (c->bread >= c->length)) {
1744 /* finished a keep-alive connection */
1748 /* first time here */
1751 else if ((c->bread != doclen) && !nolength) {
1755 if (done < requests) {
1756 struct data *s = &stats[done++];
1758 c->done = apr_time_now();
1759 s->starttime = c->start;
1760 s->ctime = ap_max(0, c->connect - c->start);
1761 s->time = ap_max(0, c->done - c->start);
1762 s->waittime = ap_max(0, c->beginread - c->endwrite);
1763 if (heartbeatres && !(done % heartbeatres)) {
1764 fprintf(stderr, "Completed %d requests\n", done);
1772 c->read = c->bread = 0;
1773 /* zero connect time with keep-alive */
1774 c->start = c->connect = lasttime = apr_time_now();
1775 set_conn_state(c, STATE_CONNECTED);
1780 /* --------------------------------------------------------- */
1784 static void test(void)
1786 apr_time_t stoptime;
1790 apr_status_t status;
1791 int snprintf_res = 0;
1793 apr_size_t inbytes_left, outbytes_left;
1797 connecthost = apr_pstrdup(cntxt, proxyhost);
1798 connectport = proxyport;
1801 connecthost = apr_pstrdup(cntxt, hostname);
1806 printf("Benchmarking %s ", hostname);
1808 printf("[through %s:%d] ", proxyhost, proxyport);
1809 printf("(be patient)%s",
1810 (heartbeatres ? "\n" : "..."));
1814 con = xcalloc(concurrency, sizeof(struct connection));
1817 * XXX: a way to calculate the stats without requiring O(requests) memory
1818 * XXX: would be nice.
1820 stats = xcalloc(requests, sizeof(struct data));
1822 if ((status = apr_pollset_create(&readbits, concurrency, cntxt,
1823 APR_POLLSET_NOCOPY)) != APR_SUCCESS) {
1824 apr_err("apr_pollset_create failed", status);
1827 /* add default headers if necessary */
1829 /* Host: header not overridden, add default value to hdrs */
1830 hdrs = apr_pstrcat(cntxt, hdrs, "Host: ", host_field, colonhost, "\r\n", NULL);
1833 /* Header overridden, no need to add, as it is already in hdrs */
1837 if (is_ssl && tls_use_sni) {
1839 if (((tls_sni = opt_host) || (tls_sni = hostname)) &&
1840 (!*tls_sni || apr_ipsubnet_create(&ip, tls_sni, NULL,
1841 cntxt) == APR_SUCCESS)) {
1842 /* IP not allowed in TLS SNI extension */
1848 if (!opt_useragent) {
1849 /* User-Agent: header not overridden, add default value to hdrs */
1850 hdrs = apr_pstrcat(cntxt, hdrs, "User-Agent: ApacheBench/", AP_AB_BASEREVISION, "\r\n", NULL);
1853 /* Header overridden, no need to add, as it is already in hdrs */
1857 /* Accept: header not overridden, add default value to hdrs */
1858 hdrs = apr_pstrcat(cntxt, hdrs, "Accept: */*\r\n", NULL);
1861 /* Header overridden, no need to add, as it is already in hdrs */
1866 snprintf_res = apr_snprintf(request, sizeof(_request),
1867 "%s %s HTTP/1.0\r\n"
1871 (isproxy) ? fullurl : path,
1872 keepalive ? "Connection: Keep-Alive\r\n" : "",
1873 cookie, auth, hdrs);
1876 snprintf_res = apr_snprintf(request, sizeof(_request),
1877 "%s %s HTTP/1.0\r\n"
1879 "Content-length: %" APR_SIZE_T_FMT "\r\n"
1880 "Content-type: %s\r\n"
1884 (isproxy) ? fullurl : path,
1885 keepalive ? "Connection: Keep-Alive\r\n" : "",
1888 (content_type != NULL) ? content_type : "text/plain", hdrs);
1890 if (snprintf_res >= sizeof(_request)) {
1891 err("Request too long\n");
1895 printf("INFO: %s header == \n---\n%s\n---\n",
1896 method_str[method], request);
1898 reqlen = strlen(request);
1901 * Combine headers and (optional) post file into one continuous buffer
1904 char *buff = xmalloc(postlen + reqlen + 1);
1905 strcpy(buff, request);
1906 memcpy(buff + reqlen, postdata, postlen);
1911 inbytes_left = outbytes_left = reqlen;
1912 status = apr_xlate_conv_buffer(to_ascii, request, &inbytes_left,
1913 request, &outbytes_left);
1914 if (status || inbytes_left || outbytes_left) {
1915 fprintf(stderr, "only simple translation is supported (%d/%"
1916 APR_SIZE_T_FMT "/%" APR_SIZE_T_FMT ")\n",
1917 status, inbytes_left, outbytes_left);
1920 #endif /* NOT_ASCII */
1923 /* This only needs to be done once */
1924 if ((rv = apr_sockaddr_info_get(&mysa, myhost, APR_UNSPEC, 0, 0, cntxt)) != APR_SUCCESS) {
1926 apr_snprintf(buf, sizeof(buf),
1927 "apr_sockaddr_info_get() for %s", myhost);
1933 if ((rv = apr_sockaddr_info_get(&destsa, connecthost,
1934 myhost ? mysa->family : APR_UNSPEC,
1935 connectport, 0, cntxt))
1938 apr_snprintf(buf, sizeof(buf),
1939 "apr_sockaddr_info_get() for %s", connecthost);
1943 /* ok - lets start */
1944 start = lasttime = apr_time_now();
1945 stoptime = tlimit ? (start + apr_time_from_sec(tlimit)) : AB_MAX;
1948 /* Output the results if the user terminates the run early. */
1949 apr_signal(SIGINT, output_results);
1952 /* initialise first connection to determine destination socket address
1953 * which should be used for next connections. */
1955 start_connect(&con[0]);
1959 const apr_pollfd_t *pollresults, *pollfd;
1963 status = apr_pollset_poll(readbits, aprtimeout, &n, &pollresults);
1964 } while (APR_STATUS_IS_EINTR(status));
1965 if (status != APR_SUCCESS)
1966 apr_err("apr_pollset_poll", status);
1968 for (i = 0, pollfd = pollresults; i < n; i++, pollfd++) {
1969 struct connection *c;
1971 c = pollfd->client_data;
1974 * If the connection isn't connected how can we check it?
1976 if (c->state == STATE_UNCONNECTED)
1979 rtnev = pollfd->rtnevents;
1982 if (c->state == STATE_CONNECTED && c->ssl && SSL_in_init(c->ssl)) {
1983 ssl_proceed_handshake(c);
1989 * Notes: APR_POLLHUP is set after FIN is received on some
1990 * systems, so treat that like APR_POLLIN so that we try to read
1993 * Some systems return APR_POLLERR with APR_POLLHUP. We need to
1994 * call read_connection() for APR_POLLHUP, so check for
1995 * APR_POLLHUP first so that a closed connection isn't treated
1996 * like an I/O error. If it is, we never figure out that the
1997 * connection is done and we loop here endlessly calling
2000 if ((rtnev & APR_POLLIN) || (rtnev & APR_POLLPRI) || (rtnev & APR_POLLHUP))
2002 if ((rtnev & APR_POLLERR) || (rtnev & APR_POLLNVAL)) {
2003 if (destsa->next && c->state == STATE_CONNECTING && good == 0) {
2004 destsa = destsa->next;
2010 /* avoid apr_poll/EINPROGRESS loop on HP-UX, let recv discover ECONNREFUSED */
2011 if (c->state == STATE_CONNECTING) {
2020 if (rtnev & APR_POLLOUT) {
2021 if (c->state == STATE_CONNECTING) {
2022 /* call connect() again to detect errors */
2023 rv = apr_socket_connect(c->aprsock, destsa);
2024 if (rv != APR_SUCCESS) {
2025 set_conn_state(c, STATE_UNCONNECTED);
2026 apr_socket_close(c->aprsock);
2030 "\nTest aborted after 10 failures\n\n");
2031 apr_err("apr_socket_connect()", rv);
2037 set_conn_state(c, STATE_CONNECTED);
2040 ssl_proceed_handshake(c);
2047 /* POLLOUT is one shot */
2048 set_polled_events(c, APR_POLLIN);
2049 if (c->state == STATE_READ) {
2058 } while (lasttime < stoptime && done < requests);
2061 fprintf(stderr, "Finished %d requests\n", done);
2066 output_html_results();
2071 /* ------------------------------------------------------- */
2073 /* display copyright information */
2074 static void copyright(void)
2077 printf("This is ApacheBench, Version %s\n", AP_AB_BASEREVISION " <$Revision$>");
2078 printf("Copyright 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/\n");
2079 printf("Licensed to The Apache Software Foundation, http://www.apache.org/\n");
2084 printf(" This is ApacheBench, Version %s <i><%s></i><br>\n", AP_AB_BASEREVISION, "$Revision$");
2085 printf(" Copyright 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/<br>\n");
2086 printf(" Licensed to The Apache Software Foundation, http://www.apache.org/<br>\n");
2087 printf("</p>\n<p>\n");
2091 /* display usage information */
2092 static void usage(const char *progname)
2094 fprintf(stderr, "Usage: %s [options] [http"
2098 "://]hostname[:port]/path\n", progname);
2099 /* 80 column ruler: ********************************************************************************
2101 fprintf(stderr, "Options are:\n");
2102 fprintf(stderr, " -n requests Number of requests to perform\n");
2103 fprintf(stderr, " -c concurrency Number of multiple requests to make at a time\n");
2104 fprintf(stderr, " -t timelimit Seconds to max. to spend on benchmarking\n");
2105 fprintf(stderr, " This implies -n 50000\n");
2106 fprintf(stderr, " -s timeout Seconds to max. wait for each response\n");
2107 fprintf(stderr, " Default is 30 seconds\n");
2108 fprintf(stderr, " -b windowsize Size of TCP send/receive buffer, in bytes\n");
2109 fprintf(stderr, " -B address Address to bind to when making outgoing connections\n");
2110 fprintf(stderr, " -p postfile File containing data to POST. Remember also to set -T\n");
2111 fprintf(stderr, " -u putfile File containing data to PUT. Remember also to set -T\n");
2112 fprintf(stderr, " -T content-type Content-type header to use for POST/PUT data, eg.\n");
2113 fprintf(stderr, " 'application/x-www-form-urlencoded'\n");
2114 fprintf(stderr, " Default is 'text/plain'\n");
2115 fprintf(stderr, " -v verbosity How much troubleshooting info to print\n");
2116 fprintf(stderr, " -w Print out results in HTML tables\n");
2117 fprintf(stderr, " -i Use HEAD instead of GET\n");
2118 fprintf(stderr, " -x attributes String to insert as table attributes\n");
2119 fprintf(stderr, " -y attributes String to insert as tr attributes\n");
2120 fprintf(stderr, " -z attributes String to insert as td or th attributes\n");
2121 fprintf(stderr, " -C attribute Add cookie, eg. 'Apache=1234'. (repeatable)\n");
2122 fprintf(stderr, " -H attribute Add Arbitrary header line, eg. 'Accept-Encoding: gzip'\n");
2123 fprintf(stderr, " Inserted after all normal header lines. (repeatable)\n");
2124 fprintf(stderr, " -A attribute Add Basic WWW Authentication, the attributes\n");
2125 fprintf(stderr, " are a colon separated username and password.\n");
2126 fprintf(stderr, " -P attribute Add Basic Proxy Authentication, the attributes\n");
2127 fprintf(stderr, " are a colon separated username and password.\n");
2128 fprintf(stderr, " -X proxy:port Proxyserver and port number to use\n");
2129 fprintf(stderr, " -V Print version number and exit\n");
2130 fprintf(stderr, " -k Use HTTP KeepAlive feature\n");
2131 fprintf(stderr, " -d Do not show percentiles served table.\n");
2132 fprintf(stderr, " -S Do not show confidence estimators and warnings.\n");
2133 fprintf(stderr, " -q Do not show progress when doing more than 150 requests\n");
2134 fprintf(stderr, " -l Accept variable document length (use this for dynamic pages)\n");
2135 fprintf(stderr, " -g filename Output collected data to gnuplot format file.\n");
2136 fprintf(stderr, " -e filename Output CSV file with percentages served\n");
2137 fprintf(stderr, " -r Don't exit on socket receive errors.\n");
2138 fprintf(stderr, " -m method Method name\n");
2139 fprintf(stderr, " -h Display usage information (this message)\n");
2142 #ifndef OPENSSL_NO_SSL2
2143 #define SSL2_HELP_MSG "SSL2, "
2145 #define SSL2_HELP_MSG ""
2148 #ifndef OPENSSL_NO_SSL3
2149 #define SSL3_HELP_MSG "SSL3, "
2151 #define SSL3_HELP_MSG ""
2155 #define TLS1_X_HELP_MSG ", TLS1.1, TLS1.2"
2157 #define TLS1_X_HELP_MSG ""
2161 fprintf(stderr, " -I Disable TLS Server Name Indication (SNI) extension\n");
2163 fprintf(stderr, " -Z ciphersuite Specify SSL/TLS cipher suite (See openssl ciphers)\n");
2164 fprintf(stderr, " -f protocol Specify SSL/TLS protocol\n");
2165 fprintf(stderr, " (" SSL2_HELP_MSG SSL3_HELP_MSG "TLS1" TLS1_X_HELP_MSG " or ALL)\n");
2170 /* ------------------------------------------------------- */
2172 /* split URL into parts */
2174 static int parse_url(const char *url)
2181 /* Save a copy for the proxy */
2182 fullurl = apr_pstrdup(cntxt, url);
2184 if (strlen(url) > 7 && strncmp(url, "http://", 7) == 0) {
2192 if (strlen(url) > 8 && strncmp(url, "https://", 8) == 0) {
2197 if (strlen(url) > 8 && strncmp(url, "https://", 8) == 0) {
2198 fprintf(stderr, "SSL not compiled in; no https support\n");
2203 if ((cp = strchr(url, '/')) == NULL)
2205 h = apr_pstrmemdup(cntxt, url, cp - url);
2206 rv = apr_parse_addr_port(&hostname, &scope_id, &port, h, cntxt);
2207 if (rv != APR_SUCCESS || !hostname || scope_id) {
2210 path = apr_pstrdup(cntxt, cp);
2212 if (*url == '[') { /* IPv6 numeric address string */
2213 host_field = apr_psprintf(cntxt, "[%s]", hostname);
2216 host_field = hostname;
2219 if (port == 0) { /* no port specified */
2230 is_ssl && (port != 443)) || (!is_ssl &&
2234 colonhost = apr_psprintf(cntxt,":%d",port);
2240 /* ------------------------------------------------------- */
2242 /* read data to POST/PUT from file, save contents and length */
2244 static apr_status_t open_postfile(const char *pfile)
2251 rv = apr_file_open(&postfd, pfile, APR_READ, APR_OS_DEFAULT, cntxt);
2252 if (rv != APR_SUCCESS) {
2253 fprintf(stderr, "ab: Could not open POST data file (%s): %s\n", pfile,
2254 apr_strerror(rv, errmsg, sizeof errmsg));
2258 rv = apr_file_info_get(&finfo, APR_FINFO_NORM, postfd);
2259 if (rv != APR_SUCCESS) {
2260 fprintf(stderr, "ab: Could not stat POST data file (%s): %s\n", pfile,
2261 apr_strerror(rv, errmsg, sizeof errmsg));
2264 postlen = (apr_size_t)finfo.size;
2265 postdata = xmalloc(postlen);
2266 rv = apr_file_read_full(postfd, postdata, postlen, NULL);
2267 if (rv != APR_SUCCESS) {
2268 fprintf(stderr, "ab: Could not read POST data file: %s\n",
2269 apr_strerror(rv, errmsg, sizeof errmsg));
2272 apr_file_close(postfd);
2276 /* ------------------------------------------------------- */
2278 /* sort out command-line args and call test */
2279 int main(int argc, const char * const argv[])
2283 apr_status_t status;
2285 const char *opt_arg;
2287 #if OPENSSL_VERSION_NUMBER >= 0x10100000L
2288 int max_prot = TLS1_2_VERSION;
2289 #ifndef OPENSSL_NO_SSL3
2290 int min_prot = SSL3_VERSION;
2292 int min_prot = TLS1_VERSION;
2294 #endif /* #if OPENSSL_VERSION_NUMBER >= 0x10100000L */
2296 AB_SSL_METHOD_CONST SSL_METHOD *meth = SSLv23_client_method();
2299 /* table defaults */
2302 tdstring = "bgcolor=white";
2308 apr_app_initialize(&argc, &argv, NULL);
2309 atexit(apr_terminate);
2310 apr_pool_create(&cntxt, NULL);
2311 apr_pool_abort_set(abort_on_oom, cntxt);
2314 status = apr_xlate_open(&to_ascii, "ISO-8859-1", APR_DEFAULT_CHARSET, cntxt);
2316 fprintf(stderr, "apr_xlate_open(to ASCII)->%d\n", status);
2319 status = apr_xlate_open(&from_ascii, APR_DEFAULT_CHARSET, "ISO-8859-1", cntxt);
2321 fprintf(stderr, "apr_xlate_open(from ASCII)->%d\n", status);
2324 status = apr_base64init_ebcdic(to_ascii, from_ascii);
2326 fprintf(stderr, "apr_base64init_ebcdic()->%d\n", status);
2331 myhost = NULL; /* 0.0.0.0 or :: */
2333 apr_getopt_init(&opt, cntxt, argc, argv);
2334 while ((status = apr_getopt(opt, "n:c:t:s:b:T:p:u:v:lrkVhwiIx:y:z:C:H:P:A:g:X:de:SqB:m:"
2338 ,&c, &opt_arg)) == APR_SUCCESS) {
2341 requests = atoi(opt_arg);
2342 if (requests <= 0) {
2343 err("Invalid number of requests\n");
2353 concurrency = atoi(opt_arg);
2356 windowsize = atoi(opt_arg);
2359 if (method != NO_METH)
2360 err("Cannot mix HEAD with other methods\n");
2364 gnuplot = xstrdup(opt_arg);
2370 csvperc = xstrdup(opt_arg);
2376 aprtimeout = apr_time_from_sec(atoi(opt_arg)); /* timeout value */
2379 if (method != NO_METH)
2380 err("Cannot mix POST with other methods\n");
2381 if (open_postfile(opt_arg) != APR_SUCCESS) {
2388 if (method != NO_METH)
2389 err("Cannot mix PUT with other methods\n");
2390 if (open_postfile(opt_arg) != APR_SUCCESS) {
2403 verbosity = atoi(opt_arg);
2406 tlimit = atoi(opt_arg);
2407 requests = MAX_REQUESTS; /* need to size data array on
2411 content_type = apr_pstrdup(cntxt, opt_arg);
2414 cookie = apr_pstrcat(cntxt, "Cookie: ", opt_arg, "\r\n", NULL);
2418 * assume username passwd already to be in colon separated form.
2419 * Ready to be uu-encoded.
2421 while (apr_isspace(*opt_arg))
2423 if (apr_base64_encode_len(strlen(opt_arg)) > sizeof(tmp)) {
2424 err("Authentication credentials too long\n");
2426 l = apr_base64_encode(tmp, opt_arg, strlen(opt_arg));
2429 auth = apr_pstrcat(cntxt, auth, "Authorization: Basic ", tmp,
2434 * assume username passwd already to be in colon separated form.
2436 while (apr_isspace(*opt_arg))
2438 if (apr_base64_encode_len(strlen(opt_arg)) > sizeof(tmp)) {
2439 err("Proxy credentials too long\n");
2441 l = apr_base64_encode(tmp, opt_arg, strlen(opt_arg));
2444 auth = apr_pstrcat(cntxt, auth, "Proxy-Authorization: Basic ",
2448 hdrs = apr_pstrcat(cntxt, hdrs, opt_arg, "\r\n", NULL);
2450 * allow override of some of the common headers that ab adds
2452 if (strncasecmp(opt_arg, "Host:", 5) == 0) {
2456 while (apr_isspace(*opt_arg))
2458 len = strlen(opt_arg);
2459 host = strdup(opt_arg);
2460 while (len && apr_isspace(host[len-1]))
2463 } else if (strncasecmp(opt_arg, "Accept:", 7) == 0) {
2465 } else if (strncasecmp(opt_arg, "User-Agent:", 11) == 0) {
2473 * if any of the following three are used, turn on html output
2478 tablestring = opt_arg;
2484 * assume proxy-name[:port]
2486 if ((p = strchr(opt_arg, ':'))) {
2489 proxyport = atoi(p);
2491 proxyhost = apr_pstrdup(cntxt, opt_arg);
2510 myhost = apr_pstrdup(cntxt, opt_arg);
2513 method = CUSTOM_METHOD;
2514 method_str[CUSTOM_METHOD] = strdup(opt_arg);
2518 ssl_cipher = strdup(opt_arg);
2521 #if OPENSSL_VERSION_NUMBER < 0x10100000L
2522 if (strncasecmp(opt_arg, "ALL", 3) == 0) {
2523 meth = SSLv23_client_method();
2524 #ifndef OPENSSL_NO_SSL2
2525 } else if (strncasecmp(opt_arg, "SSL2", 4) == 0) {
2526 meth = SSLv2_client_method();
2531 #ifndef OPENSSL_NO_SSL3
2532 } else if (strncasecmp(opt_arg, "SSL3", 4) == 0) {
2533 meth = SSLv3_client_method();
2539 } else if (strncasecmp(opt_arg, "TLS1.1", 6) == 0) {
2540 meth = TLSv1_1_client_method();
2541 } else if (strncasecmp(opt_arg, "TLS1.2", 6) == 0) {
2542 meth = TLSv1_2_client_method();
2544 } else if (strncasecmp(opt_arg, "TLS1", 4) == 0) {
2545 meth = TLSv1_client_method();
2547 #else /* #if OPENSSL_VERSION_NUMBER < 0x10100000L */
2548 meth = TLS_client_method();
2549 if (strncasecmp(opt_arg, "ALL", 3) == 0) {
2550 max_prot = TLS1_2_VERSION;
2551 #ifndef OPENSSL_NO_SSL3
2552 min_prot = SSL3_VERSION;
2554 min_prot = TLS1_VERSION;
2556 #ifndef OPENSSL_NO_SSL3
2557 } else if (strncasecmp(opt_arg, "SSL3", 4) == 0) {
2558 max_prot = SSL3_VERSION;
2559 min_prot = SSL3_VERSION;
2561 } else if (strncasecmp(opt_arg, "TLS1.1", 6) == 0) {
2562 max_prot = TLS1_1_VERSION;
2563 min_prot = TLS1_1_VERSION;
2564 } else if (strncasecmp(opt_arg, "TLS1.2", 6) == 0) {
2565 max_prot = TLS1_2_VERSION;
2566 min_prot = TLS1_2_VERSION;
2567 } else if (strncasecmp(opt_arg, "TLS1", 4) == 0) {
2568 max_prot = TLS1_VERSION;
2569 min_prot = TLS1_VERSION;
2571 #endif /* #if OPENSSL_VERSION_NUMBER < 0x10100000L */
2582 if (opt->ind != argc - 1) {
2583 fprintf(stderr, "%s: wrong number of arguments\n", argv[0]);
2587 if (method == NO_METH) {
2591 if (parse_url(apr_pstrdup(cntxt, opt->argv[opt->ind++]))) {
2592 fprintf(stderr, "%s: invalid URL\n", argv[0]);
2596 if ((concurrency < 0) || (concurrency > MAX_CONCURRENCY)) {
2597 fprintf(stderr, "%s: Invalid Concurrency [Range 0..%d]\n",
2598 argv[0], MAX_CONCURRENCY);
2602 if (concurrency > requests) {
2603 fprintf(stderr, "%s: Cannot use concurrency level greater than "
2604 "total number of requests\n", argv[0]);
2608 if ((heartbeatres) && (requests > 150)) {
2609 heartbeatres = requests / 10; /* Print line every 10% of requests */
2610 if (heartbeatres < 100)
2611 heartbeatres = 100; /* but never more often than once every 100
2621 #if OPENSSL_VERSION_NUMBER < 0x10100000L
2622 CRYPTO_malloc_init();
2625 SSL_load_error_strings();
2627 bio_out=BIO_new_fp(stdout,BIO_NOCLOSE);
2628 bio_err=BIO_new_fp(stderr,BIO_NOCLOSE);
2630 if (!(ssl_ctx = SSL_CTX_new(meth))) {
2631 BIO_printf(bio_err, "Could not initialize SSL Context.\n");
2632 ERR_print_errors(bio_err);
2635 SSL_CTX_set_options(ssl_ctx, SSL_OP_ALL);
2636 #if OPENSSL_VERSION_NUMBER >= 0x10100000L
2637 SSL_CTX_set_max_proto_version(ssl_ctx, max_prot);
2638 SSL_CTX_set_min_proto_version(ssl_ctx, min_prot);
2640 #ifdef SSL_MODE_RELEASE_BUFFERS
2641 /* Keep memory usage as low as possible */
2642 SSL_CTX_set_mode (ssl_ctx, SSL_MODE_RELEASE_BUFFERS);
2644 if (ssl_cipher != NULL) {
2645 if (!SSL_CTX_set_cipher_list(ssl_ctx, ssl_cipher)) {
2646 fprintf(stderr, "error setting cipher list [%s]\n", ssl_cipher);
2647 ERR_print_errors_fp(stderr);
2651 if (verbosity >= 3) {
2652 SSL_CTX_set_info_callback(ssl_ctx, ssl_state_cb);
2656 apr_signal(SIGPIPE, SIG_IGN); /* Ignore writes to connections that
2657 * have been closed at the other end. */
2661 apr_pool_destroy(cntxt);