From 50f0edfca9b552d332d250022e0d8c5fdaa531c7 Mon Sep 17 00:00:00 2001 From: Marco Capitani Date: Thu, 22 Jun 2017 11:04:11 +0200 Subject: Storyboard tested --- rumba/model.py | 40 ++++++++++++++++++++++++++++------------ 1 file changed, 28 insertions(+), 12 deletions(-) (limited to 'rumba/model.py') diff --git a/rumba/model.py b/rumba/model.py index 46a2351..ce4e938 100644 --- a/rumba/model.py +++ b/rumba/model.py @@ -30,9 +30,17 @@ logger = log.get_logger(__name__) try: from numpy.random import poisson + from numpy.random import exponential + logger.debug("Using numpy for faster and better random variables.") except ImportError: from rumba.recpoisson import poisson + def exponential(mean_duration): + return random.expovariate(1.0 / mean_duration) + + logger.debug("Falling back to simple implementations.") + # PROBLEM! These logs will almost never be printed... + # Represents generic testbed info # @@ -717,15 +725,12 @@ class ClientProcess(Client): self.ap, self.node.name, self.duration ) - script = r'nohup "$@" > /dev/null & echo "$!"' opt_str = self.options if self.options is not None else "" - cmds = ["echo '%s' > startup.sh && chmod a+x startup.sh" - % (script,), - "./startup.sh %s %s" % (self.ap, opt_str)] + cmd = "./startup.sh %s %s" % (self.ap, opt_str) self.running = True - self.pid = ssh_support.execute_commands(self.testbed, - self.node.ssh_config, - cmds) + self.pid = ssh_support.execute_command(self.testbed, + self.node.ssh_config, + cmd) def stop(self): logger.debug( @@ -807,20 +812,21 @@ class Server: """Returns a client of this server""" if len(self.clients) == 0: raise Exception("Server %s has empty client list." % (self,)) - duration = random.expovariate(1.0 / self.mean_duration) + duration = exponential(self.mean_duration) return random.choice(self.clients)\ .start_process(duration=duration) def run(self): for node in self.nodes: opt_str = self.options if self.options is not None else "" - script = r'nohup "$@" > /dev/null & echo "$!"' + logfile = "%s.log" % self.ap + script = r'nohup "$@" > %s & echo "$!"' % logfile cmds = ["echo '%s' > startup.sh && chmod a+x startup.sh" % (script,), "./startup.sh %s %s" % (self.ap, opt_str)] logger.debug( - 'Starting server %s on node %s.', - self.ap, node.name + 'Starting server %s on node %s with logfile %s.', + self.ap, node.name, logfile ) self.pids[node] = (ssh_support.execute_commands(self.testbed, node.ssh_config, @@ -843,13 +849,14 @@ class Server: # # @experiment: Experiment to use as input # @duration: Duration of the whole storyboard +# @testbed: The testbed the experiment is run on. # @servers: App servers available in the network # class StoryBoard: DEFAULT_INTERVAL = 2.5 # in seconds (may be a float) - def __init__(self, experiment, duration, servers=None): + def __init__(self, experiment, duration, testbed, servers=None): self.experiment = experiment self.duration = duration if servers is None: @@ -858,6 +865,7 @@ class StoryBoard: self.client_nodes = [c for c in experiment.nodes if c.client] self.active_clients = [] self.start_time = None + self.testbed = testbed def add_server(self, server): self.servers.append(server) @@ -867,6 +875,14 @@ class StoryBoard: def start(self): self.start_time = time.time() + script = r'nohup "$@" > /dev/null & echo "$!"' + for node in self.client_nodes: + logger.debug("Writing utility startup script on client nodes.") + ssh_support.execute_command( + self.testbed, + node.ssh_config, + "echo '%s' > startup.sh && chmod a+x startup.sh" % (script,) + ) try: for server in self.servers: server.run() -- cgit v1.2.3