1 # Copyright 2014: Mirantis Inc.
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 every run arithmetically steps specified input value(s) to
20 the scenario. This just means step value(s) is added to the previous value(s).
21 It is possible to combine several named input values and run with those either
22 as nested for loops or combine each i:th index of each "input value list"
23 until the end of the shortest list is reached (optimally all lists should be
24 defined with the same number of values when using such iter_type).
27 from __future__ import absolute_import
31 import multiprocessing
37 from six.moves import range
39 from yardstick.benchmark.runners import base
41 LOG = logging.getLogger(__name__)
44 def _worker_process(queue, cls, method_name, scenario_cfg,
45 context_cfg, aborted):
49 runner_cfg = scenario_cfg['runner']
51 interval = runner_cfg.get("interval", 1)
52 if 'options' in scenario_cfg:
53 options = scenario_cfg['options']
54 else: # options must be instatiated if not present in yaml
56 scenario_cfg['options'] = options
58 runner_cfg['runner_id'] = os.getpid()
60 LOG.info("worker START, class %s", cls)
62 benchmark = cls(scenario_cfg, context_cfg)
64 method = getattr(benchmark, method_name)
66 queue.put({'runner_id': runner_cfg['runner_id'],
67 'scenario_cfg': scenario_cfg,
68 'context_cfg': context_cfg})
71 if "sla" in scenario_cfg:
72 sla_action = scenario_cfg["sla"].get("action", "assert")
74 # To both be able to include the stop value and handle backwards stepping
75 def margin(start, stop):
76 return -1 if start > stop else 1
79 [range(d['start'], d['stop'] + margin(d['start'], d['stop']),
80 d['step']) for d in runner_cfg['iterators']]
81 param_names = [d['name'] for d in runner_cfg['iterators']]
83 iter_type = runner_cfg.get("iter_type", "nested_for_loops")
85 if iter_type == 'nested_for_loops':
86 # Create a complete combination set of all parameter lists
87 loop_iter = itertools.product(*param_iters)
88 elif iter_type == 'tuple_loops':
89 # Combine each i;th index of respective parameter list
90 loop_iter = six.moves.zip(*param_iters)
92 LOG.warning("iter_type unrecognized: %s", iter_type)
93 raise TypeError("iter_type unrecognized: %s", iter_type)
95 # Populate options and run the requested method for each value combination
96 for comb_values in loop_iter:
101 LOG.debug("runner=%(runner)s seq=%(sequence)s START",
102 {"runner": runner_cfg["runner_id"], "sequence": sequence})
104 for i, value in enumerate(comb_values):
105 options[param_names[i]] = value
112 except AssertionError as assertion:
113 # SLA validation failed in scenario, determine what to do now
114 if sla_action == "assert":
116 elif sla_action == "monitor":
117 LOG.warning("SLA validation failed: %s", assertion.args)
118 errors = assertion.args
119 except Exception as e:
120 errors = traceback.format_exc()
126 'timestamp': time.time(),
127 'sequence': sequence,
132 record = {'runner_id': runner_cfg['runner_id'],
133 'benchmark': benchmark_output}
137 LOG.debug("runner=%(runner)s seq=%(sequence)s END",
138 {"runner": runner_cfg["runner_id"], "sequence": sequence})
142 if errors and sla_action is None:
146 LOG.info("worker END")
149 class ArithmeticRunner(base.Runner):
150 """Run a scenario arithmetically stepping input value(s)
153 interval - time to wait between each scenario invocation
157 iter_type: - Iteration type of input parameter(s): nested_for_loops
161 default: nested_for_loops
163 name - name of scenario option that will be increased for each invocation
167 start - value to use in first invocation of scenario
171 stop - value indicating end of invocation. Can be set to same
172 value as start for one single value.
176 step - value added to start value in next invocation of scenario.
177 Must not be set to zero. Can be set negative if start > stop
182 name - and so on......
185 __execution_type__ = 'Arithmetic'
187 def _run_benchmark(self, cls, method, scenario_cfg, context_cfg):
188 self.process = multiprocessing.Process(
189 target=_worker_process,
190 args=(self.result_queue, cls, method, scenario_cfg,
191 context_cfg, self.aborted))