aboutsummaryrefslogtreecommitdiff
path: root/src/benchmarks/httpd.py
blob: 18a9bf63b4d6b6e140aded3ed02ea7e1c41cd6bd (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
88
89
90
91
92
93
94
# 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
import src.facter
import src.plots as plt


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)

    def prepare(self):
        super().prepare()

        self.results["facts"]["versions"]["nginx"] = src.facter.exe_version(
            "nginx", "-v")
        self.results["facts"]["versions"]["ab"] = src.facter.exe_version(
            "ab", "-V")

    @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)

    def summary(self):
        plt.plot(self,
                 "{requests}",
                 fig_options={
                     'xlabel': "threads",
                     'ylabel': "requests/s",
                     'title': "{perm.site}: requests/s",
                     'autoticks': False,
                 },
                 file_postfix="requests")

        plt.plot(self,
                 "{nginx_vmhwm}",
                 fig_options={
                    'xlabel': "threads",
                    'ylabel': "VmHWM in KB",
                    'title': "{perm.site}: nginx memory usage",
                    'autoticks': False,
                 },
                 file_postfix="httpd_vmhwm")

        plt.plot(self,
                 "{php-fpm_vmhwm}",
                 fig_options={
                     'xlabel': "threads",
                     'ylabel': "VmHWM in KB",
                     'title': "{perm.site}: php-fpm memory usage",
                     'autoticks': False,
                 },
                 file_postfix="php-fpm_vmhwm")


httpd = BenchmarkHTTPD()