Skip to content

Commit

Permalink
locustio#1884 Make rebalance interval configurable
Browse files Browse the repository at this point in the history
  • Loading branch information
tyge68 committed Sep 15, 2021
1 parent 09ff6bc commit e5f43d2
Show file tree
Hide file tree
Showing 3 changed files with 366 additions and 1 deletion.
8 changes: 8 additions & 0 deletions locust/argument_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -471,6 +471,14 @@ def setup_parser_arguments(parser):
dest="enable_rebalancing",
help="Allow to automatically rebalance users if new workers are added after ramp up completed.",
)
other_group.add_argument(
"--rebalance-interval",
action="store",
type=int,
default=5,
dest="rebalance_interval",
help="Rebalance interval in seconds, default is 5 seconds. To be used with --enable-rebalancing",
)

user_classes_group = parser.add_argument_group("User classes")
user_classes_group.add_argument(
Expand Down
6 changes: 5 additions & 1 deletion locust/runners.py
Original file line number Diff line number Diff line change
Expand Up @@ -603,6 +603,10 @@ def __init__(self, environment, master_bind_host, master_bind_port):
self.master_bind_port = master_bind_port
self.spawn_rate: float = 0
self.spawning_completed = False
self.rebalanceInterval = REBALANCE_INTERVAL

if self.environment.parsed_options:
self.rebalanceInterval = self.environment.parsed_options.rebalance_interval

self.clients = WorkerNodes()
try:
Expand Down Expand Up @@ -825,7 +829,7 @@ def check_stopped(self):

def rebalance_worker(self):
while True:
gevent.sleep(REBALANCE_INTERVAL)
gevent.sleep(self.rebalanceInterval)
if self.state == STATE_RUNNING and self.spawning_completed and len(self.clients.ready) > 0:
logger.info(
f"detected ready workers, rebalancing with target={self.target_user_count}, rate={self.spawn_rate}"
Expand Down
Loading

0 comments on commit e5f43d2

Please sign in to comment.