aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFlorian Fischer <florian.fl.fischer@fau.de>2019-04-02 12:01:41 +0200
committerFlorian Fischer <florian.fl.fischer@fau.de>2019-04-02 12:01:41 +0200
commit5bcc88fb9131884edd545af1f085c043cf34166a (patch)
tree090b05e1d97ab44e15cc82903707701b6f03ed60
parent5f477e0561b613038888a0fd7169f9b6dc11b118 (diff)
downloadallocbench-5bcc88fb9131884edd545af1f085c043cf34166a.tar.gz
allocbench-5bcc88fb9131884edd545af1f085c043cf34166a.zip
add real simple webserver benchmark using nginx and ab
-rw-r--r--src/benchmarks/httpd.py87
-rw-r--r--src/benchmarks/httpd/Makefile19
-rw-r--r--src/benchmarks/httpd/html/index.html5
-rw-r--r--src/benchmarks/httpd/nginx/nginx.conf72
4 files changed, 183 insertions, 0 deletions
diff --git a/src/benchmarks/httpd.py b/src/benchmarks/httpd.py
new file mode 100644
index 0000000..e52dc16
--- /dev/null
+++ b/src/benchmarks/httpd.py
@@ -0,0 +1,87 @@
+import atexit
+import matplotlib.pyplot as plt
+import numpy as np
+import re
+import shutil
+import subprocess
+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(25)}
+ self.cmd = "ab -n 10000 -c {nthreads} localhost:8080/index.html"
+ self.measure_cmd = ""
+ self.server_benchmark = True
+
+ self.requirements = ["nginx", "ab"]
+
+ atexit.register(self.terminate_server)
+
+ super().__init__()
+
+ def terminate_server(self):
+ 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)
+
+ # with open("/proc/"+str(self.server.pid)+"/status", "r") as f:
+ # for l in f.readlines():
+ # if l.startswith("VmHWM:"):
+ # result["rssmax"] = int(l.replace("VmHWM:", "").strip().split()[0])
+ # break
+
+ def summary(self):
+ allocators = self.results["allocators"]
+ args = self.results["args"]
+
+ # linear plot
+ self.plot_single_arg("{requests}",
+ xlabel='"threads"',
+ ylabel='"requests/s"',
+ title='"ab -n 10000 -c threads"')
+
+ # linear plot
+ ref_alloc = list(allocators)[0]
+ self.plot_single_arg("{requests}",
+ xlabel='"threads"',
+ ylabel='"requests/s scaled at " + scale',
+ title='"ab -n 10000 -c threads (normalized)"',
+ filepostfix="norm",
+ scale=ref_alloc)
+
+httpd = Benchmark_HTTPD()
diff --git a/src/benchmarks/httpd/Makefile b/src/benchmarks/httpd/Makefile
new file mode 100644
index 0000000..572f3e6
--- /dev/null
+++ b/src/benchmarks/httpd/Makefile
@@ -0,0 +1,19 @@
+OBJDIR ?= obj
+
+.PHONY = all clean
+
+all: $(OBJDIR)/html $(OBJDIR)/nginx
+
+$(OBJDIR)/html: html | $(OBJDIR)
+ cp -r html $(OBJDIR)/html
+
+$(OBJDIR)/nginx: nginx/nginx.conf | $(OBJDIR)
+ mkdir $@
+ mkdir $@/logs
+ sed "s|OBJDIR|$(OBJDIR)|" $< > $@/nginx.conf
+
+$(OBJDIR):
+ mkdir -p $@
+
+clean:
+ rm -rf $(OBJDIR)
diff --git a/src/benchmarks/httpd/html/index.html b/src/benchmarks/httpd/html/index.html
new file mode 100644
index 0000000..7052ab3
--- /dev/null
+++ b/src/benchmarks/httpd/html/index.html
@@ -0,0 +1,5 @@
+<html>
+<body>
+foobar
+</body>
+</html>
diff --git a/src/benchmarks/httpd/nginx/nginx.conf b/src/benchmarks/httpd/nginx/nginx.conf
new file mode 100644
index 0000000..988639e
--- /dev/null
+++ b/src/benchmarks/httpd/nginx/nginx.conf
@@ -0,0 +1,72 @@
+#user html;
+worker_processes 1;
+
+
+error_log OBJDIR/nginx/logs/error.log;
+error_log OBJDIR/nginx/logs/error.log notice;
+error_log OBJDIR/nginx/logs/error.log info;
+
+pid OBJDIR/nginx/logs/nginx.pid;
+
+
+events {
+ worker_connections 1024;
+}
+
+
+http {
+ log_format main '$remote_addr - $remote_user [$time_local] "$request" '
+ '$status $body_bytes_sent "$http_referer" '
+ '"$http_user_agent" "$http_x_forwarded_for"';
+
+ access_log OBJDIR/nginx/logs/access.log main;
+
+ sendfile on;
+ #tcp_nopush on;
+
+ #keepalive_timeout 0;
+ keepalive_timeout 65;
+
+ #gzip on;
+
+ server {
+ listen 8080;
+ server_name localhost;
+
+ location / {
+ root OBJDIR/html;
+ index index.html index.htm;
+ }
+
+ #error_page 404 /404.html;
+
+ # redirect server error pages to the static page /50x.html
+ #
+ error_page 500 502 503 504 /50x.html;
+ location = /50x.html {
+ root /usr/share/nginx/html;
+ }
+ }
+
+ # HTTPS server
+ #
+ #server {
+ # listen 443 ssl;
+ # server_name localhost;
+
+ # ssl_certificate cert.pem;
+ # ssl_certificate_key cert.key;
+
+ # ssl_session_cache shared:SSL:1m;
+ # ssl_session_timeout 5m;
+
+ # ssl_ciphers HIGH:!aNULL:!MD5;
+ # ssl_prefer_server_ciphers on;
+
+ # location / {
+ # root html;
+ # index index.html index.htm;
+ # }
+ #}
+
+}