Check configuration before running any benchmarks
authorTomas Vondra <tv@fuzzy.cz>
Thu, 11 Aug 2016 00:00:32 +0000 (02:00 +0200)
committerTomas Vondra <tomas@2ndquadrant.com>
Mon, 27 Feb 2017 00:25:34 +0000 (01:25 +0100)
Before doing any heavy-lifting, check existence of directories,
binaries and some other sanity checks.

client/benchmarks/pgbench.py
client/benchmarks/runner.py
client/perffarm-client.py

index eaa84024c76fbb5ceaf300546addc210fb73e52e..2ec38d558b3843e1baa9ad7a035015bddfa298c4 100644 (file)
@@ -1,5 +1,6 @@
 import math
 import os
+import os.path
 import re
 import time
 
@@ -155,6 +156,35 @@ class PgBench(object):
                return '\n'.join(o)
 
 
+       def check_config(self):
+               'check pgbench configuration (existence of binaries etc.)'
+
+               issues = []
+
+               if not os.path.isdir(self._bin):
+                       issues.append("bin_dir='%s' does not exist" % (self._bin,))
+               elif not os.path.exists('%s/pgbench' % (self._bin,)):
+                       issues.append("pgbench not found in bin_dir='%s'" % (self._bin,))
+               elif not os.path.exists('%s/createdb' % (self._bin,)):
+                       issues.append("createdb not found in bin_dir='%s'" % (self._bin,))
+               elif not os.path.exists('%s/dropdb' % (self._bin,)):
+                       issues.append("dropdb not found in bin_dir='%s'" % (self._bin,))
+               elif not os.path.exists('%s/psql' % (self._bin,)):
+                       issues.append("psql not found in bin_dir='%s'" % (self._bin,))
+
+               if type(self._duration) is not int:
+                       issues.append("duration (%s) needs to be an integer" % (self._duration,))
+               elif not self._duration >= 1:
+                       issues.append("duration (%s) needs to be >= 1" % (self._duration,))
+
+               if type(self._runs) is not int:
+                       issues.append("runs (%s) needs to be an integer" % (self._duration,))
+               elif not self._runs >= 1:
+                       issues.append("runs (%s) needs to be >= 1" % (self._runs,))
+
+               return issues
+
+
        def _run(self, duration, nclients=1, njobs=1, read_only=False, aggregate=True):
                'run pgbench on the database (either a warmup or actual benchmark run)'
 
index 3a891dca9fdd0bd1cd5da555b9a014ec97b30124..b6ef293a40537d2aa41967a4c7d884a48abe1742 100644 (file)
@@ -32,6 +32,38 @@ class BenchmarkRunner(object):
                self._configs.update({config_name : {'benchmark' : benchmark_name, 'config' : kwargs, 'postgres' : postgres_config}})
 
 
+       def _check_config(self, config_name):
+               ''
+
+               log("checking benchmark configuration '%s'" % (config_name,))
+
+               # construct the benchmark class for the given config name
+               config = self._configs[config_name]
+               bench = self._benchmarks[config['benchmark']]
+
+               # expand the attribute names
+               bench = bench(**config['config'])
+
+               # run the tests
+               return bench.check_config()
+
+
+       def check(self):
+               'check configurations for all benchmarks'
+
+               issues = {}
+
+               if os.path.exists(self._output):
+                       issues['global'] = ["output directory '%s' already exists" % (self._output,)]
+
+               for config_name in self._configs:
+                       t = self._check_config(config_name)
+                       if t:
+                               issues[config_name] = t
+
+               return issues
+
+
        def _run_config(self, config_name):
                ''
 
@@ -75,7 +107,6 @@ class BenchmarkRunner(object):
        def run(self):
                'run all the configured benchmarks'
 
-               # FIXME check that the directory does not exist
                os.mkdir(self._output)
 
                for config_name in self._configs:
index 1d75a10bf8feb9276ef7fcc68c3cd1d2efc422cb..5826d3343813ac3c640d31500c605c7b63f27479 100755 (executable)
@@ -51,4 +51,13 @@ if __name__ == '__main__':
                                                                postgres_config = POSTGRES_CONFIG,
                                                                **PGBENCH_CONFIG)
 
-               runner.run()
+               # check configuration and report all issues
+               issues = runner.check()
+
+               if issues:
+                       # print the issues
+                       for k in issues:
+                               for v in issues[k]:
+                                       print k, ':', v
+               else:
+                       runner.run()