Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitcdf4b9a

Browse files
committed
Apply patches from Neil Conway.
> Hi Tatsuo,>> I've attached a patch for the version of pgbench in CVS. It includes the> following changes:>> - fix some spelling mistakes, indentation stuff, etc.>> - minor code cleanup -- (void) args instead of (), etc.>> - allocate the state array dynamically, so that it is only as> large as needed. This reduces the memory consumption of pgbench> slightly, and makes a larger MAXCLIENTS setting possible>> - (the only controversial change) add an option "-l" to log> transaction latencies to a file. The "transaction latency"> is the time between when the BEGIN is issued and the transaction> commits. This is written to a file, along with the client #> and the transaction #. The data in the file can then be used> for things like:>> - consistency analysis: is the TPS the same through the> entire run of pgbench, or does it change?>> - more detailed stats: what is the average latency, worse-case> latency, best-case latency?>> - graphs: feed the data to gnuplot, graph latency versus. time>> - etc.>> I was going to store this data in memory and write it to disk> at the end of the pgbench run, but that isn't feasible because> the data can be very large: for example, ~70MB if benchmarking> 128 clients doing 100,000 transactions each.>> Cheers,>> Neil
1 parent009d593 commitcdf4b9a

File tree

3 files changed

+100
-40
lines changed

3 files changed

+100
-40
lines changed

‎contrib/pgbench/README.pgbench

Lines changed: 23 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
pgbench README2001/10/24 Tatsuo Ishii (t-ishii@sra.co.jp)
1+
pgbench README2002/07/20 Tatsuo Ishii (t-ishii@sra.co.jp)
22

33
o What is pgbench?
44

@@ -101,7 +101,7 @@ o options
101101
(10,000,000) tuples in the accounts table.
102102
default is 1.
103103

104-
-U login
104+
-U login
105105
Specify db user's login name if it is different from
106106
the Unix login name.
107107

@@ -111,7 +111,7 @@ o options
111111
show the password. Use this for TESTING PURPOSE ONLY.
112112

113113
-n
114-
No vacuuming and cleaning the history table prior the
114+
No vacuuming and cleaning the history table priortothe
115115
test is performed.
116116

117117
-v
@@ -122,10 +122,19 @@ o options
122122
-S
123123
Perform select only transactions instead of TPC-B.
124124

125-
-C
125+
-C
126126
Establish connection for each transaction, rather than
127-
doing it just once at begining of pgbench in the normal
128-
mode. This is usefull to measure the connection overhead.
127+
doing it just once at beginning of pgbench in the normal
128+
mode. This is useful to measure the connection overhead.
129+
130+
-l
131+
Write the time taken by each transaction to a logfile,
132+
with the name "pgbench_log.xxx", where xxx is the PID
133+
of the pgbench process. The format of the log is:
134+
135+
client_id transaction_no time
136+
137+
where time is measured in microseconds.
129138

130139
-d
131140
debug option.
@@ -153,6 +162,14 @@ Basically it is same as BSD license. See pgbench.c for more details.
153162

154163
o History
155164

165+
2002/07/20
166+
* patch contributed by Neil Conway.
167+
* code/document clean up and add -l option.
168+
169+
2002/02/24
170+
* do not CHECKPOINT anymore while initializing benchmark
171+
* database. Add -N option.
172+
156173
2001/10/24
157174
* "time"->"mtime"
158175

‎contrib/pgbench/README.pgbench_jis

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
pgbench README2002/02/24 Tatsuo Ishii (t-ishii@sra.co.jp)
1+
pgbench README2002/07/20 Tatsuo Ishii (t-ishii@sra.co.jp)
22

33
$B"#(Bpgbench $B$H$O!)(B
44

@@ -104,18 +104,19 @@ pgbench $B$K$O$$$m$$$m$J%*%W%7%g%s$,$"$j$^$9!%(B
104104
$B$OE,9g$7$J$/$J$j$^$9$,!$$h$j8=<BE*$JIi2Y$r%F%9%H$9$k$3(B
105105
$B$H$,$G$-$^$9!%(B
106106

107-
-N
108-
"branches"$B$H(B"tellers"$B%F!<%V%k$N99?7$r9T$$$^$;$s!%$3$l(B
109-
$B$K$h$C$F(B"branches"$B$H(B"tellers"$B$X$NBgNL$N99?7$N6%9g$N$J(B
110-
$B$$>uBV$G$NB,Dj$r9T$$$^$9!%$7$?$,$C$F(BTPC-B$B$N%9%Z%C%/$K(B
111-
$B$OE,9g$7$J$/$J$j$^$9$,!$$h$j8=<BE*$JIi2Y$r%F%9%H$9$k$3(B
112-
$B$H$,$G$-$^$9!%(B
113-
114107
-C$B$3$N%*%W%7%g%s$r;XDj$9$k$H!$:G=i$K3NN)$7$?%3%M%/%7%g%s(B
115108
$B$r;H$$2s$9$N$G$O$J$/!$3F%H%i%s%6%/%7%g%s$4$H$K(BDB$B$X$N@\(B
116109
$BB3$r9T$$$^$9!%%3%M%/%7%g%s$N%*!<%P!<$X%C%I$rB,Dj$9$k$N(B
117110
$B$KM-8z$G$9!%(B
118111

112+
-l$B8D!9$N%H%i%s%6%/%7%g%s$N<B9T;~4V$r5-O?$7$^$9!%5-O?@h$O(B
113+
$B%+%l%s%H%G%#%l%/%H%j0J2<$N(Bpgbench_log.xxx$B$H$$$&%U%!%$(B
114+
$B%k$G$9!%%U%!%$%k$N%U%)!<%^%C%H$O!$(B
115+
116+
$B%/%i%$%"%s%H(BID$B%H%i%s%6%/%7%g%sHV9f(B $B;~4V(B
117+
118+
$B$H$J$C$F$$$^$9!%;~4V$O%^%$%/%mICC10L$G$9!%(B
119+
119120
-d$B%G%P%C%0%*%W%7%g%s!%MM!9$J>pJs$,I=<($5$l$^$9!%(B
120121

121122
$B"#%G!<%?%Y!<%9$N=i4|2=(B
@@ -183,10 +184,9 @@ pgbench $B$O@P0f(B $BC#IW$K$h$C$F=q$+$l$^$7$?!%%i%$%;%s%9>r7o$O(B pgbench.c
183184

184185
$B"#2~DjMzNr(B
185186

186-
2002/02/24
187-
* $B$3$3$+$i$O(B7.3$BMQ$NJQ99$G$9!%(B
188-
* CHECKPOINT$B$NH/9T$r$d$a$^$7$?!%(B
189-
* -N $B%*%W%7%g%s$rDI2C$7$^$7$?!%(B
187+
2002/07/20
188+
* Nei Conway$B$5$s$N%Q%C%A$rE,MQ!%(B
189+
* -l $B%*%W%7%g%s$NDI2C!%(B
190190

191191
2002/02/24
192192
* $B$3$3$+$i$O(B7.3$BMQ$NJQ99$G$9!%(B

‎contrib/pgbench/pgbench.c

Lines changed: 65 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* $Header: /cvsroot/pgsql/contrib/pgbench/pgbench.c,v 1.16 2002/02/24 00:17:57 ishii Exp $
2+
* $Header: /cvsroot/pgsql/contrib/pgbench/pgbench.c,v 1.17 2002/07/20 03:02:01 ishii Exp $
33
*
44
* pgbench: a simple TPC-B like benchmark program for PostgreSQL
55
* written by Tatsuo Ishii
@@ -39,7 +39,7 @@
3939

4040
/* for getrlimit */
4141
#include<sys/resource.h>
42-
#endif/* WIN32 */
42+
#endif/*!WIN32 */
4343

4444
/********************************************************************
4545
* some configurable parameters */
@@ -64,10 +64,14 @@ inttps = 1;
6464
#definentellers10
6565
#definenaccounts100000
6666

67-
intremains;/* number of remained clients */
67+
FILE*LOGFILE=NULL;
68+
69+
booluse_log;/* log transaction latencies to a file */
70+
71+
intremains;/* number of remaining clients */
6872

6973
intis_connect;/* establish connection for each
70-
*transactoin */
74+
*transaction */
7175

7276
char*pghost="";
7377
char*pgport=NULL;
@@ -80,22 +84,24 @@ char *dbName;
8084
typedefstruct
8185
{
8286
PGconn*con;/* connection handle to DB */
87+
intid;/* client No. */
8388
intstate;/* state No. */
8489
intcnt;/* xacts count */
8590
intecnt;/* error count */
86-
intlisten;/*none0 indicates that an async query
91+
intlisten;/* 0 indicates that an async query
8792
* has been sent */
8893
intaid;/* account id for this transaction */
8994
intbid;/* branch id for this transaction */
9095
inttid;/* teller id for this transaction */
9196
intdelta;
9297
intabalance;
98+
structtimevaltxn_begin;/* used for measuring latencies */
9399
}CState;
94100

95101
staticvoid
96102
usage()
97103
{
98-
fprintf(stderr,"usage: pgbench [-h hostname][-p port][-c nclients][-t ntransactions][-s scaling_factor][-n][-C][-v][-S][-N][-U login][-P password][-d][dbname]\n");
104+
fprintf(stderr,"usage: pgbench [-h hostname][-p port][-c nclients][-t ntransactions][-s scaling_factor][-n][-C][-v][-S][-N][-l][-U login][-P password][-d][dbname]\n");
99105
fprintf(stderr,"(initialize mode): pgbench -i [-h hostname][-p port][-s scaling_factor][-U login][-P password][-d][dbname]\n");
100106
}
101107

@@ -235,6 +241,19 @@ doOne(CState * state, int n, int debug, int ttype)
235241
discard_response(st);
236242
break;
237243
case6:/* response to "end" */
244+
/* transaction finished: record the time it took in the log */
245+
if (use_log)
246+
{
247+
long longdiff;
248+
structtimevalnow;
249+
250+
gettimeofday(&now,0);
251+
diff= (now.tv_sec-st->txn_begin.tv_sec)*1000000+
252+
(now.tv_usec-st->txn_begin.tv_usec);
253+
254+
fprintf(LOGFILE,"%d %d %lld\n",st->id,st->cnt,diff);
255+
}
256+
238257
res=PQgetResult(st->con);
239258
if (check(state,res,n,PGRES_COMMAND_OK))
240259
return;
@@ -249,7 +268,7 @@ doOne(CState * state, int n, int debug, int ttype)
249268

250269
if (++st->cnt >=nxacts)
251270
{
252-
remains--;/* I've done */
271+
remains--;/* I'm done */
253272
if (st->con!=NULL)
254273
{
255274
PQfinish(st->con);
@@ -287,6 +306,8 @@ doOne(CState * state, int n, int debug, int ttype)
287306
st->bid=getrand(1,nbranches*tps);
288307
st->tid=getrand(1,ntellers*tps);
289308
st->delta=getrand(1,1000);
309+
if (use_log)
310+
gettimeofday(&(st->txn_begin),0);
290311
break;
291312
case1:
292313
sprintf(sql,"update accounts set abalance = abalance + %d where aid = %d\n",st->delta,st->aid);
@@ -326,7 +347,7 @@ doOne(CState * state, int n, int debug, int ttype)
326347
}
327348
else
328349
{
329-
st->listen++;/* flags that should belistned */
350+
st->listen++;/* flags that should belistened */
330351
}
331352
}
332353

@@ -420,7 +441,7 @@ doSelectOnly(CState * state, int n, int debug)
420441
}
421442
else
422443
{
423-
st->listen++;/* flags that should belistned */
444+
st->listen++;/* flags that should belistened */
424445
}
425446
}
426447

@@ -439,7 +460,7 @@ disconnect_all(CState * state)
439460

440461
/* create tables and setup data */
441462
staticvoid
442-
init()
463+
init(void)
443464
{
444465
PGconn*con;
445466
PGresult*res;
@@ -616,8 +637,8 @@ printResults(
616637
printf("number of clients: %d\n",nclients);
617638
printf("number of transactions per client: %d\n",nxacts);
618639
printf("number of transactions actually processed: %d/%d\n",normal_xacts,nxacts*nclients);
619-
printf("tps = %f(including connections establishing)\n",t1);
620-
printf("tps = %f(excluding connections establishing)\n",t2);
640+
printf("tps = %f(including connections establishing)\n",t1);
641+
printf("tps = %f(excluding connections establishing)\n",t2);
621642
}
622643

623644

@@ -634,11 +655,10 @@ main(int argc, char **argv)
634655
* testing? */
635656
intis_full_vacuum=0;/* do full vacuum before testing? */
636657
intdebug=0;/* debug flag */
637-
intttype=0;/* transaction type. 0: TPC-B, 1: SELECT
638-
* only
639-
2: skip updation of branches and tellers */
658+
intttype=0;/* transaction type. 0: TPC-B, 1: SELECT only,
659+
* 2: skip update of branches and tellers */
640660

641-
staticCStatestate[MAXCLIENTS];/*clientsstatus */
661+
staticCState*state;/* status of clients */
642662

643663
structtimevaltv1;/* start up time */
644664
structtimevaltv2;/* after establishing all connections to
@@ -658,7 +678,7 @@ main(int argc, char **argv)
658678
PGconn*con;
659679
PGresult*res;
660680

661-
while ((c=getopt(argc,argv,"ih:nvp:dc:t:s:U:P:CNS"))!=-1)
681+
while ((c=getopt(argc,argv,"ih:nvp:dc:t:s:U:P:CNSl"))!=-1)
662682
{
663683
switch (c)
664684
{
@@ -690,7 +710,7 @@ main(int argc, char **argv)
690710
nclients=atoi(optarg);
691711
if (nclients <=0||nclients>MAXCLIENTS)
692712
{
693-
fprintf(stderr,"wrong number of clients: %d\n",nclients);
713+
fprintf(stderr,"invalid number of clients: %d\n",nclients);
694714
exit(1);
695715
}
696716
#ifndef__CYGWIN__
@@ -719,15 +739,15 @@ main(int argc, char **argv)
719739
tps=atoi(optarg);
720740
if (tps <=0)
721741
{
722-
fprintf(stderr,"wrong scaling factor: %d\n",tps);
742+
fprintf(stderr,"invalid scaling factor: %d\n",tps);
723743
exit(1);
724744
}
725745
break;
726746
case't':
727747
nxacts=atoi(optarg);
728748
if (nxacts <=0)
729749
{
730-
fprintf(stderr,"wrong number of transactions: %d\n",nxacts);
750+
fprintf(stderr,"invalid number of transactions: %d\n",nxacts);
731751
exit(1);
732752
}
733753
break;
@@ -737,6 +757,9 @@ main(int argc, char **argv)
737757
case'P':
738758
pwd=optarg;
739759
break;
760+
case'l':
761+
use_log= true;
762+
break;
740763
default:
741764
usage();
742765
exit(1);
@@ -761,6 +784,23 @@ main(int argc, char **argv)
761784

762785
remains=nclients;
763786

787+
state= (CState*)malloc(sizeof(*state)*nclients);
788+
memset(state,0,sizeof(*state));
789+
790+
if (use_log)
791+
{
792+
charlogpath[64];
793+
794+
snprintf(logpath,64,"pgbench_log.%d",getpid());
795+
LOGFILE=fopen(logpath,"w");
796+
797+
if (LOGFILE==NULL)
798+
{
799+
fprintf(stderr,"Couldn't open logfile \"%s\": %s",logpath,strerror(errno));
800+
exit(1);
801+
}
802+
}
803+
764804
if (debug)
765805
{
766806
printf("pghost: %s pgport: %s nclients: %d nxacts: %d dbName: %s\n",
@@ -860,6 +900,7 @@ main(int argc, char **argv)
860900
/* make connections to the database */
861901
for (i=0;i<nclients;i++)
862902
{
903+
state[i].id=i;
863904
if ((state[i].con=doConnect())==NULL)
864905
exit(1);
865906
}
@@ -868,7 +909,7 @@ main(int argc, char **argv)
868909
/* time after connections set up */
869910
gettimeofday(&tv2,0);
870911

871-
/* send start upquries in async manner */
912+
/* send start upqueries in async manner */
872913
for (i=0;i<nclients;i++)
873914
{
874915
if (ttype==0||ttype==2)
@@ -885,6 +926,8 @@ main(int argc, char **argv)
885926
/* get end time */
886927
gettimeofday(&tv3,0);
887928
printResults(ttype,state,&tv1,&tv2,&tv3);
929+
if (LOGFILE)
930+
fclose(LOGFILE);
888931
exit(0);
889932
}
890933

@@ -899,7 +942,7 @@ main(int argc, char **argv)
899942

900943
if (sock<0)
901944
{
902-
fprintf(stderr,"Client %d:PQsock failed\n",i);
945+
fprintf(stderr,"Client %d:PQsocket failed\n",i);
903946
disconnect_all(state);
904947
exit(1);
905948
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp