11/*
2- * $PostgreSQL: pgsql/contrib/pgbench/pgbench.c,v 1.53 2006/08/15 13:05:30 ishii Exp $
2+ * $PostgreSQL: pgsql/contrib/pgbench/pgbench.c,v 1.54 2006/09/13 00:39:19 ishii Exp $
33 *
44 * pgbench: a simple benchmark program for PostgreSQL
55 * written by Tatsuo Ishii
@@ -58,10 +58,10 @@ int nclients = 1; /* default number of simulated clients */
5858int nxacts = 10 ; /* default number of transactions per clients */
5959
6060/*
61- * scaling factor. for example, tps = 10 will make 1000000 tuples of
61+ * scaling factor. for example, scale = 10 will make 1000000 tuples of
6262 * accounts table.
6363 */
64- int tps = 1 ;
64+ int scale = 1 ;
6565
6666/*
6767 * end of configurable parameters
@@ -134,9 +134,9 @@ int num_files; /* its number */
134134
135135/* default scenario */
136136static char * tpc_b = {
137- "\\set nbranches :tps \n"
138- "\\set ntellers 10 * :tps \n"
139- "\\set naccounts 100000 * :tps \n"
137+ "\\set nbranches :scale \n"
138+ "\\set ntellers 10 * :scale \n"
139+ "\\set naccounts 100000 * :scale \n"
140140 "\\setrandom aid 1 :naccounts\n"
141141 "\\setrandom bid 1 :nbranches\n"
142142 "\\setrandom tid 1 :ntellers\n"
@@ -152,9 +152,9 @@ static char *tpc_b = {
152152
153153/* -N case */
154154static char * simple_update = {
155- "\\set nbranches :tps \n"
156- "\\set ntellers 10 * :tps \n"
157- "\\set naccounts 100000 * :tps \n"
155+ "\\set nbranches :scale \n"
156+ "\\set ntellers 10 * :scale \n"
157+ "\\set naccounts 100000 * :scale \n"
158158 "\\setrandom aid 1 :naccounts\n"
159159 "\\setrandom bid 1 :nbranches\n"
160160 "\\setrandom tid 1 :ntellers\n"
@@ -168,7 +168,7 @@ static char *simple_update = {
168168
169169/* -S case */
170170static char * select_only = {
171- "\\set naccounts 100000 * :tps \n"
171+ "\\set naccounts 100000 * :scale \n"
172172 "\\setrandom aid 1 :naccounts\n"
173173 "SELECT abalance FROM accounts WHERE aid = :aid;\n"
174174};
@@ -338,10 +338,13 @@ putVariable(CState * st, char *name, char *value)
338338 }
339339 else
340340 {
341- if ((value = strdup (value )) == NULL )
341+ char * val ;
342+
343+ if ((val = strdup (value )) == NULL )
342344 return false;
345+
343346 free (var -> value );
344- var -> value = value ;
347+ var -> value = val ;
345348 }
346349
347350 return true;
@@ -755,7 +758,7 @@ init(void)
755758 }
756759 PQclear (res );
757760
758- for (i = 0 ; i < nbranches * tps ; i ++ )
761+ for (i = 0 ; i < nbranches * scale ; i ++ )
759762 {
760763 snprintf (sql , 256 , "insert into branches(bid,bbalance) values(%d,0)" , i + 1 );
761764 res = PQexec (con , sql );
@@ -767,7 +770,7 @@ init(void)
767770 PQclear (res );
768771 }
769772
770- for (i = 0 ; i < ntellers * tps ; i ++ )
773+ for (i = 0 ; i < ntellers * scale ; i ++ )
771774 {
772775 snprintf (sql , 256 , "insert into tellers(tid,bid,tbalance) values (%d,%d,0)"
773776 ,i + 1 , i / ntellers + 1 );
@@ -792,7 +795,7 @@ init(void)
792795 * occupy accounts table with some data
793796 */
794797 fprintf (stderr , "creating tables...\n" );
795- for (i = 0 ; i < naccounts * tps ; i ++ )
798+ for (i = 0 ; i < naccounts * scale ; i ++ )
796799 {
797800 int j = i + 1 ;
798801
@@ -1133,7 +1136,7 @@ printResults(
11331136 s = "Custom query" ;
11341137
11351138 printf ("transaction type: %s\n" , s );
1136- printf ("scaling factor: %d\n" , tps );
1139+ printf ("scaling factor: %d\n" , scale );
11371140 printf ("number of clients: %d\n" , nclients );
11381141 printf ("number of transactions per client: %d\n" , nxacts );
11391142 printf ("number of transactions actually processed: %d/%d\n" , normal_xacts , nxacts * nclients );
@@ -1175,6 +1178,8 @@ main(int argc, char **argv)
11751178 PGresult * res ;
11761179 char * env ;
11771180
1181+ char val [64 ];
1182+
11781183 if ((env = getenv ("PGHOST" )) != NULL && * env != '\0' )
11791184 pghost = env ;
11801185 if ((env = getenv ("PGPORT" )) != NULL && * env != '\0' )
@@ -1248,10 +1253,10 @@ main(int argc, char **argv)
12481253 is_connect = 1 ;
12491254 break ;
12501255 case 's' :
1251- tps = atoi (optarg );
1252- if (tps <= 0 )
1256+ scale = atoi (optarg );
1257+ if (scale <= 0 )
12531258 {
1254- fprintf (stderr , "invalid scaling factor: %d\n" , tps );
1259+ fprintf (stderr , "invalid scaling factor: %d\n" , scale );
12551260 exit (1 );
12561261 }
12571262 break ;
@@ -1323,12 +1328,10 @@ main(int argc, char **argv)
13231328
13241329 remains = nclients ;
13251330
1326- if (getVariable (& state [0 ], "tps " ) == NULL )
1331+ if (getVariable (& state [0 ], "scale " ) == NULL )
13271332 {
1328- char val [64 ];
1329-
1330- snprintf (val , sizeof (val ), "%d" , tps );
1331- if (putVariable (& state [0 ], "tps" , val ) == false)
1333+ snprintf (val , sizeof (val ), "%d" , scale );
1334+ if (putVariable (& state [0 ], "scale" , val ) == false)
13321335 {
13331336 fprintf (stderr , "Couldn't allocate memory for variable\n" );
13341337 exit (1 );
@@ -1405,13 +1408,20 @@ main(int argc, char **argv)
14051408 fprintf (stderr , "%s" , PQerrorMessage (con ));
14061409 exit (1 );
14071410 }
1408- tps = atoi (PQgetvalue (res , 0 , 0 ));
1409- if (tps < 0 )
1411+ scale = atoi (PQgetvalue (res , 0 , 0 ));
1412+ if (scale < 0 )
14101413 {
1411- fprintf (stderr , "count(*) from branches invalid (%d)\n" , tps );
1414+ fprintf (stderr , "count(*) from branches invalid (%d)\n" , scale );
14121415 exit (1 );
14131416 }
14141417 PQclear (res );
1418+
1419+ snprintf (val , sizeof (val ), "%d" , scale );
1420+ if (putVariable (& state [0 ], "scale" , val ) == false)
1421+ {
1422+ fprintf (stderr , "Couldn't allocate memory for variable\n" );
1423+ exit (1 );
1424+ }
14151425 }
14161426
14171427 if (!is_no_vacuum )
0 commit comments