aboutsummaryrefslogtreecommitdiff
path: root/src/benchmarks/httpd.py
blob: 4569500dab8ec489036a4b799bdeedbbd1c14c21 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
# Copyright 2018-2019 Florian Fischer <florian.fl.fischer@fau.de>
#
# This file is part of allocbench.
#
# allocbench is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# allocbench is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with allocbench.  If not, see <http://www.gnu.org/licenses/>.

"""Definition of the httpd benchmark"""

import re

from src.benchmark import Benchmark


class BenchmarkHTTPD(Benchmark):
    """TODO"""

    def __init__(self):
        name = "httpd"

        self.args = {"nthreads": Benchmark.scale_threads_for_cpus(2),
                     "site": ["index.html", "index.php"]}
        self.cmd = "ab -n 10000 -c {nthreads} localhost:8080/{site}"
        self.measure_cmd = ""
        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"]

        super().__init__(name)

    @staticmethod
    def process_output(result, stdout, stderr, allocator, perm):
        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"]

        self.calc_desc_statistics()

        # linear plot
        self.plot_fixed_arg("{requests}",
                            xlabel='"threads"',
                            ylabel='"requests/s"',
                            autoticks=False,
                            filepostfix="requests",
                            title='"ab -n 10000 -c " + str(perm.nthreads)')

        # linear plot
        ref_alloc = list(allocators)[0]
        self.plot_fixed_arg("{requests}",
                            xlabel='"threads"',
                            ylabel='"requests/s scaled at " + scale',
                            title='"ab -n 10000 -c " + str(perm.nthreads) + " (normalized)"',
                            filepostfix="requests.norm",
                            autoticks=False,
                            scale=ref_alloc)

        # bar plot
        # self.barplot_fixed_arg("{requests}",
                               # xlabel='"threads"',
                               # ylabel='"requests/s"',
                               # filepostfix="b",
                               # title='"ab -n 10000 -c threads"')


httpd = BenchmarkHTTPD()