diff options
| -rw-r--r-- | src/benchmark.py | 75 | ||||
| -rw-r--r-- | src/benchmarks/httpd.py | 7 | ||||
| -rw-r--r-- | src/benchmarks/mysql.py | 3 |
3 files changed, 62 insertions, 23 deletions
diff --git a/src/benchmark.py b/src/benchmark.py index c5e96c9..52c2461 100644 --- a/src/benchmark.py +++ b/src/benchmark.py @@ -30,7 +30,7 @@ class Benchmark: defaults = {"cmd": "false", "args": {}, "measure_cmd": "perf stat -x, -d", - "server_cmds": [], + "servers": [], "allocators": copy.deepcopy(src.globalvars.allocators)} @staticmethod @@ -88,9 +88,6 @@ class Benchmark: if not hasattr(self, k): setattr(self, k, Benchmark.defaults[k]) - # List of Popen server objects - self.servers = [] - # Set result_dir if not hasattr(self, "result_dir"): self.result_dir = os.path.abspath(os.path.join(src.globalvars.resdir, @@ -118,7 +115,7 @@ class Benchmark: print_debug("Creating benchmark", self.name) print_debug("Cmd:", self.cmd) print_debug("Args:", self.args) - print_debug("Server Cmds:", self.server_cmds) + print_debug("Servers:", self.servers) print_debug("Requirements:", self.requirements) print_debug("Results dictionary:", self.results) print_debug("Results directory:", self.result_dir) @@ -236,10 +233,11 @@ class Benchmark: substitutions.update(self.__dict__) substitutions.update(alloc) - for server_cmd in self.server_cmds: - print_info("Starting Server for", alloc_name) + for server in self.servers: + server_name = server.get("name", "Server") + print_info(f"Starting {server_name} for {alloc_name}") - server_cmd = src.util.prefix_cmd_with_abspath(server_cmd) + server_cmd = src.util.prefix_cmd_with_abspath(server["cmd"]) server_cmd = "{} {} {}".format(self.measure_cmd, alloc["cmd_prefix"], server_cmd) @@ -247,7 +245,7 @@ class Benchmark: server_cmd = server_cmd.format(**substitutions) print_debug(server_cmd) - server = subprocess.Popen(server_cmd.split(), env=env, + proc = subprocess.Popen(server_cmd.split(), env=env, stdout=subprocess.PIPE, stderr=subprocess.PIPE, universal_newlines=True) @@ -255,20 +253,56 @@ class Benchmark: # TODO: check if server is up sleep(5) - ret = server.poll() + ret = proc.poll() if ret is not None: - print_debug("Stdout:", server.stdout) - print_debug("Stderr:", server.stderr) - raise Exception("Starting Server failed with exit code " + str(ret)) + print_debug("Stdout:", proc.stdout.read()) + print_debug("Stderr:", proc.stderr.read()) + raise Exception(f"Starting {server_name} failed with exit code: {ret}") + server["popen"] = proc # Register termination of the server - atexit.register(Benchmark.terminate_subprocess, popen=server) - self.servers.append(server) + atexit.register(Benchmark.shutdown_server, server=server) + + if not "prepare_cmds" in server: + continue + + print_info(f"Preparing {server_name}") + for prep_cmd in server["prepare_cmds"]: + prep_cmd = prep_cmd.format(**substitutions) + print_debug(prep_cmd) + + proc = subprocess.run(prep_cmd.split(), universal_newlines=True, + stdout=subprocess.PIPE, stderr=subprocess.PIPE) + + print_debug("Stdout:", proc.stdout) + print_debug("Stderr:", proc.stderr) + + + @staticmethod + def shutdown_server(server): + """Terminate a started server running its shutdown_cmds in advance""" + server_name = server.get("name", "Server") + print_info(f"Shutting down {server_name}") + + if server["popen"].poll(): + return + + if "shutdown_cmds" in server: + for shutdown_cmd in server["shutdown_cmds"]: + print_debug(shutdown_cmd) + + proc = subprocess.run(shutdown_cmd.split(), universal_newlines=True, + stdout=subprocess.PIPE, stderr=subprocess.PIPE) + + print_debug("Stdout:", proc.stdout) + print_debug("Stderr:", proc.stderr) + + Benchmark.terminate_subprocess(server["popen"]) def shutdown_servers(self): """Terminate all started servers""" print_info("Shutting down servers") for server in self.servers: - Benchmark.terminate_subprocess(server) + Benchmark.shutdown_server(server) def run(self, runs=3): """generic run implementation""" @@ -336,7 +370,7 @@ class Benchmark: argv = [] # Prepend cmd if we are not measuring servers - if self.server_cmds == []: + if self.servers == []: prefix_argv = alloc["cmd_prefix"].format(**substitutions).split() if self.measure_cmd != "": measure_argv = self.measure_cmd.format(**substitutions) @@ -376,7 +410,7 @@ class Benchmark: # parse and store results else: - if self.server_cmds == []: + if self.servers == []: if os.path.isfile("status"): # Read VmHWM from status file. If our benchmark # didn't fork the first occurance of VmHWM is from @@ -391,7 +425,8 @@ class Benchmark: else: result["server_status"] = [] for server in self.servers: - with open("/proc/{}/status".format(server.pid), "r") as f: + print(server) + with open("/proc/{}/status".format(server["popen"].pid), "r") as f: result["server_status"].append(f.read()) # parse perf output if available @@ -421,7 +456,7 @@ class Benchmark: if os.getcwd() != cwd: os.chdir(cwd) - if self.server_cmds != []: + if self.servers != []: self.shutdown_servers() if hasattr(self, "postallocator_hook"): diff --git a/src/benchmarks/httpd.py b/src/benchmarks/httpd.py index 16d3b20..4569500 100644 --- a/src/benchmarks/httpd.py +++ b/src/benchmarks/httpd.py @@ -32,8 +32,11 @@ class BenchmarkHTTPD(Benchmark): "site": ["index.html", "index.php"]} self.cmd = "ab -n 10000 -c {nthreads} localhost:8080/{site}" self.measure_cmd = "" - self.server_cmds = ["nginx -c {builddir}/benchmarks/httpd/etc/nginx/nginx.conf", - "php-fpm -c {builddir}/benchmarks/httpd/etc/php/php.ini -y {builddir}/benchmarks/httpd/etc/php/php-fpm.conf -F"] + self.servers = [{"name": "nginx", + "cmd": "nginx -c {builddir}/benchmarks/httpd/etc/nginx/nginx.conf"}, + {"name": "php-fpm", + "cmd": "php-fpm -c {builddir}/benchmarks/httpd/etc/php/php.ini "\ + "-y {builddir}/benchmarks/httpd/etc/php/php-fpm.conf -F"}] self.requirements = ["nginx", "ab"] diff --git a/src/benchmarks/mysql.py b/src/benchmarks/mysql.py index 28cb982..a47873b 100644 --- a/src/benchmarks/mysql.py +++ b/src/benchmarks/mysql.py @@ -56,7 +56,8 @@ class BenchmarkMYSQL(Benchmark): self.args = {"nthreads": Benchmark.scale_threads_for_cpus(1)} self.cmd = CMD - self.server_cmds = [SERVER_CMD] + self.servers = [{"name": "mysqld", + "cmd" : SERVER_CMD}] self.measure_cmd = "" self.requirements = ["mysqld", "sysbench"] |
