1 # Copyright 2016: Nokia
4 # Licensed under the Apache License, Version 2.0 (the "License"); you may
5 # not use this file except in compliance with the License. You may obtain
6 # a copy of the License at
8 # http://www.apache.org/licenses/LICENSE-2.0
10 # Unless required by applicable law or agreed to in writing, software
11 # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12 # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13 # License for the specific language governing permissions and limitations
16 # yardstick comment: this is a modified copy of
17 # rally/rally/benchmark/runners/constant.py
19 """A runner that searches for the max throughput with binary search
23 import multiprocessing
28 from yardstick.benchmark.runners import base
30 LOG = logging.getLogger(__name__)
33 def _worker_process(queue, cls, method_name, scenario_cfg,
34 context_cfg, aborted): # pragma: no cover
36 queue.cancel_join_thread()
37 runner_cfg = scenario_cfg['runner']
38 iterations = runner_cfg.get("iterations", 1)
39 interval = runner_cfg.get("interval", 1)
40 run_step = runner_cfg.get("run_step", "setup,run,teardown")
41 delta = runner_cfg.get("delta", 1000)
42 options_cfg = scenario_cfg['options']
43 initial_rate = options_cfg.get("pps", 1000000)
44 LOG.info("worker START, class %s", cls)
46 runner_cfg['runner_id'] = os.getpid()
48 benchmark = cls(scenario_cfg, context_cfg)
49 if "setup" in run_step:
52 method = getattr(benchmark, method_name)
54 queue.put({'runner_id': runner_cfg['runner_id'],
55 'scenario_cfg': scenario_cfg,
56 'context_cfg': context_cfg})
60 search_max = initial_rate
62 while iterator < iterations:
63 search_min = int(search_min / 2)
64 scenario_cfg['options']['pps'] = search_max
65 search_max_found = False
66 max_throuput_found = False
70 last_min_data['packets_per_second'] = 0
79 LOG.debug("sequence: %s search_min: %s search_max: %s",
80 sequence, search_min, search_max)
84 except AssertionError as assertion:
85 LOG.warning("SLA validation failed: %s" % assertion.args)
87 except Exception as e:
88 errors = traceback.format_exc()
91 actual_pps = data['packets_per_second']
94 search_max = actual_pps
96 if not search_max_found:
97 search_max_found = True
100 search_min = actual_pps
102 # Check if the actual rate is well below the asked rate
103 if scenario_cfg['options']['pps'] > actual_pps * 1.5:
104 search_max = actual_pps
105 LOG.debug("Sender reached max tput: %s", search_max)
106 elif not search_max_found:
107 search_max = int(actual_pps * 1.5)
109 if ((search_max - search_min) < delta) or \
110 (search_max <= search_min) or (10 <= sequence):
111 if last_min_data['packets_per_second'] > 0:
115 'timestamp': time.time(),
116 'sequence': sequence,
122 'runner_id': runner_cfg['runner_id'],
123 'benchmark': benchmark_output
127 max_throuput_found = True
129 if (errors) or aborted.is_set() or max_throuput_found:
130 LOG.info("worker END")
133 if not search_max_found:
134 scenario_cfg['options']['pps'] = search_max
136 scenario_cfg['options']['pps'] = \
137 (search_max - search_min) / 2 + search_min
142 LOG.debug("iterator: %s iterations: %s", iterator, iterations)
144 if "teardown" in run_step:
148 class IterationRunner(base.Runner):
149 '''Run a scenario to find the max throughput
151 If the scenario ends before the time has elapsed, it will be started again.
154 interval - time to wait between each scenario invocation
158 delta - stop condition for the search.
163 __execution_type__ = 'Dynamictp'
165 def _run_benchmark(self, cls, method, scenario_cfg, context_cfg):
166 self.process = multiprocessing.Process(
167 target=_worker_process,
168 args=(self.result_queue, cls, method, scenario_cfg,
169 context_cfg, self.aborted))