1 /* ====================================================================
2 * The Apache Software License, Version 1.1
4 * Copyright (c) 2000 The Apache Software Foundation. All rights
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
11 * 1. Redistributions of source code must retain the above copyright
12 * notice, this list of conditions and the following disclaimer.
14 * 2. Redistributions in binary form must reproduce the above copyright
15 * notice, this list of conditions and the following disclaimer in
16 * the documentation and/or other materials provided with the
19 * 3. The end-user documentation included with the redistribution,
20 * if any, must include the following acknowledgment:
21 * "This product includes software developed by the
22 * Apache Software Foundation (http://www.apache.org/)."
23 * Alternately, this acknowledgment may appear in the software itself,
24 * if and wherever such third-party acknowledgments normally appear.
26 * 4. The names "Apache" and "Apache Software Foundation" must
27 * not be used to endorse or promote products derived from this
28 * software without prior written permission. For written
29 * permission, please contact apache@apache.org.
31 * 5. Products derived from this software may not be called "Apache",
32 * nor may "Apache" appear in their name, without prior written
33 * permission of the Apache Software Foundation.
35 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
36 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
37 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
38 * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
39 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
40 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
41 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
42 * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
43 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
44 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
45 * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
47 * ====================================================================
49 * This software consists of voluntary contributions made by many
50 * individuals on behalf of the Apache Software Foundation. For more
51 * information on the Apache Software Foundation, please see
52 * <http://www.apache.org/>.
54 * Portions of this software are based upon public domain software
55 * originally written at the National Center for Supercomputing Applications,
56 * University of Illinois, Urbana-Champaign.
60 ** This program is based on ZeusBench V1.0 written by Adam Twiss
61 ** which is Copyright (c) 1996 by Zeus Technology Ltd. http://www.zeustech.net/
63 ** This software is provided "as is" and any express or implied waranties,
64 ** including but not limited to, the implied warranties of merchantability and
65 ** fitness for a particular purpose are disclaimed. In no event shall
66 ** Zeus Technology Ltd. be liable for any direct, indirect, incidental, special,
67 ** exemplary, or consequential damaged (including, but not limited to,
68 ** procurement of substitute good or services; loss of use, data, or profits;
69 ** or business interruption) however caused and on theory of liability. Whether
70 ** in contract, strict liability or tort (including negligence or otherwise)
71 ** arising in any way out of the use of this software, even if advised of the
72 ** possibility of such damage.
78 ** - Originally written by Adam Twiss <adam@zeus.co.uk>, March 1996
79 ** with input from Mike Belshe <mbelshe@netscape.com> and
80 ** Michael Campanella <campanella@stevms.enet.dec.com>
81 ** - Enhanced by Dean Gaudet <dgaudet@apache.org>, November 1997
82 ** - Cleaned up by Ralf S. Engelschall <rse@apache.org>, March 1998
83 ** - POST and verbosity by Kurt Sussman <kls@merlot.com>, August 1998
84 ** - HTML table output added by David N. Welton <davidw@prosa.it>, January 1999
85 ** - Added Cookie, Arbitrary header and auth support. <dirkx@webweaving.org>, April 199
93 * - has various other poor buffer attacks related to the lazy parsing of
94 * response headers from the server
95 * - doesn't implement much of HTTP/1.x, only accepts certain forms of
97 * - (performance problem) heavy use of strstr shows up top in profile
98 * only an issue for loopback usage
101 #define VERSION "1.3c"
103 /* -------------------------------------------------------------------- */
106 /* Hmmm... This source code isn't being compiled in ASCII.
107 * In order for data that flows over the network to make
108 * sense, we need to translate to/from ASCII.
113 /* affects include files on Solaris */
116 #include "apr_network_io.h"
117 #include "apr_file_io.h"
118 #include "apr_time.h"
119 #include "apr_getopt.h"
121 #include "apr_xlate.h"
127 /* ------------------- DEFINITIONS -------------------------- */
129 /* maximum number of requests on a time limited test */
130 #define MAX_REQUESTS 50000
132 /* good old state hostname */
133 #define STATE_UNCONNECTED 0
134 #define STATE_CONNECTING 1
137 #define CBUFFSIZE 512
140 ap_socket_t *aprsock;
142 int read; /* amount of bytes read */
143 int bread; /* amount of body read */
144 int length; /* Content-Length value used for keep-alive */
145 char cbuff[CBUFFSIZE]; /* a buffer to store server response header */
146 int cbx; /* offset in cbuffer */
147 int keepalive; /* non-zero if a keep-alive request */
148 int gotheader; /* non-zero if we have the entire header in
150 ap_time_t start, connect, done;
155 int read; /* number of bytes read */
156 int ctime; /* time in ms to connect */
157 int time; /* time in ms for connection */
160 #define ap_min(a,b) ((a)<(b))?(a):(b)
161 #define ap_max(a,b) ((a)>(b))?(a):(b)
163 /* --------------------- GLOBALS ---------------------------- */
164 API_VAR_IMPORT char *ap_optarg; /* argument associated with option */
165 API_VAR_IMPORT int ap_optind;
167 int verbosity = 0; /* no verbosity by default */
168 int posting = 0; /* GET by default */
169 int requests = 1; /* Number of requests to make */
170 int concurrency = 1; /* Number of multiple requests to make */
171 int tlimit = 0; /* time limit in cs */
172 int keepalive = 0; /* try and do keepalive connections */
173 char servername[1024]; /* name that server reports */
174 char hostname[1024]; /* host name */
175 char path[1024]; /* path name */
176 char postfile[1024]; /* name of file containing post data */
177 char *postdata; /* *buffer containing data from postfile */
178 ap_ssize_t postlen = 0; /* length of data to be POSTed */
179 char content_type[1024]; /* content type to put in POST header */
180 char cookie[1024], /* optional cookie line */
181 auth[1024], /* optional (basic/uuencoded)
182 * authentification */
183 hdrs[4096]; /* optional arbitrary headers */
184 int port = 80; /* port number */
185 time_t aprtimeout = 30 * AP_USEC_PER_SEC; /* timeout value */
187 int use_html = 0; /* use html in the report */
192 int doclen = 0; /* the length the document should be */
193 int totalread = 0; /* total number of bytes read */
194 int totalbread = 0; /* totoal amount of entity body read */
195 int totalposted = 0; /* total number of bytes posted, inc. headers */
196 int done = 0; /* number of requests we have done */
197 int doneka = 0; /* number of keep alive connections done */
198 int good = 0, bad = 0; /* number of good and bad requests */
200 /* store error cases */
201 int err_length = 0, err_conn = 0, err_except = 0;
202 int err_response = 0;
204 ap_time_t start, endtime;
206 /* global request (and its length) */
210 /* one global throw-away buffer to read stuff into */
213 struct connection *con; /* connection array */
214 struct data *stats; /* date for each request */
217 ap_pollfd_t *readbits;
219 ap_xlate_t *fromascii, *toascii;
222 /* --------------------------------------------------------- */
224 /* simple little function to perror and exit */
226 static void err(char *s)
237 /* --------------------------------------------------------- */
239 /* write out request to a connection - assumes we can write
240 (small) request out in one go into our new socket buffer */
242 static void write_request(struct connection *c)
244 ap_ssize_t len = reqlen;
245 c->connect = ap_now();
246 ap_setsocketopt(c->aprsock, APR_SO_TIMEOUT, 30 * AP_USEC_PER_SEC);
247 if (ap_send(c->aprsock, request, &reqlen) != APR_SUCCESS ||
249 printf("Send request failed!\n");
252 ap_send(c->aprsock, postdata, &postlen);
253 totalposted += (reqlen + postlen);
256 c->state = STATE_READ;
257 ap_add_poll_socket(readbits, c->aprsock, APR_POLLIN);
258 ap_remove_poll_socket(readbits, c->aprsock);
261 /* --------------------------------------------------------- */
263 /* calculate and output results */
265 static void output_results(void)
270 timetaken = (endtime - start) / 1000;
273 printf("Server Software: %s\n", servername);
274 printf("Server Hostname: %s\n", hostname);
275 printf("Server Port: %d\n", port);
277 printf("Document Path: %s\n", path);
278 printf("Document Length: %d bytes\n", doclen);
280 printf("Concurrency Level: %d\n", concurrency);
281 printf("Time taken for tests: %d.%03d seconds\n",
282 timetaken / 1000, timetaken % 1000);
283 printf("Complete requests: %d\n", done);
284 printf("Failed requests: %d\n", bad);
286 printf(" (Connect: %d, Length: %d, Exceptions: %d)\n",
287 err_conn, err_length, err_except);
289 printf("Non-2xx responses: %d\n", err_response);
291 printf("Keep-Alive requests: %d\n", doneka);
292 printf("Total transferred: %d bytes\n", totalread);
294 printf("Total POSTed: %d\n", totalposted);
295 printf("HTML transferred: %d bytes\n", totalbread);
297 /* avoid divide by zero */
299 printf("Requests per second: %.2f\n", 1000 * (float) (done) / timetaken);
300 printf("Transfer rate: %.2f kb/s received\n",
301 (float) (totalread) / timetaken);
303 printf(" %.2f kb/s sent\n",
304 (float) (totalposted) / timetaken);
305 printf(" %.2f kb/s total\n",
306 (float) (totalread + totalposted) / timetaken);
311 /* work out connection times */
313 int totalcon = 0, total = 0;
314 int mincon = 9999999, mintot = 999999;
315 int maxcon = 0, maxtot = 0;
317 for (i = 0; i < requests; i++) {
318 struct data s = stats[i];
319 mincon = ap_min(mincon, s.ctime);
320 mintot = ap_min(mintot, s.time);
321 maxcon = ap_max(maxcon, s.ctime);
322 maxtot = ap_max(maxtot, s.time);
326 if (requests > 0) { /* avoid division by zero (if 0 requests) */
327 printf("\nConnnection Times (ms)\n");
328 printf(" min avg max\n");
329 printf("Connect: %5d %5d %5d\n", mincon, totalcon / requests, maxcon);
330 printf("Processing: %5d %5d %5d\n",
331 mintot - mincon, (total / requests) - (totalcon / requests),
333 printf("Total: %5d %5d %5d\n", mintot, total / requests, maxtot);
338 /* --------------------------------------------------------- */
340 /* calculate and output results in HTML */
342 static void output_html_results(void)
347 timetaken = (endtime - start) / 1000;
349 printf("\n\n<table %s>\n", tablestring);
350 printf("<tr %s><th colspan=2 %s>Server Software:</th>"
351 "<td colspan=2 %s>%s</td></tr>\n",
352 trstring, tdstring, tdstring, servername);
353 printf("<tr %s><th colspan=2 %s>Server Hostname:</th>"
354 "<td colspan=2 %s>%s</td></tr>\n",
355 trstring, tdstring, tdstring, hostname);
356 printf("<tr %s><th colspan=2 %s>Server Port:</th>"
357 "<td colspan=2 %s>%d</td></tr>\n",
358 trstring, tdstring, tdstring, port);
359 printf("<tr %s><th colspan=2 %s>Document Path:</th>"
360 "<td colspan=2 %s>%s</td></tr>\n",
361 trstring, tdstring, tdstring, path);
362 printf("<tr %s><th colspan=2 %s>Document Length:</th>"
363 "<td colspan=2 %s>%d bytes</td></tr>\n",
364 trstring, tdstring, tdstring, doclen);
365 printf("<tr %s><th colspan=2 %s>Concurrency Level:</th>"
366 "<td colspan=2 %s>%d</td></tr>\n",
367 trstring, tdstring, tdstring, concurrency);
368 printf("<tr %s><th colspan=2 %s>Time taken for tests:</th>"
369 "<td colspan=2 %s>%d.%03d seconds</td></tr>\n",
370 trstring, tdstring, tdstring, timetaken / 1000, timetaken % 1000);
371 printf("<tr %s><th colspan=2 %s>Complete requests:</th>"
372 "<td colspan=2 %s>%d</td></tr>\n",
373 trstring, tdstring, tdstring, done);
374 printf("<tr %s><th colspan=2 %s>Failed requests:</th>"
375 "<td colspan=2 %s>%d</td></tr>\n",
376 trstring, tdstring, tdstring, bad);
378 printf("<tr %s><td colspan=4 %s > (Connect: %d, Length: %d, Exceptions: %d)</td></tr>\n",
379 trstring, tdstring, err_conn, err_length, err_except);
381 printf("<tr %s><th colspan=2 %s>Non-2xx responses:</th>"
382 "<td colspan=2 %s>%d</td></tr>\n",
383 trstring, tdstring, tdstring, err_response);
385 printf("<tr %s><th colspan=2 %s>Keep-Alive requests:</th>"
386 "<td colspan=2 %s>%d</td></tr>\n",
387 trstring, tdstring, tdstring, doneka);
388 printf("<tr %s><th colspan=2 %s>Total transferred:</th>"
389 "<td colspan=2 %s>%d bytes</td></tr>\n",
390 trstring, tdstring, tdstring, totalread);
392 printf("<tr %s><th colspan=2 %s>Total POSTed:</th>"
393 "<td colspan=2 %s>%d</td></tr>\n",
394 trstring, tdstring, tdstring, totalposted);
395 printf("<tr %s><th colspan=2 %s>HTML transferred:</th>"
396 "<td colspan=2 %s>%d bytes</td></tr>\n",
397 trstring, tdstring, tdstring, totalbread);
399 /* avoid divide by zero */
401 printf("<tr %s><th colspan=2 %s>Requests per second:</th>"
402 "<td colspan=2 %s>%.2f</td></tr>\n",
403 trstring, tdstring, tdstring, 1000 * (float) (done) / timetaken);
404 printf("<tr %s><th colspan=2 %s>Transfer rate:</th>"
405 "<td colspan=2 %s>%.2f kb/s received</td></tr>\n",
406 trstring, tdstring, tdstring, (float) (totalread) / timetaken);
408 printf("<tr %s><td colspan=2 %s> </td>"
409 "<td colspan=2 %s>%.2f kb/s sent</td></tr>\n",
410 trstring, tdstring, tdstring,
411 (float) (totalposted) / timetaken);
412 printf("<tr %s><td colspan=2 %s> </td>"
413 "<td colspan=2 %s>%.2f kb/s total</td></tr>\n",
414 trstring, tdstring, tdstring,
415 (float) (totalread + totalposted) / timetaken);
420 /* work out connection times */
422 int totalcon = 0, total = 0;
423 int mincon = 9999999, mintot = 999999;
424 int maxcon = 0, maxtot = 0;
426 for (i = 0; i < requests; i++) {
427 struct data s = stats[i];
428 mincon = ap_min(mincon, s.ctime);
429 mintot = ap_min(mintot, s.time);
430 maxcon = ap_max(maxcon, s.ctime);
431 maxtot = ap_max(maxtot, s.time);
436 if (requests > 0) { /* avoid division by zero (if 0 requests) */
437 printf("<tr %s><th %s colspan=4>Connnection Times (ms)</th></tr>\n",
439 printf("<tr %s><th %s> </th> <th %s>min</th> <th %s>avg</th> <th %s>max</th></tr>\n",
440 trstring, tdstring, tdstring, tdstring, tdstring);
441 printf("<tr %s><th %s>Connect:</th>"
444 "<td %s>%5d</td></tr>\n",
445 trstring, tdstring, tdstring, mincon, tdstring, totalcon / requests, tdstring, maxcon);
446 printf("<tr %s><th %s>Processing:</th>"
449 "<td %s>%5d</td></tr>\n",
450 trstring, tdstring, tdstring, mintot - mincon, tdstring,
451 (total / requests) - (totalcon / requests), tdstring, maxtot - maxcon);
452 printf("<tr %s><th %s>Total:</th>"
455 "<td %s>%5d</td></tr>\n",
456 trstring, tdstring, tdstring, mintot, tdstring, total / requests, tdstring, maxtot);
458 printf("</table>\n");
462 /* --------------------------------------------------------- */
464 /* start asnchronous non-blocking connection */
466 static void start_connect(struct connection *c)
474 if (ap_create_tcp_socket(&c->aprsock, cntxt) != APR_SUCCESS) {
478 if (ap_connect(c->aprsock, hostname) != APR_SUCCESS) {
479 if (errno == APR_EINPROGRESS) {
480 c->state = STATE_CONNECTING;
481 ap_add_poll_socket(readbits, c->aprsock, APR_POLLOUT);
485 /* we done't have to close the socket. If we have an error this
486 * bad, ap_connect will destroy it for us.
490 err("\nTest aborted after 10 failures\n\n");
496 /* connected first time */
500 /* --------------------------------------------------------- */
502 /* close down connection and save stats */
504 static void close_connection(struct connection *c)
506 if (c->read == 0 && c->keepalive) {
507 /* server has legitimately shut down an idle keep alive request */
508 good--; /* connection never happend */
512 /* first time here */
515 else if (c->bread != doclen) {
520 if (done < requests) {
524 s.ctime = (c->connect - c->start) / 1000;
525 s.time = (c->done - c->start) / 1000;
530 ap_remove_poll_socket(readbits, c->aprsock);
531 ap_close_socket(c->aprsock);
538 /* --------------------------------------------------------- */
540 /* read data from connection */
542 static void read_connection(struct connection *c)
547 char respcode[4]; /* 3 digits and null */
550 ap_setsocketopt(c->aprsock, APR_SO_TIMEOUT, aprtimeout);
551 status = ap_recv(c->aprsock, buffer, &r);
552 if (r == 0 || (status != 0 && ap_canonical_error(status) != APR_EAGAIN)) {
558 if (ap_canonical_error(status) == EAGAIN)
567 int space = CBUFFSIZE - c->cbx - 1; /* -1 to allow for 0 terminator */
568 int tocopy = (space < r) ? space : r;
570 ap_size_t inbytes_left = space, outbytes_left = space;
572 status = ap_xlate_conv_buffer(fromascii, buffer, &inbytes_left,
573 c->cbuff + c->cbx, &outbytes_left);
574 if (status || inbytes_left || outbytes_left) {
575 fprintf(stderr, "only simple translation is supported (%d/%u/%u)\n",
576 status, inbytes_left, outbytes_left);
580 memcpy(c->cbuff + c->cbx, buffer, space);
581 #endif /*NOT_ASCII */
584 c->cbuff[c->cbx] = 0; /* terminate for benefit of strstr */
585 if (verbosity >= 4) {
586 printf("LOG: header received:\n%s\n", c->cbuff);
588 s = strstr(c->cbuff, "\r\n\r\n");
589 /* this next line is so that we talk to NCSA 1.5 which blatantly
590 * breaks the http specifaction
593 s = strstr(c->cbuff, "\n\n");
598 /* read rest next time */
603 /* header is in invalid or too big - close connection */
604 ap_remove_poll_socket(readbits, c->aprsock);
605 ap_close_socket(c->aprsock);
607 err("\nTest aborted after 10 failures\n\n");
613 /* have full header */
615 /* this is first time, extract some interesting info */
617 p = strstr(c->cbuff, "Server:");
627 /* XXX: this parsing isn't even remotely HTTP compliant...
628 * but in the interest of speed it doesn't totally have to be,
629 * it just needs to be extended to handle whatever servers
630 * folks want to test against. -djg */
632 /* check response code */
633 part = strstr(c->cbuff, "HTTP"); /* really HTTP/1.x_ */
634 strncpy(respcode, (part + strlen("HTTP/1.x_")), 3);
636 if (respcode[0] != '2') {
639 printf("WARNING: Response code not 2xx (%s)\n", respcode);
641 else if (verbosity >= 3) {
642 printf("LOG: Response code = %s\n", respcode);
646 *s = 0; /* terminate at end of header */
648 (strstr(c->cbuff, "Keep-Alive")
649 || strstr(c->cbuff, "keep-alive"))) { /* for benefit of MSIIS */
651 cl = strstr(c->cbuff, "Content-Length:");
652 /* handle NCSA, which sends Content-length: */
654 cl = strstr(c->cbuff, "Content-length:");
657 c->length = atoi(cl + 16);
660 c->bread += c->cbx - (s + l - c->cbuff) + r - tocopy;
661 totalbread += c->bread;
665 /* outside header, everything we have read is entity body */
670 if (c->keepalive && (c->bread >= c->length)) {
671 /* finished a keep-alive connection */
676 /* first time here */
679 else if (c->bread != doclen) {
683 if (done < requests) {
687 s.ctime = (c->connect - c->start) / 1000;
688 s.time = (c->done - c->start) / 1000;
695 c->read = c->bread = 0;
697 c->start = c->connect; /* zero connect time with keep-alive */
701 /* --------------------------------------------------------- */
705 static void test(void)
708 ap_interval_time_t timeout;
713 ap_size_t inbytes_left, outbytes_left;
717 printf("Benchmarking %s (be patient)...", hostname);
723 con = malloc(concurrency * sizeof(struct connection));
724 memset(con, 0, concurrency * sizeof(struct connection));
726 stats = malloc(requests * sizeof(struct data));
727 ap_setup_poll(&readbits, concurrency, cntxt);
731 sprintf(request, "%s %s HTTP/1.0\r\n"
732 "User-Agent: ApacheBench/%s\r\n"
737 (posting == 0) ? "GET" : "HEAD",
740 keepalive ? "Connection: Keep-Alive\r\n" : "",
741 cookie, auth, hostname, hdrs);
744 sprintf(request, "POST %s HTTP/1.0\r\n"
745 "User-Agent: ApacheBench/%s\r\n"
749 "Content-length: %d\r\n"
750 "Content-type: %s\r\n"
755 keepalive ? "Connection: Keep-Alive\r\n" : "",
758 (content_type[0]) ? content_type : "text/plain", hdrs);
762 printf("INFO: POST header == \n---\n%s\n---\n", request);
764 reqlen = strlen(request);
767 inbytes_left = outbytes_left = reqlen;
768 status = ap_xlate_conv_buffer(toascii, request, &inbytes_left,
769 request, &outbytes_left);
770 if (status || inbytes_left || outbytes_left) {
771 fprintf(stderr, "only simple translation is supported (%d/%u/%u)\n",
772 status, inbytes_left, outbytes_left);
777 /* ok - lets start */
780 /* initialise lots of requests */
781 for (i = 0; i < concurrency; i++) {
783 start_connect(&con[i]);
786 while (done < requests) {
790 /* check for time limit expiry */
792 timed = (now - start) / AP_USEC_PER_SEC;
793 if (tlimit && timed > (tlimit * 1000)) {
794 requests = done; /* so stats are correct */
796 /* Timeout of 30 seconds. */
797 timeout = 30 * AP_USEC_PER_SEC;
800 ap_poll(readbits, &n, timeout);
803 err("\nServer timed out\n\n");
808 for (i = 0; i < concurrency; i++) {
809 ap_get_revents(&rv, con[i].aprsock, readbits);
811 /* Note: APR_POLLHUP is set after FIN is received on some
812 * systems, so treat that like APR_POLLIN so that we try
815 if ((rv & APR_POLLERR) || (rv & APR_POLLNVAL)) {
818 start_connect(&con[i]);
821 if ((rv & APR_POLLIN) || (rv & APR_POLLPRI) || (rv & APR_POLLHUP))
822 read_connection(&con[i]);
823 if (rv & APR_POLLOUT)
824 write_request(&con[i]);
828 output_html_results();
833 /* ------------------------------------------------------- */
835 /* display copyright information */
836 static void copyright(void)
839 printf("This is ApacheBench, Version %s\n", VERSION " <$Revision: 1.8 $> apache-2.0");
840 printf("Copyright (c) 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/\n");
841 printf("Copyright (c) 1998-2000 The Apache Software Foundation, http://www.apache.org/\n");
846 printf(" This is ApacheBench, Version %s <i><%s></i> apache-2.0<br>\n", VERSION, "$Revision: 1.8 $");
847 printf(" Copyright (c) 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/<br>\n");
848 printf(" Copyright (c) 1998-2000 The Apache Software Foundation, http://www.apache.org/<br>\n");
849 printf("</p>\n<p>\n");
853 /* display usage information */
854 static void usage(char *progname)
856 fprintf(stderr, "Usage: %s [options] [http://]hostname[:port]/path\n", progname);
857 fprintf(stderr, "Options are:\n");
858 fprintf(stderr, " -n requests Number of requests to perform\n");
859 fprintf(stderr, " -c concurrency Number of multiple requests to make\n");
860 fprintf(stderr, " -t timelimit Seconds to max. wait for responses\n");
861 fprintf(stderr, " -p postfile File containg data to POST\n");
862 fprintf(stderr, " -T content-type Content-type header for POSTing\n");
863 fprintf(stderr, " -v verbosity How much troubleshooting info to print\n");
864 fprintf(stderr, " -w Print out results in HTML tables\n");
865 fprintf(stderr, " -i Use HEAD instead of GET\n");
866 fprintf(stderr, " -x attributes String to insert as table attributes\n");
867 fprintf(stderr, " -y attributes String to insert as tr attributes\n");
868 fprintf(stderr, " -z attributes String to insert as td or th attributes\n");
869 fprintf(stderr, " -C attribute Add cookie, eg. 'Apache=1234. (repeatable)\n");
870 fprintf(stderr, " -H attribute Add Arbitrary header line, eg. 'Accept-Encoding: zop'\n");
871 fprintf(stderr, " Inserted after all normal header lines. (repeatable)\n");
872 fprintf(stderr, " -A attribute Add Basic WWW Authentication, the attributes\n");
873 fprintf(stderr, " are a colon separated username and password.\n");
874 fprintf(stderr, " -p attribute Add Basic Proxy Authentication, the attributes\n");
875 fprintf(stderr, " are a colon separated username and password.\n");
876 fprintf(stderr, " -V Print version number and exit\n");
877 fprintf(stderr, " -k Use HTTP KeepAlive feature\n");
878 fprintf(stderr, " -h Display usage information (this message)\n");
882 /* ------------------------------------------------------- */
884 /* split URL into parts */
886 static int parse_url(char *url)
892 if (strlen(url) > 7 && strncmp(url, "http://", 7) == 0)
895 if ((cp = strchr(url, ':')) != NULL) {
900 if ((cp = strchr(url, '/')) == NULL)
910 /* ------------------------------------------------------- */
912 /* read data to POST from file, save contents and length */
914 static int open_postfile(char *pfile)
916 ap_file_t *postfd = NULL;
918 ap_fileperms_t mode = APR_OS_DEFAULT;
921 if (ap_open(&postfd, pfile, APR_READ, mode, cntxt) != APR_SUCCESS) {
922 printf("Invalid postfile name (%s)\n", pfile);
926 ap_getfileinfo(&finfo, postfd);
927 postlen = finfo.size;
928 postdata = (char *)malloc(postlen);
930 printf("Can\'t alloc postfile buffer\n");
934 if (ap_read(postfd, postdata, &length) != APR_SUCCESS &&
936 printf("error reading postfilen");
942 /* ------------------------------------------------------- */
944 /* sort out command-line args and call test */
945 int main(int argc, char **argv)
956 tdstring = "bgcolor=white";
962 atexit(ap_terminate);
963 ap_create_pool(&cntxt, NULL);
966 status = ap_xlate_open(&toascii, "ISO8859-1", APR_DEFAULT_CHARSET, cntxt);
968 fprintf(stderr, "ap_xlate_open(to ASCII)->%d\n", status);
971 status = ap_xlate_open(&fromascii, APR_DEFAULT_CHARSET, "ISO8859-1", cntxt)
974 fprintf(stderr, "ap_xlate_open(from ASCII)->%d\n", status);
980 while (ap_getopt(argc, argv, "n:c:t:T:p:v:kVhwx:y:z:", &c, cntxt) == APR_SUCCESS) {
983 requests = atoi(ap_optarg);
985 err("Invalid number of requests\n");
992 concurrency = atoi(ap_optarg);
996 err("Cannot mix POST and HEAD");
1000 err("Cannot mix POST and HEAD");
1002 if (0 == (r = open_postfile(ap_optarg))) {
1005 else if (postdata) {
1010 verbosity = atoi(ap_optarg);
1013 tlimit = atoi(ap_optarg);
1014 requests = MAX_REQUESTS; /* need to size data array on something */
1017 strcpy(content_type, ap_optarg);
1020 strncat(cookie, "Cookie: ", sizeof(cookie));
1021 strncat(cookie, ap_optarg, sizeof(cookie));
1022 strncat(cookie, "\r\n", sizeof(cookie));
1025 /* assume username passwd already to be in colon separated form.
1026 * Ready to be uu-encoded.
1028 while(isspace(*ap_optarg))
1030 l=ap_base64encode(tmp, ap_optarg, strlen(ap_optarg));
1033 strncat(auth, "Authorization: basic ", sizeof(auth));
1034 strncat(auth, tmp, sizeof(auth));
1035 strncat(auth, "\r\n", sizeof(auth));
1039 * assume username passwd already to be in colon separated form.
1041 while(isspace(*ap_optarg))
1043 l=ap_base64encode(tmp, ap_optarg, strlen(ap_optarg));
1046 strncat(auth, "Proxy-Authorization: basic ", sizeof(auth));
1047 strncat(auth, tmp, sizeof(auth));
1048 strncat(auth, "\r\n", sizeof(auth));
1051 strncat(hdrs, ap_optarg, sizeof(hdrs));
1052 strncat(hdrs, "\r\n", sizeof(hdrs));
1053 strcpy(content_type, ap_optarg);
1057 if (ap_optind != argc - 1) {
1058 fprintf(stderr, "%s: wrong number of arguments\n", argv[0]);
1062 if (parse_url(argv[ap_optind++])) {
1063 fprintf(stderr, "%s: invalid URL\n", argv[0]);