Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

balance/recover the load distribution when new slave joins #970

Merged
merged 2 commits into from
Mar 13, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -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
Expand Down
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.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.")
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