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

Simplified server clients and server client examples + README

parent fd59360d
......@@ -141,10 +141,9 @@ from client import Client
from server import Server
class ServerClient(Assembly):
def __init__(self, ...):
...
self.server = Server(...)
self.client = Client(...)
def __init__(self):
self.server = Server()
self.client = Client()
Assembly.__init__(self)
def deploy(self):
......@@ -157,7 +156,7 @@ class ServerClient(Assembly):
'server', 'service')
self.push_b('client', 'install_start')
self.push_b('server', 'deploy')
self.wait('client') # In this case, equivalent to self.wait_all()
self.wait_all()
self.synchronize()
```
......
......@@ -34,41 +34,35 @@ class Client(Component):
self.initial_place = 'off'
def __init__(self, t_ci1=1., t_ci2=1., t_cc=1., t_cr=1., t_cs1=2., t_cs2=0.):
def __init__(self):
self.server_ip = None
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
Component.__init__(self)
def install1(self):
self.print_color("installing (1/2)")
time.sleep(self.t_ci1)
time.sleep(2.)
self.print_color("installed (1/2)")
def install2(self):
self.print_color("installing (2/2)")
time.sleep(self.t_ci2)
time.sleep(3.)
self.print_color("installed (2/2)")
def configure(self):
self.server_ip = self.read('server_ip')
self.print_color("configuring [server IP: %s]" % self.server_ip)
time.sleep(self.t_cc)
time.sleep(1.)
self.print_color("configured")
def start(self):
self.print_color("starting")
time.sleep(self.t_cr)
time.sleep(1.)
self.print_color("running")
def suspend1(self):
self.print_color("suspending")
time.sleep(self.t_cs1)
time.sleep(0.)
def suspend2(self):
time.sleep(1.)
self.print_color("suspended")
time.sleep(self.t_cs2)
......@@ -26,32 +26,28 @@ class Server(Component):
self.initial_place = 'undeployed'
def __init__(self, t_sa=4., t_sr=4., t_su=1., t_sc=0.5):
def __init__(self):
self.my_ip = None
self.t_sa = t_sa
self.t_sr = t_sr
self.t_su = t_su
self.t_sc = t_sc
Component.__init__(self)
def allocate(self):
self.print_color("allocating resources")
time.sleep(self.t_sa)
time.sleep(6.)
self.my_ip = "123.124.1.2"
self.write('ip', self.my_ip)
self.print_color("finished allocation (IP: %s)" % self.my_ip)
def run(self):
self.print_color("preparing to run")
time.sleep(self.t_sr)
time.sleep(4.)
self.print_color("running")
def update(self):
self.print_color("updating")
time.sleep(self.t_su)
time.sleep(3.)
self.print_color("updated")
def cleanup(self):
self.print_color("cleaning up")
time.sleep(self.t_sc)
time.sleep(2.)
self.print_color("cleaned up")
......@@ -7,19 +7,9 @@ from 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
self.server = Server(t_sa=self.t_sa, t_sr=self.t_sr, t_su=self.t_su, t_sc=self.t_sc)
self.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)
def __init__(self):
self.server = Server()
self.client = Client()
Assembly.__init__(self)
def deploy(self):
......@@ -32,21 +22,21 @@ class ServerClient(Assembly):
'server', 'service')
self.push_b('client', 'install_start')
self.push_b('server', 'deploy')
self.wait('client')
self.wait_all()
self.synchronize()
def suspend(self):
self.print("### SUSPENDING ###")
self.push_b('client', 'stop')
self.push_b('server', 'stop')
self.wait('server')
self.wait_all()
self.synchronize()
def restart(self):
self.print("### RESTARTING ###")
self.push_b('client', 'install_start')
self.push_b('server', 'deploy')
self.wait('client')
self.wait_all()
self.synchronize()
def maintain(self):
......@@ -55,5 +45,5 @@ class ServerClient(Assembly):
self.push_b('server', 'stop')
self.push_b('client', 'install_start')
self.push_b('server', 'deploy')
self.wait('client')
self.wait_all()
self.synchronize()
......@@ -6,156 +6,29 @@ import time, datetime
from server_client_assembly import ServerClient
# Creating an instance of the ServerClient assembly and setting some parameters
sca = ServerClient()
sca.set_use_gantt_chart(True)
sca.set_verbosity(1)
sca.set_print_time(True)
def time_test(verbosity : int = 0, printing : bool = False, print_time : bool = False) -> float:
start_time : float = time.perf_counter()
if printing: Printer.st_tprint("Main: creating the assembly")
sca = ServerClient()
sca.set_use_gantt_chart(True)
sca.set_verbosity(verbosity)
sca.set_print_time(print_time)
if printing: Printer.st_tprint("Main: deploying the assembly")
sca.deploy()
if printing: Printer.st_tprint("Main: waiting a little before reconfiguring")
time.sleep(3)
sca.suspend()
if printing: Printer.st_tprint("Main: waiting a little before restarting")
time.sleep(5)
sca.restart()
end_time : float = time.perf_counter()
total_time = end_time-start_time
if printing: Printer.st_tprint("Total time in seconds: %f"%total_time)
sca.terminate()
gc : GanttChart = sca.get_gantt_chart()
gc.export_gnuplot("results.gpl")
gc.export_json("results.json")
return total_time
Printer.st_tprint("Main: deploying the assembly")
sca.deploy() # First reconfiguration
Printer.st_tprint("Main: waiting a little before reconfiguring")
time.sleep(3)
def time_test_params(verbosity : int = -1, printing : bool = True, print_time : bool = False,
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.):
if printing: Printer.st_tprint("Main: creating the assembly")
sca = ServerClient(t_sa, t_sr, t_su, t_sc, t_ci1, t_ci2, t_cc, t_cr, t_cs1, t_cs2)
sca.set_use_gantt_chart(False)
sca.set_verbosity(verbosity)
sca.set_print_time(print_time)
if printing: Printer.st_tprint("Main: deploying the assembly")
deploy_start_time : float = time.perf_counter()
sca.deploy()
deploy_end_time : float = time.perf_counter()
total_deploy_time = deploy_end_time-deploy_start_time
if printing: Printer.st_tprint("Main: waiting a little before reconfiguring")
time.sleep(1)
if printing: Printer.st_tprint("Main: reconfiguring the assembly")
reconf_start_time : float = time.perf_counter()
sca.maintain()
reconf_end_time : float = time.perf_counter()
total_reconf_time = reconf_end_time-reconf_start_time
total_time = total_deploy_time+total_reconf_time
Printer.st_tprint("Total time in seconds: %f\n deploy: %f\n reconf: %f"%(total_time,total_deploy_time,total_reconf_time))
deploy_theoretical_time = max(t_sa+t_sr,t_cr+max(t_ci2,t_cc+max(t_ci1,t_sa)))
reconf_theoretical_time = max(t_cs1+t_cs2+t_cr,t_sr+t_cs1+max(t_su,t_sc))
total_theoretical_time = deploy_theoretical_time + reconf_theoretical_time
Printer.st_tprint("Theoretical time in seconds: %f\n deploy: %f\n reconf: %f"%(total_theoretical_time,deploy_theoretical_time,reconf_theoretical_time))
sca.terminate()
return total_deploy_time, total_reconf_time, deploy_theoretical_time, reconf_theoretical_time
sca.suspend() # Second reconfiguration
Printer.st_tprint("Main: waiting a little before restarting")
time.sleep(5)
def random_tests(nb_trials, min_value=0., max_value=10.):
from random import uniform
from json import dumps
from sys import stderr
results = {
"trials": [],
"max_distance_deploy": 0.,
"max_distance_reconf": 0.
}
for i in range(nb_trials):
print("Trial %d/%d"%(i+1,nb_trials), file=stderr)
t_sa = uniform(min_value,max_value)
t_sr = uniform(min_value,max_value)
t_su = uniform(min_value,max_value)
t_sc = uniform(min_value,max_value)
t_ci1 = uniform(min_value,max_value)
t_ci2 = uniform(min_value,max_value)
t_cc = uniform(min_value,max_value)
t_cr = uniform(min_value,max_value)
t_cs1 = uniform(min_value,max_value)
t_cs2 = uniform(min_value,max_value)
trial = {
"t_sa": t_sa,
"t_sr": t_sr,
"t_su": t_su,
"t_sc": t_sc,
"t_ci1": t_ci1,
"t_ci2": t_ci2,
"t_cc": t_cc,
"t_cr": t_cr,
"t_cs1": t_cs1,
"t_cs2": t_cs2
}
real_deploy, real_reconf, theoretical_deploy, theoretical_reconf = time_test_params(verbosity=-1, printing = False, print_time = False,
t_sa=t_sa, t_sr=t_sr, t_su=t_su, t_sc=t_sc, t_ci1=t_ci1, t_ci2=t_ci2, t_cc=t_cc, t_cr=t_cr, t_cs1=t_cs1, t_cs2=t_cs2)
distance_deploy = abs(real_deploy-theoretical_deploy)
distance_reconf = abs(real_reconf-theoretical_reconf)
trial["real_deploy"] = real_deploy
trial["real_reconf"] = real_reconf
trial["theoretical_deploy"] = theoretical_deploy
trial["theoretical_reconf"] = theoretical_reconf
trial["distance_deploy"] = distance_deploy
trial["distance_reconf"] = distance_reconf
results["trials"].append(trial)
if (distance_deploy) > results["max_distance_deploy"]:
results["max_distance_deploy"] = distance_deploy
if (distance_reconf) > results["max_distance_reconf"]:
results["max_distance_reconf"] = distance_reconf
print(dumps(results, indent='\t'))
sca.restart() # Third reconfiguration
sca.terminate() # Terminating the assembly (shutting down the execution thread)
if __name__ == '__main__':
#time_test(
#verbosity = 2,
#printing = False,
#print_time = True
#)
#time_test_params(
#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.
#)
#time_test_params(
#t_sa = 5. ,
#t_sr = 3. ,
#t_su = 8. ,
#t_sc = 7. ,
#t_ci1 = 4. ,
#t_ci2 = 10. ,
#t_cc = 2.5 ,
#t_cr = 2 ,
#t_cs1 = 1. ,
#t_cs2 = 1.5
#)
random_tests(300)
# Exporting the Gantt chart in Gnuplot and JSON formats
Printer.st_tprint("Main: exporting Gantt chart in Gnuplot and JSON formats")
gc : GanttChart = sca.get_gantt_chart()
gc.export_gnuplot("results.gpl")
gc.export_json("results.json")
......@@ -4,65 +4,14 @@ from concerto.all import *
from concerto.utility import Printer
import time, datetime
from client import Client
from server import Server
from examples.utils import *
class ServerClient(Assembly):
def __init__(self, nb_clients):
self.nb_clients = nb_clients
Assembly.__init__(self)
self.clients = []
for i in range(self.nb_clients):
self.clients.append(Client())
self.add_component(self.client_name(i), self.clients[i])
self.server = Server()
self.add_component('server', self.server)
self.synchronize()
@staticmethod
def client_name(id : int):
return 'client%d'%id
def deploy(self):
self.print("### DEPLOYING ####")
for i in range(self.nb_clients):
self.connect(self.client_name(i), 'server_ip',
'server', 'ip')
self.connect(self.client_name(i), 'service',
'server', 'service')
self.push_b(self.client_name(i), 'install_start')
self.push_b('server', 'deploy')
for i in range(self.nb_clients):
self.wait(self.client_name(i))
self.synchronize()
def suspend(self):
self.print("### SUSPENDING ###")
for i in range(self.nb_clients):
self.push_b(self.client_name(i), 'stop')
self.push_b('server', 'stop')
self.wait('server')
self.synchronize()
def restart(self):
self.print("### RESTARTING ###")
for i in range(self.nb_clients):
self.push_b(self.client_name(i), 'install_start')
self.push_b('server', 'deploy')
for i in range(self.nb_clients):
self.wait(self.client_name(i))
self.synchronize()
from server_clients_assembly import ServerClients
def time_test(nb_clients : int, verbosity : int = 0, printing : bool = False, print_time : bool = False) -> float:
start_time : float = time.perf_counter()
if printing: Printer.st_tprint("Main: creating the assembly")
sca = ServerClient(nb_clients)
sca = ServerClients(nb_clients)
sca.set_verbosity(verbosity)
sca.set_print_time(print_time)
......@@ -85,12 +34,11 @@ def time_test(nb_clients : int, verbosity : int = 0, printing : bool = False, pr
sca.terminate()
return total_time
if __name__ == '__main__':
time_test(
nb_clients = 1000,
verbosity = -1,
printing = False,
nb_clients = 3,
verbosity = 1,
printing = True,
print_time = True
)
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