1
1
/*
2
- * $Header: /cvsroot/pgsql/contrib/pgbench/pgbench.c,v 1.15 2002/02/18 05:46:41 momjian Exp $
2
+ * $Header: /cvsroot/pgsql/contrib/pgbench/pgbench.c,v 1.16 2002/02/24 00:17:57 ishii Exp $
3
3
*
4
4
* pgbench: a simple TPC-B like benchmark program for PostgreSQL
5
5
* written by Tatsuo Ishii
6
6
*
7
- * Copyright (c) 2000 Tatsuo Ishii
7
+ * Copyright (c) 2000-2002 Tatsuo Ishii
8
8
*
9
9
* Permission to use, copy, modify, and distribute this software and
10
10
* its documentation for any purpose and without fee is hereby
@@ -95,7 +95,7 @@ typedef struct
95
95
static void
96
96
usage ()
97
97
{
98
- fprintf (stderr , "usage: pgbench [-h hostname][-p port][-c nclients][-t ntransactions][-s scaling_factor][-n][-C][-v][-S][-U login][-P password][-d][dbname]\n" );
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" );
99
99
fprintf (stderr , "(initialize mode): pgbench -i [-h hostname][-p port][-s scaling_factor][-U login][-P password][-d][dbname]\n" );
100
100
}
101
101
@@ -168,7 +168,7 @@ check(CState * state, PGresult *res, int n, int good)
168
168
169
169
/* process a transaction */
170
170
static void
171
- doOne (CState * state , int n , int debug )
171
+ doOne (CState * state , int n , int debug , int ttype )
172
172
{
173
173
char sql [256 ];
174
174
PGresult * res ;
@@ -295,12 +295,18 @@ doOne(CState * state, int n, int debug)
295
295
sprintf (sql , "select abalance from accounts where aid = %d" , st -> aid );
296
296
break ;
297
297
case 3 :
298
- sprintf (sql , "update tellers set tbalance = tbalance + %d where tid = %d\n" ,
299
- st -> delta , st -> tid );
300
- break ;
298
+ if (ttype == 0 )
299
+ {
300
+ sprintf (sql , "update tellers set tbalance = tbalance + %d where tid = %d\n" ,
301
+ st -> delta , st -> tid );
302
+ break ;
303
+ }
301
304
case 4 :
302
- sprintf (sql , "update branches set bbalance = bbalance + %d where bid = %d" , st -> delta , st -> bid );
303
- break ;
305
+ if (ttype == 0 )
306
+ {
307
+ sprintf (sql , "update branches set bbalance = bbalance + %d where bid = %d" , st -> delta , st -> bid );
308
+ break ;
309
+ }
304
310
case 5 :
305
311
sprintf (sql , "insert into history(tid,bid,aid,delta,mtime) values(%d,%d,%d,%d,'now')" ,
306
312
st -> tid , st -> bid , st -> aid , st -> delta );
@@ -548,6 +554,18 @@ init()
548
554
fprintf (stderr , "PQendcopy failed\n" );
549
555
exit (1 );
550
556
}
557
+
558
+ #ifdef NOT_USED
559
+ /*
560
+ * do a checkpoint to purge the old WAL logs
561
+ */
562
+ res = PQexec (con , "checkpoint" );
563
+ if (PQresultStatus (res ) != PGRES_COMMAND_OK )
564
+ {
565
+ fprintf (stderr , "%s" , PQerrorMessage (con ));
566
+ exit (1 );
567
+ }
568
+ #endif /* NOT_USED */
551
569
}
552
570
}
553
571
@@ -575,6 +593,7 @@ printResults(
575
593
t2 ;
576
594
int i ;
577
595
int normal_xacts = 0 ;
596
+ char * s ;
578
597
579
598
for (i = 0 ; i < nclients ; i ++ )
580
599
normal_xacts += state [i ].cnt ;
@@ -585,7 +604,14 @@ printResults(
585
604
t2 = (tv3 -> tv_sec - tv2 -> tv_sec ) * 1000000.0 + (tv3 -> tv_usec - tv2 -> tv_usec );
586
605
t2 = normal_xacts * 1000000.0 / t2 ;
587
606
588
- printf ("transaction type: %s\n" , ttype == 0 ? "TPC-B (sort of)" : "SELECT only" );
607
+ if (ttype == 0 )
608
+ s = "TPC-B (sort of)" ;
609
+ else if (ttype == 2 )
610
+ s = "Update only accounts" ;
611
+ else
612
+ s = "SELECT only" ;
613
+
614
+ printf ("transaction type: %s\n" , s );
589
615
printf ("scaling factor: %d\n" , tps );
590
616
printf ("number of clients: %d\n" , nclients );
591
617
printf ("number of transactions per client: %d\n" , nxacts );
@@ -609,7 +635,8 @@ main(int argc, char **argv)
609
635
int is_full_vacuum = 0 ; /* do full vacuum before testing? */
610
636
int debug = 0 ; /* debug flag */
611
637
int ttype = 0 ; /* transaction type. 0: TPC-B, 1: SELECT
612
- * only */
638
+ * only
639
+ 2: skip updation of branches and tellers */
613
640
614
641
static CState state [MAXCLIENTS ]; /* clients status */
615
642
@@ -631,7 +658,7 @@ main(int argc, char **argv)
631
658
PGconn * con ;
632
659
PGresult * res ;
633
660
634
- while ((c = getopt (argc , argv , "ih:nvp:dc:t:s:U:P:CS " )) != -1 )
661
+ while ((c = getopt (argc , argv , "ih:nvp:dc:t:s:U:P:CNS " )) != -1 )
635
662
{
636
663
switch (c )
637
664
{
@@ -656,6 +683,9 @@ main(int argc, char **argv)
656
683
case 'S' :
657
684
ttype = 1 ;
658
685
break ;
686
+ case 'N' :
687
+ ttype = 2 ;
688
+ break ;
659
689
case 'c' :
660
690
nclients = atoi (optarg );
661
691
if (nclients <= 0 || nclients > MAXCLIENTS )
@@ -841,8 +871,8 @@ main(int argc, char **argv)
841
871
/* send start up quries in async manner */
842
872
for (i = 0 ; i < nclients ; i ++ )
843
873
{
844
- if (ttype == 0 )
845
- doOne (state , i , debug );
874
+ if (ttype == 0 || ttype == 2 )
875
+ doOne (state , i , debug , ttype );
846
876
else if (ttype == 1 )
847
877
doSelectOnly (state , i , debug );
848
878
}
@@ -905,8 +935,8 @@ main(int argc, char **argv)
905
935
{
906
936
if (state [i ].con && FD_ISSET (PQsocket (state [i ].con ), & input_mask ))
907
937
{
908
- if (ttype == 0 )
909
- doOne (state , i , debug );
938
+ if (ttype == 0 || ttype == 2 )
939
+ doOne (state , i , debug , ttype );
910
940
else if (ttype == 1 )
911
941
doSelectOnly (state , i , debug );
912
942
}
0 commit comments