diff options
-rw-r--r-- | rumba/storyboard.py | 30 |
1 files changed, 23 insertions, 7 deletions
diff --git a/rumba/storyboard.py b/rumba/storyboard.py index 5d1202f..b6e07d6 100644 --- a/rumba/storyboard.py +++ b/rumba/storyboard.py @@ -180,7 +180,7 @@ class ClientProcess(object): class Server: def __init__(self, ap, arrival_rate, mean_duration, options=None, max_clients=float('inf'), - clients=None, nodes=None): + clients=None, nodes=None, min_duration=2): self.ap = ap self.options = options if options is not None else "" self.max_clients = max_clients @@ -191,8 +191,10 @@ class Server: nodes = [] self.nodes = nodes self.arrival_rate = arrival_rate # mean requests/s - self.mean_duration = mean_duration # in seconds + self.actual_parameter = max(mean_duration - min_duration, 0.1) + # in seconds self.pids = {} + self.min_duration = min_duration def add_client(self, client): self.clients.append(client) @@ -222,7 +224,7 @@ class Server: """Returns a client of this server""" if len(self.clients) == 0: raise Exception("Server %s has empty client list." % (self,)) - duration = exponential(self.mean_duration) + duration = exponential(self.actual_parameter) + self.min_duration return random.choice(self.clients).process( duration=float("%.2f" % (duration,)) ) @@ -331,17 +333,21 @@ class StoryBoard: try: for server in self.servers: server.run() - while time.time() - self.start_time < (self.duration + 10): - # + 10 -> To account for last-minute terminations. + while time.time() - self.start_time < self.duration: for server in self.servers: clients = server.get_new_clients(self.DEFAULT_INTERVAL) for new_client in clients: # type: ClientProcess new_client.duration = min( new_client.duration, - self.duration - time.time() + self.duration - (time.time() - self.start_time) ) # Make sure the duration of the client does not # go beyond the storyboard lifetime + if new_client.duration < server.min_duration: + continue + # Do not start clients that would not run for + # at least the minimum duration + # (due to sb constraints) new_client.run() self.active_clients.append(new_client) surviving = [] @@ -350,7 +356,17 @@ class StoryBoard: surviving.append(x) self.active_clients = surviving time.sleep(self.DEFAULT_INTERVAL) - finally: + time.sleep(5) + # Do a check that is supposed to find all remaining clients + # as expired + surviving = [] + for x in self.active_clients: + if x.check(): + surviving.append(x) + self.active_clients = surviving + if surviving: # implied: is not empty + logger.warning('Some clients could not be killed gracefully.') + finally: # Kill everything. No more mercy. for client in self.active_clients: client.stop() for server in self.servers: |