pgbench: allow a script weight of zero
authorAlvaro Herrera <alvherre@alvh.no-ip.org>
Tue, 29 Mar 2016 17:13:51 +0000 (14:13 -0300)
committerAlvaro Herrera <alvherre@alvh.no-ip.org>
Tue, 29 Mar 2016 17:47:10 +0000 (14:47 -0300)
This refines the previous weight range and allows a script to be "turned
off" by passing a zero weight, which is useful when scripting multiple
pgbench runs.

I did not apply the suggested warning when a script uses zero weight; we
use the principle elsewhere that if there's nothing to be done, do
nothing quietly.

Adjust docs accordingly.

Author: Jeff Janes, Fabien Coelho

doc/src/sgml/ref/pgbench.sgml
src/bin/pgbench/pgbench.c

index c5399ff952a8a7e477b01f9caae0c8fe698710cc..1d13897030dd9596e80aec05e7f4543e6009bdb2 100644 (file)
@@ -698,6 +698,7 @@ pgbench <optional> <replaceable>options</> </optional> <replaceable>dbname</>
    Each script may be given a relative weight specified after a
    <literal>@</> so as to change its drawing probability.
    The default weight is <literal>1</>.
+   Scripts with a weight of <literal>0</> are ignored.
  </para>
 
   <para>
@@ -1259,17 +1260,17 @@ tps = 618.764555 (including connections establishing)
 tps = 622.977698 (excluding connections establishing)
 script statistics:
  - statement latencies in milliseconds:
-        0.002522        \set aid random(1, 100000 * :scale)
-        0.005459        \set bid random(1, 1 * :scale)
-        0.002348        \set tid random(1, 10 * :scale)
-        0.001078        \set delta random(-5000, 5000)
-        0.326152        BEGIN;
-        0.603376        UPDATE pgbench_accounts SET abalance = abalance + :delta WHERE aid = :aid;
-        0.454643        SELECT abalance FROM pgbench_accounts WHERE aid = :aid;
-        5.528491        UPDATE pgbench_tellers SET tbalance = tbalance + :delta WHERE tid = :tid;
-        7.335435        UPDATE pgbench_branches SET bbalance = bbalance + :delta WHERE bid = :bid;
-        0.371851        INSERT INTO pgbench_history (tid, bid, aid, delta, mtime) VALUES (:tid, :bid, :aid, :delta, CURRENT_TIMESTAMP);
-        1.212976        END;
+        0.002  \set aid random(1, 100000 * :scale)
+        0.005  \set bid random(1, 1 * :scale)
+        0.002  \set tid random(1, 10 * :scale)
+        0.001  \set delta random(-5000, 5000)
+        0.326  BEGIN;
+        0.603  UPDATE pgbench_accounts SET abalance = abalance + :delta WHERE aid = :aid;
+        0.454  SELECT abalance FROM pgbench_accounts WHERE aid = :aid;
+        5.528  UPDATE pgbench_tellers SET tbalance = tbalance + :delta WHERE tid = :tid;
+        7.335  UPDATE pgbench_branches SET bbalance = bbalance + :delta WHERE bid = :bid;
+        0.371  INSERT INTO pgbench_history (tid, bid, aid, delta, mtime) VALUES (:tid, :bid, :aid, :delta, CURRENT_TIMESTAMP);
+        1.212  END;
 </screen>
   </para>
 
index 90e538cedc92714ac0758fa07252c3f162a3bcf5..52d12239106ee4839790a276343dd0cbf0ed9717 100644 (file)
@@ -3054,10 +3054,10 @@ parseScriptWeight(const char *option, char **script)
            fprintf(stderr, "invalid weight specification: %s\n", sep);
            exit(1);
        }
-       if (wtmp > INT_MAX || wtmp <= 0)
+       if (wtmp > INT_MAX || wtmp < 0)
        {
            fprintf(stderr,
-           "weight specification out of range (1 .. %u): " INT64_FORMAT "\n",
+           "weight specification out of range (0 .. %u): " INT64_FORMAT "\n",
                    INT_MAX, (int64) wtmp);
            exit(1);
        }
@@ -3181,10 +3181,11 @@ printResults(TState *threads, StatsData *total, instr_time total_time,
        {
            if (num_scripts > 1)
                printf("SQL script %d: %s\n"
-                      " - weight = %d\n"
+                      " - weight = %d (targets %.1f%% of total)\n"
                       " - " INT64_FORMAT " transactions (%.1f%% of total, tps = %f)\n",
                       i + 1, sql_script[i].desc,
                       sql_script[i].weight,
+                      100.0 * sql_script[i].weight / total_weight,
                       sql_script[i].stats.cnt,
                       100.0 * sql_script[i].stats.cnt / total->cnt,
                       sql_script[i].stats.cnt / time_include);
@@ -3628,6 +3629,12 @@ main(int argc, char **argv)
        /* cannot overflow: weight is 32b, total_weight 64b */
        total_weight += sql_script[i].weight;
 
+   if (total_weight == 0 && !is_init_mode)
+   {
+       fprintf(stderr, "total script weight must not be zero\n");
+       exit(1);
+   }
+
    /* show per script stats if several scripts are used */
    if (num_scripts > 1)
        per_script_stats = true;