Add support for auto-setting maximum worker thread
authorGreg Smith <gsmith@gregsmith.com>
Mon, 15 Mar 2010 14:37:06 +0000 (10:37 -0400)
committerGreg Smith <gsmith@gregsmith.com>
Mon, 15 Mar 2010 14:37:06 +0000 (10:37 -0400)
count to match client one, up to configured maximum

benchwarmer
config
init/resultdb.sql
report.sql

index a8d28dd54d96f6669d721e1ff217a9e5e7786a85..a8e77afeb0fa40a36a5c86595aa23c4db9d47f5b 100755 (executable)
@@ -39,6 +39,34 @@ function get_bgwriter {
 TRANS=`expr $TOTTRANS / $CLIENTS`
 TOTTRANS=`expr $TRANS \* $CLIENTS`
 
+# Set WORKERS string so that the largest possible worker count
+# up to MAX_WORKERS is used, while still dividing CLIENTS into an
+# even number per worker.
+WORKERS=""
+NUM_WORKERS="1"
+
+if [ -n "$MAX_WORKERS" ] ; then
+
+  # Only bother with/allow adjustment to WORKERS if the max is >1.
+  # That keeps up out of trouble if using a pgbench before 9.0,
+  # where using any value for "-j" won't be allowed, as long as the
+  # config file we're given isn't setup incorrectly.
+
+  if [ "$MAX_WORKERS" -gt 1 ]; then
+    NUM_WORKERS=$MAX_WORKERS
+
+    while [ "$NUM_WORKERS" -gt 1 ]; do
+      (( remainder=$CLIENTS % $NUM_WORKERS ))
+      if [ $remainder -eq 0 ] ; then
+        break
+      fi
+      (( NUM_WORKERS = $NUM_WORKERS - 1 ))
+    done
+
+    WORKERS="-j ${NUM_WORKERS}"
+  fi
+fi
+
 # psql statements for the test database and the result database
 TESTPSQL="psql -h $TESTHOST -U $TESTUSER -p $TESTPORT -d $TESTDB"
 RESULTPSQL="psql -h $RESULTHOST -U $RESULTUSER -p $RESULTPORT -d $RESULTDB"
@@ -71,7 +99,7 @@ if [ "$?" -ne "0" ]; then
   exit
 fi
 
-# Cleanuip pgbench tables, unless we've been told to skip that
+# Cleanup pgbench tables, unless we've been told to skip that
 if [ "$SKIPINIT" -ne "1" ]; then
   echo Cleaning up database $TESTDB
   $TESTPSQL -c "truncate table ${TABLEPREFIX}history"
@@ -84,7 +112,7 @@ fi
 
 # Create the tests record
 DBSIZE=`$TESTPSQL -A -t -c "select pg_database_size('$TESTDB')"`
-$RESULTPSQL -q -c "insert into tests (script,clients,trans,set,scale,dbsize) values('$SCRIPT','$CLIENTS','$TOTTRANS','$SET','$SCALE','$DBSIZE')"
+$RESULTPSQL -q -c "insert into tests (script,clients,workers,trans,set,scale,dbsize) values('$SCRIPT','$CLIENTS','$NUM_WORKERS','$TOTTRANS','$SET','$SCALE','$DBSIZE')"
 TEST=`$RESULTPSQL -A -t -c "select max(test) from tests"`
 if [ "$?" -ne "0" ]; then
   echo ERROR  Can\'t read from tests table.  Was the test data installed?
@@ -106,7 +134,7 @@ mkdir -p results/$TEST
 cd results/$TEST
 
 echo Script $SCRIPT executing $TRANS transactions for each of $CLIENTS concurrent users... 1>&2
-$PGBENCHBIN -f $BASEDIR/$TESTDIR/$SCRIPT -s $SCALE -l -n -U $TESTUSER -t $TRANS -h $TESTHOST -c $CLIENTS $TESTDB > results.txt &
+$PGBENCHBIN -f $BASEDIR/$TESTDIR/$SCRIPT -s $SCALE -l -n -U $TESTUSER -t $TRANS -h $TESTHOST -c $CLIENTS $WORKERS $TESTDB > results.txt &
 P=$!
 wait $P
 $RESULTPSQL -q -c "update tests set end_time=now() where test=$TEST"
diff --git a/config b/config
index bc1790331d6e699a2a28117abe3668741000e6e0..372f43a5e9554ee31b6cb037becb943be89765f6 100755 (executable)
--- a/config
+++ b/config
@@ -9,6 +9,15 @@ TESTDIR="tests"
 #TABLEPREFIX=""
 #TESTDIR="tests-8.3"
 
+# Set this to a number only when using pgbench 9.0 or later.  This will set
+# the number of worker threads up to this maximum for each client count
+MAX_WORKERS=""
+
+# SKIPINIT should be set to 1 either when simulating a cold cache, or
+# if you are not using the pgbench tables for your test
+SKIPINIT=0
+
+# Test/result database connection
 TESTHOST=localhost
 TESTUSER=postgres
 TESTPORT=5432
@@ -19,13 +28,9 @@ RESULTUSER="$TESTUSER"
 RESULTPORT="$TESTPORT"
 RESULTDB=results
 
-SCALES="1 10 100 1000"
+# Test run customization
 SCRIPT="select.sql"
 TOTTRANS=100000
-
-SETTIMES=3
 SETCLIENTS="1 2 4 8 16 32"
-
-# SKIPINIT should be set to 1 either when simulating a cold cache, or
-# if you are not using the pgbench tables for your test
-SKIPINIT=0
+SCALES="1 10 100 1000"
+SETTIMES=3
index 9996fcdb3443b39878d0869920568558c3d2e374..60e2ef883f57e631a1b0cf41d77e982f71d65e6b 100644 (file)
@@ -21,6 +21,7 @@ CREATE TABLE tests(
   tps decimal default 0,
   script text,
   clients int,
+  workers int,
   trans int,
   avg_latency float,
   max_latency float,
index 9229efde2d6ebb6e1fc68907c1b9a380d75940af..9dd20657aa1ad439c282e297def87aa06cc1195e 100644 (file)
@@ -1 +1 @@
-select set,scale,test,script,clients,round(tps) as tps,round(1000*avg_latency)/1000 as avg_latency,round(1000*percentile_90_latency)/1000 as "90%<",1000*round(max_latency)/1000 as max_latency,trans from tests order by set,scale,script,clients,test; 
+select set,scale,test,script,clients,workers,round(tps) as tps,round(1000*avg_latency)/1000 as avg_latency,round(1000*percentile_90_latency)/1000 as "90%<",1000*round(max_latency)/1000 as max_latency,trans from tests order by set,scale,script,clients,test;