Skip to content
Snippets Groups Projects

Implement Benchmarking Strategy: Heuristic 1 (Step Strategy)

Closed Simon Ehrenstein requested to merge stu200776/spesb:48-step-strategy into master
3 files
+ 13
15
Compare changes
  • Side-by-side
  • Inline
Files
3
import pprint
from strategies.config import ExperimentConfig
import strategies.strategies.step_strategy as step_strategy
from strategies.experiment_execution import ExperimentExecutor
import strategies.subexperiment_execution.subexperiment_executor as subexperiment_executor
class Object(object):
pass
pp = pprint.PrettyPrinter(indent=4)
dim_values = [0, 1, 2, 3, 4, 5, 6]
replicas = [0, 1, 2, 3, 4, 5, 6]
# True means the experiment was successful
# the experiments are indexed row (representing dimension values) and column (representing number of replicas) wise as usual arrays from 0 - 6 respectively.
# this means the first row starts with (0,0), the second row with (1, 0) etc.
successful = [
[ True , True , True , True , True , True , True ],
[ False, False, True , True , True , True , True ],
[ False, False, True , True , True , True , True ],
[ False, False, False, True , True , True , True ],
[ False, False, False, False, True , True , True ],
[ False, False, False, False, False, False, True ],
[ False, False, False, False, False, False, False ]
]
# the expected order of executed experiments
expected_order = [
(0,0),
(1,0),
(1,1),
(1,2),
(2,2),
(3,2),
(3,3),
(4,3),
(4,4),
(5,4),
(5,5),
(5,6),
(6,6)
]
last_experiment = (0, 0)
experiment_counter = -1
subexperiment_executor = Object()
def subexperiment_executor_executor(config):
global experiment_counter, last_experiment, pp
print("Simulate subexperiment with config:")
pp.pprint(config)
last_experiment = (config.dim_value, config.replicas)
experiment_counter += 1
print("Simulation complete")
subexperiment_executor.execute = subexperiment_executor_executor
# returns True if the experiment was successful
subexperiment_evaluator = Object()
def subexperiment_evaluator_execute():
print("Evaluating last experiment. Index was:")
global expected_order, experiment_counter, last_experiment, successful
pp.pprint(expected_order[experiment_counter])
assert expected_order[experiment_counter] == last_experiment
print("Index was as expected. Evaluation finished.")
return 1 if successful[last_experiment[0]][last_experiment[1]] else 0
subexperiment_evaluator.execute = subexperiment_evaluator_execute
def test_step_strategy():
# declare parameters
uc="test-uc"
partitions=40
cpu_limit="1000m"
memory_limit="4Gi"
kafka_streams_commit_interval_ms=100
execution_minutes=5
# execute
experiment_config = ExperimentConfig(uc, dim_values, replicas, partitions, cpu_limit, memory_limit, kafka_streams_commit_interval_ms, execution_minutes, step_strategy, subexperiment_executor, subexperiment_evaluator)
executor = ExperimentExecutor(experiment_config)
executor.execute()
\ No newline at end of file
Loading