cvs commit: apachen/src/test zb.c
dgaudet 97/11/09 17:55:48 Added: src/test zb.c Log: Add zeusbench since the zeus folks seem to have removed it from their pages. It's freely distributable provided we leave the copyright intact at the top of the code. Revision ChangesPath 1.1 apachen/src/test/zb.c Index: zb.c === /* ZeusBench V1.0 == This program is Copyright (C) Zeus Technology Limited 1996. This program may be used and copied freely providing this copyright notice is not removed. This software is provided "as is" and any express or implied waranties, including but not limited to, the implied warranties of merchantability and fitness for a particular purpose are disclaimed. In no event shall Zeus Technology Ltd. be liable for any direct, indirect, incidental, special, exemplary, or consequential damaged (including, but not limited to, procurement of substitute good or services; loss of use, data, or profits; or business interruption) however caused and on theory of liability. Whether in contract, strict liability or tort (including negligence or otherwise) arising in any way out of the use of this software, even if advised of the possibility of such damage Written by Adam Twiss ([EMAIL PROTECTED]). February 1996 */ #ifdef SUNOS /* for some reason my SunOS headers did not have these defined */ extern char *optarg; extern int optind, opterr, optopt; #endif /* #include */ #include #include #include #include #include #include #include #include #include #include #include /* --- DEFINITIONS -- */ /* good old state machine */ #define STATE_UNCONNECTED 0 #define STATE_CONNECTING 1 #define STATE_READ2 #define CBUFFSIZE 512 struct connection { int fd; int state; int read; /* amount of bytes read */ int bread; /* amount of body read */ int length; /* Content-Length value used for keep-alive */ char cbuff[CBUFFSIZE]; /* a buffer to store server response header */ int cbx;/* offset in cbuffer */ int keepalive; /* non-zero if a keep-alive request */ int gotheader; /* non-zero if we have the entire header in cbuff */ struct timeval start, connect, done; }; struct data { int read; /* number of bytes read */ int ctime; /* time in ms to connect */ int time; /* time in ms for connection */ }; #define min(a,b) ((a)<(b))?(a):(b) #define max(a,b) ((a)>(b))?(a):(b) /* - GLOBALS */ int requests = 1; /* Number of requests to make */ int concurrency = 1; /* Number of multiple requests to make */ int tlimit = 0;/* time limit in cs */ int keepalive = 0; /* try and do keepalive connections */ char *machine; /* Machine name */ char *file;/* file name to use */ char server_name[80]; /* name that server reports */ int port = 80; /* port to use */ int doclen = 0;/* the length the document should be */ int totalread = 0; /* total number of bytes read */ int totalbread = 0;/* totoal amount of entity body read */ int done=0;/* number of requests we have done */ int doneka=0; /* number of keep alive connections done */ int good=0, bad=0; /* number of good and bad requests */ /* store error cases */ int err_length = 0, err_conn = 0, err_except = 0; struct timeval start, end; /* global request (and its length) */ char request[512]; int reqlen; /* one global throw-away buffer to read stuff into */ char buffer[4096]; struct connection *con; /* connection array */ struct data *stats; /* date for each request */ fd_set readbits, writebits; /* bits for select */ struct sockaddr_in server; /* server addr structure */ /* - */ /* simple little function to perror and exit */ static void err(char *s) { perror(s); exit(errno); } /* - */ /* write out request to a connection - assumes we can write (small) request out in one go into our new socket buffer */ void write_request(struct connection *c) { gettimeofday(&c->connect,0); write(c->fd,request, reqlen); c->state = STATE_READ; FD_SET(c->fd, &readbits); FD_CLR(c->fd, &writebits); } /* - */ /* make an fd non blocking */ void nonblock(int fd) { int i=1; ioctl(fd, FIONBIO, &i); } /* ---
cvs commit: apachen/src/test zb.c
dgaudet 97/11/09 18:06:03 Modified:src/test zb.c Log: Update to v1.01. Obtained from:http://www.zeus.co.uk/misc/zb.c Revision ChangesPath 1.2 +74 -33apachen/src/test/zb.c Index: zb.c === RCS file: /export/home/cvs/apachen/src/test/zb.c,v retrieving revision 1.1 retrieving revision 1.2 diff -u -r1.1 -r1.2 --- zb.c 1997/11/10 01:55:47 1.1 +++ zb.c 1997/11/10 02:06:02 1.2 @@ -1,6 +1,6 @@ -/* ZeusBench V1.0 - == +/* ZeusBench V1.01 + === This program is Copyright (C) Zeus Technology Limited 1996. @@ -16,21 +16,38 @@ or business interruption) however caused and on theory of liability. Whether in contract, strict liability or tort (including negligence or otherwise) arising in any way out of the use of this software, even if advised of the -possibility of such damage +possibility of such damage. - Written by Adam Twiss ([EMAIL PROTECTED]). February 1996 + Written by Adam Twiss ([EMAIL PROTECTED]). March 1996 + +Thanks to the following people for their input: + Mike Belshe ([EMAIL PROTECTED]) + Michael Campanella ([EMAIL PROTECTED]) */ -#ifdef SUNOS -/* for some reason my SunOS headers did not have these defined */ -extern char *optarg; -extern int optind, opterr, optopt; +/* Notes on compiling -- + +This should compile unmodified using gcc on HP-UX, FreeBSD, Linux, +IRIX, Solaris, AIX and Digital Unix (OSF). On Solaris 2.x you will +need to compile with "-lnsl -lsocket" options. If you have any +difficulties compiling then let me know. + +On SunOS 4.x.x you may need to compile with -DSUNOS4 to add the following +two lines of code which appear not to exist in my SunOS headers */ + +#ifdef SUNOS4 +extern char *optarg; +extern int optind, opterr, optopt; #endif -/* #include */ +/* */ + +/* affects include files on Solaris */ +#define BSD_COMP #include +#include #include #include #include @@ -44,6 +61,9 @@ /* --- DEFINITIONS -- */ +/* maximum number of requests on a time limited test */ +#define MAX_REQUESTS 5 + /* good old state machine */ #define STATE_UNCONNECTED 0 #define STATE_CONNECTING 1 @@ -96,7 +116,7 @@ /* store error cases */ int err_length = 0, err_conn = 0, err_except = 0; -struct timeval start, end; +struct timeval start, endtime; /* global request (and its length) */ char request[512]; @@ -168,12 +188,12 @@ { int timetaken; - gettimeofday(&end,0); - timetaken = timedif(end, start); + gettimeofday(&endtime,0); + timetaken = timedif(endtime, start); printf("\n---\n"); printf("Server: %s\n", server_name); - printf("Doucment Length:%d\n", doclen); + printf("Document Length:%d\n", doclen); printf("Concurency Level: %d\n", concurrency); printf("Time taken for tests: %d.%03d seconds\n", timetaken/1000, timetaken%1000); @@ -229,10 +249,13 @@ c->keepalive = 0; c->cbx = 0; c->gotheader = 0; + c->fd = socket(AF_INET, SOCK_STREAM, 0); if(c->fd<0) err("socket"); + nonblock(c->fd); gettimeofday(&c->start,0); + if(connect(c->fd, (struct sockaddr *) &server, sizeof(server))<0) { if(errno==EINPROGRESS) { c->state = STATE_CONNECTING; @@ -260,19 +283,28 @@ void close_connection(struct connection *c) { - if(good==1) { -/* first time here */ -doclen = c->bread; - } else if(c->bread!=doclen) { bad++; err_length++; } - - /* save out time */ - if(done < requests) { -struct data s; -gettimeofday(&c->done,0); -s.read = c->read; -s.ctime = timedif(c->connect, c->start); -s.time = timedif(c->done, c->start); -stats[done++] = s; + if(c->read == 0 && c->keepalive) { +/* server has legitiamately shut down an idle keep alive request */ +good--; /* connection never happend */ + } + else { +if(good==1) { + /* first time here */ + doclen = c->bread; +} else if (c->bread!=doclen) { + bad++; + err_length++; +} + +/* save out time */ +if(done < requests) { + struct data s; + gettimeofday(&c->done,0); + s.read = c->read; + s.ctime = timedif(c->connect, c->start); + s.time = timedif(c->done, c->start); + stats[done++] = s; +} } close(c->fd); @@ -316,6 +348,7 @@ /* this next line is so that