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"
128 /* ------------------- DEFINITIONS -------------------------- */
130 /* maximum number of requests on a time limited test */
131 #define MAX_REQUESTS 50000
133 /* good old state hostname */
134 #define STATE_UNCONNECTED 0
135 #define STATE_CONNECTING 1
138 #define CBUFFSIZE 512
141 ap_socket_t *aprsock;
143 int read; /* amount of bytes read */
144 int bread; /* amount of body read */
145 int length; /* Content-Length value used for keep-alive */
146 char cbuff[CBUFFSIZE]; /* a buffer to store server response header */
147 int cbx; /* offset in cbuffer */
148 int keepalive; /* non-zero if a keep-alive request */
149 int gotheader; /* non-zero if we have the entire header in
151 ap_time_t start, connect, done;
156 int read; /* number of bytes read */
157 int ctime; /* time in ms to connect */
158 int time; /* time in ms for connection */
161 #define ap_min(a,b) ((a)<(b))?(a):(b)
162 #define ap_max(a,b) ((a)>(b))?(a):(b)
164 /* --------------------- GLOBALS ---------------------------- */
166 int verbosity = 0; /* no verbosity by default */
167 int posting = 0; /* GET by default */
168 int requests = 1; /* Number of requests to make */
169 int concurrency = 1; /* Number of multiple requests to make */
170 int tlimit = 0; /* time limit in cs */
171 int keepalive = 0; /* try and do keepalive connections */
172 char servername[1024]; /* name that server reports */
173 char hostname[1024]; /* host name */
174 char path[1024]; /* path name */
175 char postfile[1024]; /* name of file containing post data */
176 char *postdata; /* *buffer containing data from postfile */
177 ap_ssize_t postlen = 0; /* length of data to be POSTed */
178 char content_type[1024]; /* content type to put in POST header */
179 char cookie[1024], /* optional cookie line */
180 auth[1024], /* optional (basic/uuencoded)
181 * authentification */
182 hdrs[4096]; /* optional arbitrary headers */
183 int port = 80; /* port number */
184 time_t aprtimeout = 30 * AP_USEC_PER_SEC; /* timeout value */
186 int use_html = 0; /* use html in the report */
191 int doclen = 0; /* the length the document should be */
192 int totalread = 0; /* total number of bytes read */
193 int totalbread = 0; /* totoal amount of entity body read */
194 int totalposted = 0; /* total number of bytes posted, inc. headers */
195 int done = 0; /* number of requests we have done */
196 int doneka = 0; /* number of keep alive connections done */
197 int good = 0, bad = 0; /* number of good and bad requests */
199 /* store error cases */
200 int err_length = 0, err_conn = 0, err_except = 0;
201 int err_response = 0;
203 ap_time_t start, endtime;
205 /* global request (and its length) */
209 /* one global throw-away buffer to read stuff into */
212 struct connection *con; /* connection array */
213 struct data *stats; /* date for each request */
216 ap_pollfd_t *readbits;
218 ap_xlate_t *from_ascii, *to_ascii;
221 /* --------------------------------------------------------- */
223 /* simple little function to perror and exit */
225 static void err(char *s)
236 /* --------------------------------------------------------- */
238 /* write out request to a connection - assumes we can write
239 (small) request out in one go into our new socket buffer */
241 static void write_request(struct connection *c)
243 ap_ssize_t len = reqlen;
244 c->connect = ap_now();
245 ap_setsocketopt(c->aprsock, APR_SO_TIMEOUT, 30 * AP_USEC_PER_SEC);
246 if (ap_send(c->aprsock, request, &reqlen) != APR_SUCCESS ||
248 printf("Send request failed!\n");
251 ap_send(c->aprsock, postdata, &postlen);
252 totalposted += (reqlen + postlen);
255 c->state = STATE_READ;
256 ap_add_poll_socket(readbits, c->aprsock, APR_POLLIN);
259 /* --------------------------------------------------------- */
261 /* calculate and output results */
263 static void output_results(void)
268 timetaken = (endtime - start) / 1000;
271 printf("Server Software: %s\n", servername);
272 printf("Server Hostname: %s\n", hostname);
273 printf("Server Port: %d\n", port);
275 printf("Document Path: %s\n", path);
276 printf("Document Length: %d bytes\n", doclen);
278 printf("Concurrency Level: %d\n", concurrency);
279 printf("Time taken for tests: %d.%03d seconds\n",
280 timetaken / 1000, timetaken % 1000);
281 printf("Complete requests: %d\n", done);
282 printf("Failed requests: %d\n", bad);
284 printf(" (Connect: %d, Length: %d, Exceptions: %d)\n",
285 err_conn, err_length, err_except);
287 printf("Non-2xx responses: %d\n", err_response);
289 printf("Keep-Alive requests: %d\n", doneka);
290 printf("Total transferred: %d bytes\n", totalread);
292 printf("Total POSTed: %d\n", totalposted);
293 printf("HTML transferred: %d bytes\n", totalbread);
295 /* avoid divide by zero */
297 printf("Requests per second: %.2f\n", 1000 * (float) (done) / timetaken);
298 printf("Transfer rate: %.2f kb/s received\n",
299 (float) (totalread) / timetaken);
301 printf(" %.2f kb/s sent\n",
302 (float) (totalposted) / timetaken);
303 printf(" %.2f kb/s total\n",
304 (float) (totalread + totalposted) / timetaken);
309 /* work out connection times */
311 int totalcon = 0, total = 0;
312 int mincon = 9999999, mintot = 999999;
313 int maxcon = 0, maxtot = 0;
315 for (i = 0; i < requests; i++) {
316 struct data s = stats[i];
317 mincon = ap_min(mincon, s.ctime);
318 mintot = ap_min(mintot, s.time);
319 maxcon = ap_max(maxcon, s.ctime);
320 maxtot = ap_max(maxtot, s.time);
324 if (requests > 0) { /* avoid division by zero (if 0 requests) */
325 printf("\nConnnection Times (ms)\n");
326 printf(" min avg max\n");
327 printf("Connect: %5d %5d %5d\n", mincon, totalcon / requests, maxcon);
328 printf("Processing: %5d %5d %5d\n",
329 mintot - mincon, (total / requests) - (totalcon / requests),
331 printf("Total: %5d %5d %5d\n", mintot, total / requests, maxtot);
336 /* --------------------------------------------------------- */
338 /* calculate and output results in HTML */
340 static void output_html_results(void)
345 timetaken = (endtime - start) / 1000;
347 printf("\n\n<table %s>\n", tablestring);
348 printf("<tr %s><th colspan=2 %s>Server Software:</th>"
349 "<td colspan=2 %s>%s</td></tr>\n",
350 trstring, tdstring, tdstring, servername);
351 printf("<tr %s><th colspan=2 %s>Server Hostname:</th>"
352 "<td colspan=2 %s>%s</td></tr>\n",
353 trstring, tdstring, tdstring, hostname);
354 printf("<tr %s><th colspan=2 %s>Server Port:</th>"
355 "<td colspan=2 %s>%d</td></tr>\n",
356 trstring, tdstring, tdstring, port);
357 printf("<tr %s><th colspan=2 %s>Document Path:</th>"
358 "<td colspan=2 %s>%s</td></tr>\n",
359 trstring, tdstring, tdstring, path);
360 printf("<tr %s><th colspan=2 %s>Document Length:</th>"
361 "<td colspan=2 %s>%d bytes</td></tr>\n",
362 trstring, tdstring, tdstring, doclen);
363 printf("<tr %s><th colspan=2 %s>Concurrency Level:</th>"
364 "<td colspan=2 %s>%d</td></tr>\n",
365 trstring, tdstring, tdstring, concurrency);
366 printf("<tr %s><th colspan=2 %s>Time taken for tests:</th>"
367 "<td colspan=2 %s>%d.%03d seconds</td></tr>\n",
368 trstring, tdstring, tdstring, timetaken / 1000, timetaken % 1000);
369 printf("<tr %s><th colspan=2 %s>Complete requests:</th>"
370 "<td colspan=2 %s>%d</td></tr>\n",
371 trstring, tdstring, tdstring, done);
372 printf("<tr %s><th colspan=2 %s>Failed requests:</th>"
373 "<td colspan=2 %s>%d</td></tr>\n",
374 trstring, tdstring, tdstring, bad);
376 printf("<tr %s><td colspan=4 %s > (Connect: %d, Length: %d, Exceptions: %d)</td></tr>\n",
377 trstring, tdstring, err_conn, err_length, err_except);
379 printf("<tr %s><th colspan=2 %s>Non-2xx responses:</th>"
380 "<td colspan=2 %s>%d</td></tr>\n",
381 trstring, tdstring, tdstring, err_response);
383 printf("<tr %s><th colspan=2 %s>Keep-Alive requests:</th>"
384 "<td colspan=2 %s>%d</td></tr>\n",
385 trstring, tdstring, tdstring, doneka);
386 printf("<tr %s><th colspan=2 %s>Total transferred:</th>"
387 "<td colspan=2 %s>%d bytes</td></tr>\n",
388 trstring, tdstring, tdstring, totalread);
390 printf("<tr %s><th colspan=2 %s>Total POSTed:</th>"
391 "<td colspan=2 %s>%d</td></tr>\n",
392 trstring, tdstring, tdstring, totalposted);
393 printf("<tr %s><th colspan=2 %s>HTML transferred:</th>"
394 "<td colspan=2 %s>%d bytes</td></tr>\n",
395 trstring, tdstring, tdstring, totalbread);
397 /* avoid divide by zero */
399 printf("<tr %s><th colspan=2 %s>Requests per second:</th>"
400 "<td colspan=2 %s>%.2f</td></tr>\n",
401 trstring, tdstring, tdstring, 1000 * (float) (done) / timetaken);
402 printf("<tr %s><th colspan=2 %s>Transfer rate:</th>"
403 "<td colspan=2 %s>%.2f kb/s received</td></tr>\n",
404 trstring, tdstring, tdstring, (float) (totalread) / timetaken);
406 printf("<tr %s><td colspan=2 %s> </td>"
407 "<td colspan=2 %s>%.2f kb/s sent</td></tr>\n",
408 trstring, tdstring, tdstring,
409 (float) (totalposted) / timetaken);
410 printf("<tr %s><td colspan=2 %s> </td>"
411 "<td colspan=2 %s>%.2f kb/s total</td></tr>\n",
412 trstring, tdstring, tdstring,
413 (float) (totalread + totalposted) / timetaken);
418 /* work out connection times */
420 int totalcon = 0, total = 0;
421 int mincon = 9999999, mintot = 999999;
422 int maxcon = 0, maxtot = 0;
424 for (i = 0; i < requests; i++) {
425 struct data s = stats[i];
426 mincon = ap_min(mincon, s.ctime);
427 mintot = ap_min(mintot, s.time);
428 maxcon = ap_max(maxcon, s.ctime);
429 maxtot = ap_max(maxtot, s.time);
434 if (requests > 0) { /* avoid division by zero (if 0 requests) */
435 printf("<tr %s><th %s colspan=4>Connnection Times (ms)</th></tr>\n",
437 printf("<tr %s><th %s> </th> <th %s>min</th> <th %s>avg</th> <th %s>max</th></tr>\n",
438 trstring, tdstring, tdstring, tdstring, tdstring);
439 printf("<tr %s><th %s>Connect:</th>"
442 "<td %s>%5d</td></tr>\n",
443 trstring, tdstring, tdstring, mincon, tdstring, totalcon / requests, tdstring, maxcon);
444 printf("<tr %s><th %s>Processing:</th>"
447 "<td %s>%5d</td></tr>\n",
448 trstring, tdstring, tdstring, mintot - mincon, tdstring,
449 (total / requests) - (totalcon / requests), tdstring, maxtot - maxcon);
450 printf("<tr %s><th %s>Total:</th>"
453 "<td %s>%5d</td></tr>\n",
454 trstring, tdstring, tdstring, mintot, tdstring, total / requests, tdstring, maxtot);
456 printf("</table>\n");
460 /* --------------------------------------------------------- */
462 /* start asnchronous non-blocking connection */
464 static void start_connect(struct connection *c)
474 if (ap_create_tcp_socket(&c->aprsock, cntxt) != APR_SUCCESS) {
477 if (ap_set_remote_port(c->aprsock, port) != APR_SUCCESS) {
481 if ((rv = ap_connect(c->aprsock, hostname)) != APR_SUCCESS) {
482 if (ap_canonical_error(rv) == APR_EINPROGRESS) {
483 c->state = STATE_CONNECTING;
484 ap_add_poll_socket(readbits, c->aprsock, APR_POLLOUT);
488 ap_remove_poll_socket(readbits, c->aprsock);
489 ap_close_socket(c->aprsock);
492 err("\nTest aborted after 10 failures\n\n");
498 /* connected first time */
502 /* --------------------------------------------------------- */
504 /* close down connection and save stats */
506 static void close_connection(struct connection *c)
508 if (c->read == 0 && c->keepalive) {
509 /* server has legitimately shut down an idle keep alive request */
510 good--; /* connection never happend */
514 /* first time here */
517 else if (c->bread != doclen) {
522 if (done < requests) {
526 s.ctime = (c->connect - c->start) / 1000;
527 s.time = (c->done - c->start) / 1000;
532 ap_remove_poll_socket(readbits, c->aprsock);
533 ap_close_socket(c->aprsock);
540 /* --------------------------------------------------------- */
542 /* read data from connection */
544 static void read_connection(struct connection *c)
549 char respcode[4]; /* 3 digits and null */
552 ap_setsocketopt(c->aprsock, APR_SO_TIMEOUT, aprtimeout);
553 status = ap_recv(c->aprsock, buffer, &r);
554 if (r == 0 || (status != 0 && ap_canonical_error(status) != APR_EAGAIN)) {
560 if (ap_canonical_error(status) == APR_EAGAIN)
569 int space = CBUFFSIZE - c->cbx - 1; /* -1 to allow for 0 terminator */
570 int tocopy = (space < r) ? space : r;
572 ap_size_t inbytes_left = space, outbytes_left = space;
574 status = ap_xlate_conv_buffer(from_ascii, buffer, &inbytes_left,
575 c->cbuff + c->cbx, &outbytes_left);
576 if (status || inbytes_left || outbytes_left) {
577 fprintf(stderr, "only simple translation is supported (%d/%u/%u)\n",
578 status, inbytes_left, outbytes_left);
582 memcpy(c->cbuff + c->cbx, buffer, space);
583 #endif /*NOT_ASCII */
586 c->cbuff[c->cbx] = 0; /* terminate for benefit of strstr */
587 if (verbosity >= 4) {
588 printf("LOG: header received:\n%s\n", c->cbuff);
590 s = strstr(c->cbuff, "\r\n\r\n");
591 /* this next line is so that we talk to NCSA 1.5 which blatantly
592 * breaks the http specifaction
595 s = strstr(c->cbuff, "\n\n");
600 /* read rest next time */
605 /* header is in invalid or too big - close connection */
606 ap_remove_poll_socket(readbits, c->aprsock);
607 ap_close_socket(c->aprsock);
609 err("\nTest aborted after 10 failures\n\n");
615 /* have full header */
617 /* this is first time, extract some interesting info */
619 p = strstr(c->cbuff, "Server:");
629 /* XXX: this parsing isn't even remotely HTTP compliant...
630 * but in the interest of speed it doesn't totally have to be,
631 * it just needs to be extended to handle whatever servers
632 * folks want to test against. -djg */
634 /* check response code */
635 part = strstr(c->cbuff, "HTTP"); /* really HTTP/1.x_ */
636 strncpy(respcode, (part + strlen("HTTP/1.x_")), 3);
638 if (respcode[0] != '2') {
641 printf("WARNING: Response code not 2xx (%s)\n", respcode);
643 else if (verbosity >= 3) {
644 printf("LOG: Response code = %s\n", respcode);
648 *s = 0; /* terminate at end of header */
650 (strstr(c->cbuff, "Keep-Alive")
651 || strstr(c->cbuff, "keep-alive"))) { /* for benefit of MSIIS */
653 cl = strstr(c->cbuff, "Content-Length:");
654 /* handle NCSA, which sends Content-length: */
656 cl = strstr(c->cbuff, "Content-length:");
659 c->length = atoi(cl + 16);
662 c->bread += c->cbx - (s + l - c->cbuff) + r - tocopy;
663 totalbread += c->bread;
667 /* outside header, everything we have read is entity body */
672 if (c->keepalive && (c->bread >= c->length)) {
673 /* finished a keep-alive connection */
678 /* first time here */
681 else if (c->bread != doclen) {
685 if (done < requests) {
689 s.ctime = (c->connect - c->start) / 1000;
690 s.time = (c->done - c->start) / 1000;
697 c->read = c->bread = 0;
699 c->start = c->connect; /* zero connect time with keep-alive */
703 /* --------------------------------------------------------- */
707 static void test(void)
710 ap_interval_time_t timeout;
715 ap_size_t inbytes_left, outbytes_left;
719 printf("Benchmarking %s (be patient)...", hostname);
725 con = malloc(concurrency * sizeof(struct connection));
726 memset(con, 0, concurrency * sizeof(struct connection));
728 stats = malloc(requests * sizeof(struct data));
729 ap_setup_poll(&readbits, concurrency, cntxt);
733 sprintf(request, "%s %s HTTP/1.0\r\n"
734 "User-Agent: ApacheBench/%s\r\n"
739 (posting == 0) ? "GET" : "HEAD",
742 keepalive ? "Connection: Keep-Alive\r\n" : "",
743 cookie, auth, hostname, hdrs);
746 sprintf(request, "POST %s HTTP/1.0\r\n"
747 "User-Agent: ApacheBench/%s\r\n"
751 "Content-length: %d\r\n"
752 "Content-type: %s\r\n"
757 keepalive ? "Connection: Keep-Alive\r\n" : "",
760 (content_type[0]) ? content_type : "text/plain", hdrs);
764 printf("INFO: POST header == \n---\n%s\n---\n", request);
766 reqlen = strlen(request);
769 inbytes_left = outbytes_left = reqlen;
770 status = ap_xlate_conv_buffer(to_ascii, request, &inbytes_left,
771 request, &outbytes_left);
772 if (status || inbytes_left || outbytes_left) {
773 fprintf(stderr, "only simple translation is supported (%d/%u/%u)\n",
774 status, inbytes_left, outbytes_left);
779 /* ok - lets start */
782 /* initialise lots of requests */
783 for (i = 0; i < concurrency; i++) {
785 start_connect(&con[i]);
788 while (done < requests) {
792 /* check for time limit expiry */
794 timed = (now - start) / AP_USEC_PER_SEC;
795 if (tlimit && timed > (tlimit * 1000)) {
796 requests = done; /* so stats are correct */
798 /* Timeout of 30 seconds. */
799 timeout = 30 * AP_USEC_PER_SEC;
802 ap_poll(readbits, &n, timeout);
805 err("\nServer timed out\n\n");
810 for (i = 0; i < concurrency; i++) {
811 ap_get_revents(&rv, con[i].aprsock, readbits);
813 /* Note: APR_POLLHUP is set after FIN is received on some
814 * systems, so treat that like APR_POLLIN so that we try
817 if ((rv & APR_POLLERR) || (rv & APR_POLLNVAL)) {
820 start_connect(&con[i]);
823 if ((rv & APR_POLLIN) || (rv & APR_POLLPRI) || (rv & APR_POLLHUP))
824 read_connection(&con[i]);
825 if (rv & APR_POLLOUT)
826 write_request(&con[i]);
830 output_html_results();
835 /* ------------------------------------------------------- */
837 /* display copyright information */
838 static void copyright(void)
841 printf("This is ApacheBench, Version %s\n", VERSION " <$Revision: 1.12 $> apache-2.0");
842 printf("Copyright (c) 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/\n");
843 printf("Copyright (c) 1998-2000 The Apache Software Foundation, http://www.apache.org/\n");
848 printf(" This is ApacheBench, Version %s <i><%s></i> apache-2.0<br>\n", VERSION, "$Revision: 1.12 $");
849 printf(" Copyright (c) 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/<br>\n");
850 printf(" Copyright (c) 1998-2000 The Apache Software Foundation, http://www.apache.org/<br>\n");
851 printf("</p>\n<p>\n");
855 /* display usage information */
856 static void usage(char *progname)
858 fprintf(stderr, "Usage: %s [options] [http://]hostname[:port]/path\n", progname);
859 fprintf(stderr, "Options are:\n");
860 fprintf(stderr, " -n requests Number of requests to perform\n");
861 fprintf(stderr, " -c concurrency Number of multiple requests to make\n");
862 fprintf(stderr, " -t timelimit Seconds to max. wait for responses\n");
863 fprintf(stderr, " -p postfile File containg data to POST\n");
864 fprintf(stderr, " -T content-type Content-type header for POSTing\n");
865 fprintf(stderr, " -v verbosity How much troubleshooting info to print\n");
866 fprintf(stderr, " -w Print out results in HTML tables\n");
867 fprintf(stderr, " -i Use HEAD instead of GET\n");
868 fprintf(stderr, " -x attributes String to insert as table attributes\n");
869 fprintf(stderr, " -y attributes String to insert as tr attributes\n");
870 fprintf(stderr, " -z attributes String to insert as td or th attributes\n");
871 fprintf(stderr, " -C attribute Add cookie, eg. 'Apache=1234. (repeatable)\n");
872 fprintf(stderr, " -H attribute Add Arbitrary header line, eg. 'Accept-Encoding: zop'\n");
873 fprintf(stderr, " Inserted after all normal header lines. (repeatable)\n");
874 fprintf(stderr, " -A attribute Add Basic WWW Authentication, the attributes\n");
875 fprintf(stderr, " are a colon separated username and password.\n");
876 fprintf(stderr, " -p attribute Add Basic Proxy Authentication, the attributes\n");
877 fprintf(stderr, " are a colon separated username and password.\n");
878 fprintf(stderr, " -V Print version number and exit\n");
879 fprintf(stderr, " -k Use HTTP KeepAlive feature\n");
880 fprintf(stderr, " -h Display usage information (this message)\n");
884 /* ------------------------------------------------------- */
886 /* split URL into parts */
888 static int parse_url(char *url)
892 char *p = NULL; /* points to port if url has it */
894 if (strlen(url) > 7 && strncmp(url, "http://", 7) == 0)
897 if ((cp = strchr(url, ':')) != NULL) {
902 if ((cp = strchr(url, '/')) == NULL)
912 /* ------------------------------------------------------- */
914 /* read data to POST from file, save contents and length */
916 static int open_postfile(char *pfile)
918 ap_file_t *postfd = NULL;
920 ap_fileperms_t mode = APR_OS_DEFAULT;
923 if (ap_open(&postfd, pfile, APR_READ, mode, cntxt) != APR_SUCCESS) {
924 printf("Invalid postfile name (%s)\n", pfile);
928 ap_getfileinfo(&finfo, postfd);
929 postlen = finfo.size;
930 postdata = (char *)malloc(postlen);
932 printf("Can\'t alloc postfile buffer\n");
936 if (ap_read(postfd, postdata, &length) != APR_SUCCESS &&
938 printf("error reading postfilen");
944 /* ------------------------------------------------------- */
946 /* sort out command-line args and call test */
947 int main(int argc, char **argv)
958 tdstring = "bgcolor=white";
964 atexit(ap_terminate);
965 ap_create_pool(&cntxt, NULL);
968 status = ap_xlate_open(&to_ascii, "ISO8859-1", APR_DEFAULT_CHARSET, cntxt);
970 fprintf(stderr, "ap_xlate_open(to ASCII)->%d\n", status);
973 status = ap_xlate_open(&from_ascii, APR_DEFAULT_CHARSET, "ISO8859-1", cntxt);
976 fprintf(stderr, "ap_xlate_open(from ASCII)->%d\n", status);
982 while (ap_getopt(argc, argv, "n:c:t:T:p:v:kVhwx:y:z:", &c, cntxt) == APR_SUCCESS) {
985 requests = atoi(ap_optarg);
987 err("Invalid number of requests\n");
994 concurrency = atoi(ap_optarg);
998 err("Cannot mix POST and HEAD");
1002 err("Cannot mix POST and HEAD");
1004 if (0 == (r = open_postfile(ap_optarg))) {
1007 else if (postdata) {
1012 verbosity = atoi(ap_optarg);
1015 tlimit = atoi(ap_optarg);
1016 requests = MAX_REQUESTS; /* need to size data array on something */
1019 strcpy(content_type, ap_optarg);
1022 strncat(cookie, "Cookie: ", sizeof(cookie));
1023 strncat(cookie, ap_optarg, sizeof(cookie));
1024 strncat(cookie, "\r\n", sizeof(cookie));
1027 /* assume username passwd already to be in colon separated form.
1028 * Ready to be uu-encoded.
1030 while(isspace(*ap_optarg))
1032 l=ap_base64encode(tmp, ap_optarg, strlen(ap_optarg));
1035 strncat(auth, "Authorization: basic ", sizeof(auth));
1036 strncat(auth, tmp, sizeof(auth));
1037 strncat(auth, "\r\n", sizeof(auth));
1041 * assume username passwd already to be in colon separated form.
1043 while(isspace(*ap_optarg))
1045 l=ap_base64encode(tmp, ap_optarg, strlen(ap_optarg));
1048 strncat(auth, "Proxy-Authorization: basic ", sizeof(auth));
1049 strncat(auth, tmp, sizeof(auth));
1050 strncat(auth, "\r\n", sizeof(auth));
1053 strncat(hdrs, ap_optarg, sizeof(hdrs));
1054 strncat(hdrs, "\r\n", sizeof(hdrs));
1055 strcpy(content_type, ap_optarg);
1059 if (ap_optind != argc - 1) {
1060 fprintf(stderr, "%s: wrong number of arguments\n", argv[0]);
1064 if (parse_url(argv[ap_optind++])) {
1065 fprintf(stderr, "%s: invalid URL\n", argv[0]);