Skip to content

Commit

Permalink
Changing realization of the fixed users spawning.
Browse files Browse the repository at this point in the history
Because in case then UserDispatcher._users_on_workers
is not fills instantly (see UserDispatcher._distribute_users)
we cant to monitore actual count of each user.
Also added some additional tests, includes to check this behaviour.
  • Loading branch information
EzR1d3r committed Jan 19, 2022
1 parent 4a18b91 commit 308c835
Show file tree
Hide file tree
Showing 3 changed files with 274 additions and 307 deletions.
24 changes: 17 additions & 7 deletions locust/dispatch.py
Original file line number Diff line number Diff line change
Expand Up @@ -248,6 +248,7 @@ def _add_users_on_workers(self) -> Dict[str, Dict[str, int]]:
current_user_count_target = min(
self._current_user_count + self._user_count_per_dispatch_iteration, self._target_user_count
)

for user in self._user_generator:
if not user:
self._no_user_to_spawn = True
Expand Down Expand Up @@ -309,6 +310,8 @@ def _distribute_users(
user_count = 0
while user_count < target_user_count:
user = next(user_gen)
if not user:
break
worker_node = next(worker_gen)
users_on_workers[worker_node.id][user] += 1
user_count += 1
Expand Down Expand Up @@ -366,18 +369,25 @@ def infinite_cycle_gen(users: List[Tuple[User, int]]) -> Generator[Optional[str]
# Spawn users
while True:
if self._try_dispatch_fixed:
self._try_dispatch_fixed = False
current_fixed_users_count = {u: self._get_user_current_count(u) for u in fixed_users}
spawned_classes = set()
while True:
while len(spawned_classes) != len(fixed_users):
user_name = next(cycle_fixed_gen)
if not user_name:
break
if self._get_user_current_count(user_name) >= fixed_users[user_name].fixed_count:
spawned_classes.add(user_name)
else:

if current_fixed_users_count[user_name] < fixed_users[user_name].fixed_count:
current_fixed_users_count[user_name] += 1
if current_fixed_users_count[user_name] == fixed_users[user_name].fixed_count:
spawned_classes.add(user_name)
yield user_name
if len(spawned_classes) == len(fixed_users):
break
self._try_dispatch_fixed = False

# 'self._try_dispatch_fixed' was changed outhere, we have to recalculate current count
if self._try_dispatch_fixed:
current_fixed_users_count = {u: self._get_user_current_count(u) for u in fixed_users}
spawned_classes.clear()
self._try_dispatch_fixed = False

yield next(cycle_weighted_gen)

Expand Down
Loading

0 comments on commit 308c835

Please sign in to comment.