diff options
author | Marco Capitani <m.capitani@nextworks.it> | 2017-12-06 14:29:05 +0100 |
---|---|---|
committer | Marco Capitani <m.capitani@nextworks.it> | 2017-12-06 15:15:30 +0100 |
commit | 9eba54236c54f0cd16be899ce254a38bec97af42 (patch) | |
tree | c43b9fd44f19793bbac619edc3c4507cc19c6809 | |
parent | dbc7fd74d8b2c0bf3f2b8f2e81efba8ef2302c1c (diff) | |
download | rumba-9eba54236c54f0cd16be899ce254a38bec97af42.tar.gz rumba-9eba54236c54f0cd16be899ce254a38bec97af42.zip |
storyboard: fix bug with client duration
+ Fixes bug introduced in dbc7fd74d8b2c0bf3f2b8f2e81efba8ef2302c1c
+ implements minimum duration for clients (configurable, default 2 s)
-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: |