1
1
/*
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 $
3
3
*
4
4
* pgbench: a simple benchmark program for PostgreSQL
5
5
* written by Tatsuo Ishii
@@ -58,10 +58,10 @@ int nclients = 1; /* default number of simulated clients */
58
58
int nxacts = 10 ; /* default number of transactions per clients */
59
59
60
60
/*
61
- * scaling factor. for example, tps = 10 will make 1000000 tuples of
61
+ * scaling factor. for example, scale = 10 will make 1000000 tuples of
62
62
* accounts table.
63
63
*/
64
- int tps = 1 ;
64
+ int scale = 1 ;
65
65
66
66
/*
67
67
* end of configurable parameters
@@ -134,9 +134,9 @@ int num_files; /* its number */
134
134
135
135
/* default scenario */
136
136
static 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"
140
140
"\\setrandom aid 1 :naccounts\n"
141
141
"\\setrandom bid 1 :nbranches\n"
142
142
"\\setrandom tid 1 :ntellers\n"
@@ -152,9 +152,9 @@ static char *tpc_b = {
152
152
153
153
/* -N case */
154
154
static 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"
158
158
"\\setrandom aid 1 :naccounts\n"
159
159
"\\setrandom bid 1 :nbranches\n"
160
160
"\\setrandom tid 1 :ntellers\n"
@@ -168,7 +168,7 @@ static char *simple_update = {
168
168
169
169
/* -S case */
170
170
static char * select_only = {
171
- "\\set naccounts 100000 * :tps \n"
171
+ "\\set naccounts 100000 * :scale \n"
172
172
"\\setrandom aid 1 :naccounts\n"
173
173
"SELECT abalance FROM accounts WHERE aid = :aid;\n"
174
174
};
@@ -338,10 +338,13 @@ putVariable(CState * st, char *name, char *value)
338
338
}
339
339
else
340
340
{
341
- if ((value = strdup (value )) == NULL )
341
+ char * val ;
342
+
343
+ if ((val = strdup (value )) == NULL )
342
344
return false;
345
+
343
346
free (var -> value );
344
- var -> value = value ;
347
+ var -> value = val ;
345
348
}
346
349
347
350
return true;
@@ -755,7 +758,7 @@ init(void)
755
758
}
756
759
PQclear (res );
757
760
758
- for (i = 0 ; i < nbranches * tps ; i ++ )
761
+ for (i = 0 ; i < nbranches * scale ; i ++ )
759
762
{
760
763
snprintf (sql , 256 , "insert into branches(bid,bbalance) values(%d,0)" , i + 1 );
761
764
res = PQexec (con , sql );
@@ -767,7 +770,7 @@ init(void)
767
770
PQclear (res );
768
771
}
769
772
770
- for (i = 0 ; i < ntellers * tps ; i ++ )
773
+ for (i = 0 ; i < ntellers * scale ; i ++ )
771
774
{
772
775
snprintf (sql , 256 , "insert into tellers(tid,bid,tbalance) values (%d,%d,0)"
773
776
,i + 1 , i / ntellers + 1 );
@@ -792,7 +795,7 @@ init(void)
792
795
* occupy accounts table with some data
793
796
*/
794
797
fprintf (stderr , "creating tables...\n" );
795
- for (i = 0 ; i < naccounts * tps ; i ++ )
798
+ for (i = 0 ; i < naccounts * scale ; i ++ )
796
799
{
797
800
int j = i + 1 ;
798
801
@@ -1133,7 +1136,7 @@ printResults(
1133
1136
s = "Custom query" ;
1134
1137
1135
1138
printf ("transaction type: %s\n" , s );
1136
- printf ("scaling factor: %d\n" , tps );
1139
+ printf ("scaling factor: %d\n" , scale );
1137
1140
printf ("number of clients: %d\n" , nclients );
1138
1141
printf ("number of transactions per client: %d\n" , nxacts );
1139
1142
printf ("number of transactions actually processed: %d/%d\n" , normal_xacts , nxacts * nclients );
@@ -1175,6 +1178,8 @@ main(int argc, char **argv)
1175
1178
PGresult * res ;
1176
1179
char * env ;
1177
1180
1181
+ char val [64 ];
1182
+
1178
1183
if ((env = getenv ("PGHOST" )) != NULL && * env != '\0' )
1179
1184
pghost = env ;
1180
1185
if ((env = getenv ("PGPORT" )) != NULL && * env != '\0' )
@@ -1248,10 +1253,10 @@ main(int argc, char **argv)
1248
1253
is_connect = 1 ;
1249
1254
break ;
1250
1255
case 's' :
1251
- tps = atoi (optarg );
1252
- if (tps <= 0 )
1256
+ scale = atoi (optarg );
1257
+ if (scale <= 0 )
1253
1258
{
1254
- fprintf (stderr , "invalid scaling factor: %d\n" , tps );
1259
+ fprintf (stderr , "invalid scaling factor: %d\n" , scale );
1255
1260
exit (1 );
1256
1261
}
1257
1262
break ;
@@ -1323,12 +1328,10 @@ main(int argc, char **argv)
1323
1328
1324
1329
remains = nclients ;
1325
1330
1326
- if (getVariable (& state [0 ], "tps " ) == NULL )
1331
+ if (getVariable (& state [0 ], "scale " ) == NULL )
1327
1332
{
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)
1332
1335
{
1333
1336
fprintf (stderr , "Couldn't allocate memory for variable\n" );
1334
1337
exit (1 );
@@ -1405,13 +1408,20 @@ main(int argc, char **argv)
1405
1408
fprintf (stderr , "%s" , PQerrorMessage (con ));
1406
1409
exit (1 );
1407
1410
}
1408
- tps = atoi (PQgetvalue (res , 0 , 0 ));
1409
- if (tps < 0 )
1411
+ scale = atoi (PQgetvalue (res , 0 , 0 ));
1412
+ if (scale < 0 )
1410
1413
{
1411
- fprintf (stderr , "count(*) from branches invalid (%d)\n" , tps );
1414
+ fprintf (stderr , "count(*) from branches invalid (%d)\n" , scale );
1412
1415
exit (1 );
1413
1416
}
1414
1417
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
+ }
1415
1425
}
1416
1426
1417
1427
if (!is_no_vacuum )
0 commit comments