Skip to content

Commit

Permalink
fix inconsistent status when slave status is changed
Browse files Browse the repository at this point in the history
  • Loading branch information
delulu committed Feb 20, 2019
1 parent a8c0d7d commit d5b310c
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 3 deletions.
2 changes: 2 additions & 0 deletions locust/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)
Expand All @@ -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"
)
Expand Down
11 changes: 8 additions & 3 deletions locust/runners.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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

Expand All @@ -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.user_count, 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.")
Expand Down Expand Up @@ -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):
Expand Down

0 comments on commit d5b310c

Please sign in to comment.