Commit a4c40d95 authored by Maverick Chardet's avatar Maverick Chardet
Browse files

Added ability to execute a reconfiguration in Assembly, added ability to...

Added ability to execute a reconfiguration in Assembly, added ability to evaluate a formula in Meta, updates performance analysis test
parent abf8166c
......@@ -14,6 +14,7 @@ from concerto.dependency import DepType, Dependency
from concerto.component import Component
from concerto.connection import Connection
from concerto.internal_instruction import InternalInstruction
from concerto.reconfiguration import Reconfiguration
from concerto.gantt_chart import GanttChart
from concerto.utility import Messages, COLORS, Printer
......@@ -163,6 +164,9 @@ class Assembly (object):
if not self.semantics_thread.is_alive():
self.semantics_thread.start()
def run_reconfiguration(self, reconfiguration : Reconfiguration):
for instr in reconfiguration._get_instructions():
self.add_instruction(instr)
def add_component(self, name : str, comp : Component):
self.add_instruction(InternalInstruction.build_add(name,comp))
......
......@@ -217,6 +217,27 @@ class WeightedGraph:
def __str__(self):
return self.to_string()
def evaluate(self, values_dict = None):
if values_dict is None:
values_dict = dict()
def _eval_sum_list(sl):
def __eval_elem(e):
if is_number(e):
return e
elif isinstance(e, WeightedGraph.MaxFormula):
return e.evaluate(values_dict)
else:
if e not in values_dict:
raise Exception("Error: no value provided for %s" % str(e))
return values_dict[e]
return sum([__eval_elem(e) for e in sl])
if len(self._sum_lists) == 0:
return 0
else:
return max([_eval_sum_list(sl) for sl in self._sum_lists])
def get_longest_path_formula(self, source_vertex, destination_vertex):
reversed_graph = dict()
for s, transitions in self._graph.items():
......
......@@ -32,5 +32,8 @@ class Reconfiguration:
self._instructions.append(InternalInstruction.build_wait_all())
return self
def call(self, other_reconfiguration):
self._instructions += other_reconfiguration._get_instructions()
def _get_instructions(self):
return self._instructions
#!/usr/bin/python3
from concerto.all import *
from concerto.utility import Printer
from concerto.meta import ReconfigurationPerfAnalyzer
import time, datetime
from examples.perf_analysis.client import Client
......@@ -9,17 +9,17 @@ from examples.perf_analysis.server import Server
class ServerClient(Assembly):
def __init__(self, t_sa=4., t_sr=4., t_su=1., t_sc=0.5, t_ci1=1., t_ci2=1., t_cc=1., t_cr=1., t_cs1=2., t_cs2=0.):
self.t_sa = t_sa
self.t_sr = t_sr
self.t_su = t_su
self.t_sc = t_sc
self.t_ci1 = t_ci1
self.t_ci2 = t_ci2
self.t_cc = t_cc
self.t_cr = t_cr
self.t_cs1 = t_cs1
self.t_cs2 = t_cs2
def __init__(self, times_dict):
self.t_sa = times_dict[('server', 'allocate')]
self.t_sr = times_dict[('server', 'run')]
self.t_su = times_dict[('server', 'update')]
self.t_sc = times_dict[('server', 'cleanup')]
self.t_ci1 = times_dict[('client', 'install1')]
self.t_ci2 = times_dict[('client', 'install2')]
self.t_cc = times_dict[('client', 'configure')]
self.t_cr = times_dict[('client', 'start')]
self.t_cs1 = times_dict[('client', 'suspend1')]
self.t_cs2 = times_dict[('client', 'suspend2')]
dr = Reconfiguration()
dr.add('client', Client, t_ci1=self.t_ci1, t_ci2=self.t_ci2, t_cc=self.t_cc, t_cr=self.t_cr, t_cs1=self.t_cs1, t_cs2=self.t_cs2)
......@@ -38,21 +38,36 @@ class ServerClient(Assembly):
def deploy(self):
self.print("### DEPLOYING ####")
self.add_component('client', self.client)
self.add_component('server', self.server)
self.connect('client', 'server_ip',
'server', 'ip')
self.connect('client', 'service',
'server', 'service')
self.push_b('client', 'install_start')
self.push_b('server', 'deploy')
self.wait('client')
self.run_reconfiguration(self.deploy_reconf)
self.synchronize()
from concerto.meta import ReconfigurationPerfAnalyzer
sc = ServerClient()
times = {
('server', 'allocate'): 4,
('server', 'run'): 4,
('server', 'update'): 1,
('server', 'cleanup'): 0.5,
('client', 'install1'): 1,
('client', 'install2'): 1,
('client', 'configure'): 1,
('client', 'start'): 1,
('client', 'suspend1'): 1,
('client', 'suspend2'): 1,
}
sc = ServerClient(times)
pa = ReconfigurationPerfAnalyzer(sc.deploy_reconf)
g = pa.get_graph()
g.save_as_dot("server_client.dot")
print(pa.get_exec_time_formula().to_string(lambda x: '.'.join(x)))
formula = pa.get_exec_time_formula()
print(formula.to_string(lambda x: '.'.join(x)))
print("Time predicted by graph traversal:\n%f" % pa.get_exec_time(times))
print("Time predicted by formula evaluation:\n%f" % formula.evaluate(times))
print("Running reconf...")
start_time: float = time.perf_counter()
sc.deploy()
end_time: float = time.perf_counter()
sc.terminate()
print("Time actually measured:\n%f" % (end_time-start_time))
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment