From 249901120c61fe50ea497876e847f5f8259a3eca Mon Sep 17 00:00:00 2001 From: delulu Date: Mon, 18 Feb 2019 16:07:45 +0800 Subject: [PATCH 1/2] fix inconsistent status when slave status is changed --- locust/main.py | 2 ++ locust/runners.py | 11 ++++++++--- 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/locust/main.py b/locust/main.py index f9a02c91d5..fe3186d861 100644 --- a/locust/main.py +++ b/locust/main.py @@ -132,6 +132,7 @@ def parse_options(): '--heartbeat-liveness', action='store', type='int', + dest='heartbeat_liveness', default=3, help="set number of seconds before failed heartbeat from slave" ) @@ -140,6 +141,7 @@ def parse_options(): '--heartbeat-interval', action='store', type='int', + dest='heartbeat_interval', default=1, help="set number of seconds delay between slave heartbeats to master" ) diff --git a/locust/runners.py b/locust/runners.py index f23d62fb9e..910c3f1e88 100644 --- a/locust/runners.py +++ b/locust/runners.py @@ -283,6 +283,7 @@ def start_hatching(self, locust_count, hatch_rate): return self.num_clients = locust_count + self.hatch_rate = hatch_rate slave_num_clients = locust_count // (num_slaves or 1) slave_hatch_rate = float(hatch_rate) / (num_slaves or 1) remaining = locust_count % num_slaves @@ -328,6 +329,7 @@ def heartbeat_worker(self): if client.heartbeat < 0 and client.state != STATE_MISSING: logger.info('Slave %s failed to send heartbeat, setting state to missing.' % str(client.id)) client.state = STATE_MISSING + client.user_count = 0 else: client.heartbeat -= 1 @@ -338,7 +340,10 @@ def client_listener(self): if msg.type == "client_ready": id = msg.node_id self.clients[id] = SlaveNode(id, heartbeat_liveness=self.heartbeat_liveness) - logger.info("Client %r reported as ready. Currently %i clients ready to swarm." % (id, len(self.clients.ready))) + logger.info("Client %r reported as ready. Currently %i clients ready to swarm." % (id, len(self.clients.ready + self.clients.running + self.clients.hatching))) + # balance the load distribution when new client joins + if self.state == STATE_RUNNING or self.state == STATE_HATCHING: + self.start_hatching(self.num_clients, self.hatch_rate) ## emit a warning if the slave's clock seem to be out of sync with our clock #if abs(time() - msg.data["time"]) > 5.0: # warnings.warn("The slave node's clock seem to be out of sync. For the statistics to be correct the different locust servers need to have synchronized clocks.") @@ -366,8 +371,8 @@ def client_listener(self): elif msg.type == "exception": self.log_exception(msg.node_id, msg.data["msg"], msg.data["traceback"]) - if not self.state == STATE_INIT and all(map(lambda x: x.state == STATE_INIT, self.clients.all)): - self.state = STATE_STOPPED + if not self.state == STATE_INIT and all(map(lambda x: x.state != STATE_RUNNING and x.state != STATE_HATCHING, self.clients.all)): + self.state = STATE_STOPPED @property def slave_count(self): From 0448982561d873bb22caf4c11862b97676980fd5 Mon Sep 17 00:00:00 2001 From: delulu Date: Fri, 1 Mar 2019 17:42:09 +0800 Subject: [PATCH 2/2] fix docker build issue --- Dockerfile | 1 + 1 file changed, 1 insertion(+) diff --git a/Dockerfile b/Dockerfile index b99c8f14fb..8a2c1aeff1 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,6 +1,7 @@ FROM python:3.6.6-alpine3.8 RUN apk --no-cache add g++ \ + && apk --no-cache add zeromq-dev \ && pip install locustio pyzmq EXPOSE 8089 5557 5558