diff -cpr head/contrib/pgbench/pgbench.c pgbench-duration/contrib/pgbench/pgbench.c *** head/contrib/pgbench/pgbench.c Sat May 10 00:53:07 2008 --- pgbench-duration/contrib/pgbench/pgbench.c Wed Aug 13 10:27:48 2008 *************** *** 31,36 **** --- 31,37 ---- #include "libpq-fe.h" #include + #include #ifdef WIN32 #undef FD_SETSIZE *************** extern int optind; *** 70,75 **** --- 71,79 ---- int nclients = 1; /* default number of simulated clients */ int nxacts = 10; /* default number of transactions per clients */ + struct timeval start_time; /* start up time */ + int duration = 0; /* duration is not used by default */ + /* * scaling factor. for example, scale = 10 will make 1000000 tuples of * accounts table. *************** diffTime(struct timeval *t1, struct time *** 241,247 **** static void usage(void) { ! fprintf(stderr, "usage: pgbench [-h hostname][-p port][-c nclients][-t ntransactions][-s scaling_factor][-D varname=value][-n][-C][-v][-S][-N][-M querymode][-f filename][-l][-U login][-d][dbname]\n"); fprintf(stderr, "(initialize mode): pgbench -i [-h hostname][-p port][-s scaling_factor] [-F fillfactor] [-U login][-d][dbname]\n"); } --- 245,251 ---- static void usage(void) { ! fprintf(stderr, "usage: pgbench [-h hostname][-p port][-c nclients][-t ntransactions | -T duration][-s scaling_factor][-D varname=value][-n][-C][-v][-S][-N][-M querymode][-f filename][-l][-U login][-d][dbname]\n"); fprintf(stderr, "(initialize mode): pgbench -i [-h hostname][-p port][-s scaling_factor] [-F fillfactor] [-U login][-d][dbname]\n"); } *************** top: *** 630,636 **** st->con = NULL; } ! if (++st->cnt >= nxacts) { remains--; /* I've done */ if (st->con != NULL) --- 634,659 ---- st->con = NULL; } ! ++st->cnt; ! ! if (duration > 0) ! { ! struct timeval now; ! ! gettimeofday(&now, NULL); ! if (now.tv_sec >= start_time.tv_sec + duration && ! now.tv_usec >= start_time.tv_usec) ! { ! remains--; /* I've done */ ! if (st->con != NULL) ! { ! PQfinish(st->con); ! st->con = NULL; ! } ! return; ! } ! } ! else if (st->cnt >= nxacts) { remains--; /* I've done */ if (st->con != NULL) *************** printResults( *** 1431,1438 **** printf("scaling factor: %d\n", scale); printf("query mode: %s\n", QUERYMODE[querymode]); printf("number of clients: %d\n", nclients); ! printf("number of transactions per client: %d\n", nxacts); ! printf("number of transactions actually processed: %d/%d\n", normal_xacts, nxacts * nclients); printf("tps = %f (including connections establishing)\n", t1); printf("tps = %f (excluding connections establishing)\n", t2); } --- 1454,1468 ---- printf("scaling factor: %d\n", scale); printf("query mode: %s\n", QUERYMODE[querymode]); printf("number of clients: %d\n", nclients); ! if (duration <= 0) ! { ! printf("number of transactions per client: %d\n", nxacts); ! printf("number of transactions actually processed: %d/%d\n", normal_xacts, nxacts * nclients); ! } ! else ! { ! printf("number of transactions actually processed: %d in %d s\n", normal_xacts, duration); ! } printf("tps = %f (including connections establishing)\n", t1); printf("tps = %f (excluding connections establishing)\n", t2); } *************** main(int argc, char **argv) *** 1453,1459 **** CState *state; /* status of clients */ - struct timeval start_time; /* start up time */ struct timeval end_time; /* end time */ int i; --- 1483,1488 ---- *************** main(int argc, char **argv) *** 1496,1502 **** memset(state, 0, sizeof(*state)); ! while ((c = getopt(argc, argv, "ih:nvp:dc:t:s:U:CNSlf:D:F:M:")) != -1) { switch (c) { --- 1525,1531 ---- memset(state, 0, sizeof(*state)); ! while ((c = getopt(argc, argv, "ih:nvp:dc:t:s:U:CNSlf:D:F:M:T:")) != -1) { switch (c) { *************** main(int argc, char **argv) *** 1569,1574 **** --- 1598,1611 ---- exit(1); } break; + case 'T': + duration = atoi(optarg); + if (duration <= 0) + { + fprintf(stderr, "invalid number of duration(-T): %d\n", duration); + exit(1); + } + break; case 'U': login = optarg; break; *************** main(int argc, char **argv) *** 1692,1699 **** if (debug) { ! printf("pghost: %s pgport: %s nclients: %d nxacts: %d dbName: %s\n", pghost, pgport, nclients, nxacts, dbName); } /* opening connection... */ --- 1729,1740 ---- if (debug) { ! if (duration <= 0) ! printf("pghost: %s pgport: %s nclients: %d nxacts: %d dbName: %s\n", pghost, pgport, nclients, nxacts, dbName); + else + printf("pghost: %s pgport: %s nclients: %d duration: %d dbName: %s\n", + pghost, pgport, nclients, duration, dbName); } /* opening connection... */ diff -cpr head/doc/src/sgml/pgbench.sgml pgbench-duration/doc/src/sgml/pgbench.sgml *** head/doc/src/sgml/pgbench.sgml Wed Mar 19 12:33:21 2008 --- pgbench-duration/doc/src/sgml/pgbench.sgml Wed Aug 13 10:27:48 2008 *************** pgbench options< *** 174,179 **** --- 174,186 ---- + -T duration + + Duration of benchmark in seconds. -t and + -T are mutually exclusive. + + + -M querymode Choose the query mode from the follows. default is simple.