aboutsummaryrefslogtreecommitdiff
path: root/src/benchmarks
diff options
context:
space:
mode:
authorFlorian Fischer <florian.fl.fischer@fau.de>2019-05-15 17:47:22 +0200
committerFlorian Fischer <florian.fl.fischer@fau.de>2019-05-15 17:51:06 +0200
commit7da91858ce7959f102a04bca2b2fcfd418e5a7a9 (patch)
tree19abc82074f001f85729ff00e8ae6ec0bbaad5d3 /src/benchmarks
parentf63ac8afd8110d3fcea9dd1f7eb2b8175f4ac306 (diff)
downloadallocbench-7da91858ce7959f102a04bca2b2fcfd418e5a7a9.tar.gz
allocbench-7da91858ce7959f102a04bca2b2fcfd418e5a7a9.zip
introduce server concept to Benchmark
A benchmark object can specify a list of cmds to execute as "servers" in the member attribute server_cmds. Servers are started and terminated through Popen objects. This requires the server cmds to not daemonize so the server can be terminated through the Popen object. For each started server cmd a shutdown function is registered with atexit to terminate all servers even if a exception occurs. Use the new server concept in httpd and mysql benchmarks
Diffstat (limited to 'src/benchmarks')
-rw-r--r--src/benchmarks/httpd.py70
-rw-r--r--src/benchmarks/mysql.py61
2 files changed, 27 insertions, 104 deletions
diff --git a/src/benchmarks/httpd.py b/src/benchmarks/httpd.py
index de59d4e..980a6cc 100644
--- a/src/benchmarks/httpd.py
+++ b/src/benchmarks/httpd.py
@@ -1,4 +1,3 @@
-import atexit
import matplotlib.pyplot as plt
import numpy as np
import re
@@ -8,55 +7,26 @@ from subprocess import PIPE
import sys
from time import sleep
-from src.globalvars import builddir
from src.benchmark import Benchmark
from src.util import *
-server_cmd = "{} -c {}/benchmarks/httpd/nginx/nginx.conf".format(shutil.which("nginx"), builddir).split()
-
class Benchmark_HTTPD(Benchmark):
def __init__(self):
self.name = "httpd"
self.descrition = """TODO"""
- self.args = {"nthreads": Benchmark.scale_threads_for_cpus(2)}
- self.cmd = "ab -n 10000 -c {nthreads} localhost:8080/index.html"
+ self.args = {"nthreads": Benchmark.scale_threads_for_cpus(2),
+ "site": ["index.html", "index.php"]}
+ self.cmd = "ab -n 100 -c {nthreads} localhost:8080/{site}"
self.measure_cmd = ""
- self.server_benchmark = True
+ 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.requirements = ["nginx", "ab"]
- atexit.register(self.terminate_server)
-
super().__init__()
- def terminate_server(self):
- # check if nginx is running
- if os.path.isfile(os.path.join(builddir, "benchmarks", self.name, "nginx", "nginx.pid")):
- ret = subprocess.run(server_cmd + ["-s", "stop"], stdout=PIPE,
- stderr=PIPE, universal_newlines=True)
-
- if ret.returncode != 0:
- print_debug("Stdout:", ret.stdout)
- print_debug("Stderr:", ret.stderr)
- raise Exception("Stopping {} failed with {}".format(server_cmd[0], ret.returncode))
-
- def preallocator_hook(self, allocator, run, env, verbose):
- actual_cmd = allocator[1]["cmd_prefix"].split() + server_cmd
- print_info("Starting server with:", actual_cmd)
-
- ret = subprocess.run(actual_cmd, stdout=PIPE, stderr=PIPE, env=env,
- universal_newlines=True)
- if ret.returncode != 0:
- print_debug("Stdout:", ret.stdout)
- print_debug("Stderr:", ret.stderr)
- raise Exception("Starting {} for {} failed with {}".format(server_cmd[0], allocator[0], ret.returncode))
-
-
- def postallocator_hook(self, allocator, run, verbose):
- self.terminate_server()
-
def process_output(self, result, stdout, stderr, allocator, perm, verbose):
result["time"] = re.search("Time taken for tests:\s*(\d*\.\d*) seconds", stdout).group(1)
result["requests"] = re.search("Requests per second:\s*(\d*\.\d*) .*", stdout).group(1)
@@ -74,33 +44,29 @@ class Benchmark_HTTPD(Benchmark):
self.calc_desc_statistics()
# linear plot
- self.plot_single_arg("{requests}",
+ self.plot_fixed_arg("{requests}",
xlabel='"threads"',
ylabel='"requests/s"',
- title='"ab -n 10000 -c threads"')
+ autoticks=False,
+ filepostfix="requests",
+ title='"ab -n 10000 -c " + str(perm.nthreads)')
# linear plot
ref_alloc = list(allocators)[0]
- self.plot_single_arg("{requests}",
+ self.plot_fixed_arg("{requests}",
xlabel='"threads"',
ylabel='"requests/s scaled at " + scale',
- title='"ab -n 10000 -c threads (normalized)"',
- filepostfix="norm",
+ title='"ab -n 10000 -c " + str(perm.nthreads) + " (normalized)"',
+ filepostfix="requests.norm",
+ autoticks=False,
scale=ref_alloc)
# bar plot
- self.barplot_single_arg("{requests}",
- xlabel='"threads"',
- ylabel='"requests/s"',
- filepostfix="b",
- title='"ab -n 10000 -c threads"')
+ # self.barplot_fixed_arg("{requests}",
+ # xlabel='"threads"',
+ # ylabel='"requests/s"',
+ # filepostfix="b",
+ # title='"ab -n 10000 -c threads"')
- # bar plot
- self.barplot_single_arg("{requests}",
- xlabel='"threads"',
- ylabel='"requests/s scaled at " + scale',
- title='"ab -n 10000 -c threads (normalized)"',
- filepostfix="norm.b.",
- scale=ref_alloc)
httpd = Benchmark_HTTPD()
diff --git a/src/benchmarks/mysql.py b/src/benchmarks/mysql.py
index 752a4ea..fb9c2e7 100644
--- a/src/benchmarks/mysql.py
+++ b/src/benchmarks/mysql.py
@@ -1,4 +1,3 @@
-import atexit
import copy
import matplotlib.pyplot as plt
import multiprocessing
@@ -21,14 +20,12 @@ prepare_cmd = ("sysbench oltp_read_only --db-driver=mysql --mysql-user=root "
"--mysql-socket=" + cwd + "/mysql_test/socket --tables=5 "
"--table-size=1000000 prepare").split()
-cmd = ("sysbench oltp_read_only --threads={nthreads} --time=60 --tables=5 "
+cmd = ("sysbench oltp_read_only --threads={nthreads} --time=10 --tables=5 "
"--db-driver=mysql --mysql-user=root --mysql-socket="
+ cwd + "/mysql_test/socket run")
-server_cmd = ("{0} -h {2}/mysql_test --socket={2}/mysql_test/socket "
- "--max-connections={1} "
- "--secure-file-priv=").format(shutil.which("mysqld"),
- multiprocessing.cpu_count(), cwd).split()
+server_cmd = ("mysqld -h {0}/mysql_test --socket={0}/mysql_test/socket "
+ "--max-connections={1} --secure-file-priv=").format(cwd, multiprocessing.cpu_count())
class Benchmark_MYSQL(Benchmark):
@@ -38,49 +35,18 @@ class Benchmark_MYSQL(Benchmark):
# mysqld fails with hoard somehow
self.allocators = copy.copy(allocators)
- if "hoard" in self.allocators:
- del(self.allocators["hoard"])
+ if "Hoard" in self.allocators:
+ del(self.allocators["Hoard"])
self.args = {"nthreads": Benchmark.scale_threads_for_cpus(1)}
self.cmd = cmd
+ self.server_cmds = [server_cmd]
self.measure_cmd = ""
self.requirements = ["mysqld", "sysbench"]
- atexit.register(self.terminate_server)
-
super().__init__()
- def start_and_wait_for_server(self, cmd_prefix="", env=None):
- actual_cmd = cmd_prefix.split() + server_cmd
- print_info("Starting server with:", actual_cmd)
-
- self.server = subprocess.Popen(actual_cmd, stdout=PIPE, stderr=PIPE,
- env=env, universal_newlines=True)
- # TODO make sure server comes up !
- sleep(10)
- if self.server.poll() is not None:
- print_debug("cmd_prefix:", cmd_prefix, file=sys.stderr)
- print_debug("Stderr:", self.server.stderr, file=sys.stderr)
- return False
-
- return True
-
- def terminate_server(self):
- if hasattr(self, "server"):
- if self.server.poll() is None:
- print_info("Terminating mysql server")
- self.server.terminate()
-
- for i in range(0,10):
- sleep(1)
- if self.server.poll() is not None:
- return
-
- print_info("Killing still running mysql server")
- self.server.kill()
- self.server.wait()
-
def prepare(self):
super().prepare()
@@ -106,8 +72,7 @@ class Benchmark_MYSQL(Benchmark):
print_debug(p.stderr, file=sys.stderr)
raise Exception("Creating test DB failed with:", p.returncode)
- if not self.start_and_wait_for_server():
- raise Exception("Starting mysql server failed with {}".format(self.server.returncode))
+ self.start_servers()
# Create sbtest TABLE
p = subprocess.run(("mysql -u root -S "+cwd+"/mysql_test/socket").split(" "),
@@ -128,21 +93,13 @@ class Benchmark_MYSQL(Benchmark):
self.terminate_server()
raise Exception("Preparing test tables failed with:", p.returncode)
- self.terminate_server()
+ self.shutdown_servers()
def cleanup(self):
if os.path.exists("mysql_test"):
print_status("Delete mysqld directory")
shutil.rmtree("mysql_test", ignore_errors=True)
- def preallocator_hook(self, allocator, run, env, verbose):
- if not self.start_and_wait_for_server(cmd_prefix=allocator[1]["cmd_prefix"], env=env):
- print_debug(allocator[1]["cmd_prefix"], file=sys.stderr)
- raise Exception("Starting mysql server for {} failed with".format(allocator[0], self.server.returncode))
-
- def postallocator_hook(self, allocator, run, verbose):
- self.terminate_server()
-
def process_output(self, result, stdout, stderr, allocator, perm, verbose):
result["transactions"] = re.search("transactions:\s*(\d*)", stdout).group(1)
result["queries"] = re.search("queries:\s*(\d*)", stdout).group(1)
@@ -151,7 +108,7 @@ class Benchmark_MYSQL(Benchmark):
result["avg"] = re.search("avg:\s*(\d*.\d*)", stdout).group(1)
result["max"] = re.search("max:\s*(\d*.\d*)", stdout).group(1)
- with open("/proc/"+str(self.server.pid)+"/status", "r") as f:
+ with open("/proc/"+str(self.servers[0].pid)+"/status", "r") as f:
for l in f.readlines():
if l.startswith("VmHWM:"):
result["rssmax"] = int(l.replace("VmHWM:", "").strip().split()[0])