locust

Locust: is there a way to detect the number of Users per Worker?


During the @events.test_start events, is there a way to detect the number of Users per worker? I can get a rough estimate using:

@events.test_start.add_listener
def on_test_start(environment, **_kwargs):
   if not isinstance(environment.runner, WorkerRunner):
      x = environment.runner.target_user_count/environment.runner.worker_count

However, this isn't accurate when different workers have a different number of users - e.g. 11 users and 2 workers, we might have 5 users for worker#1, and 6 users for worker#2. Is there a way to get those exact different values?

Thanks


Solution

  • On master, you can get this number by accessing environment.runner._users_dispatcher._worker_nodes[i].user_count, but it set as spawning happens. The user distribution across workers is determined iteratively, so there's no way to ask Locust before hand.

    The distribution is not random though: The "first" workers (sorted by worker id) should always be the ones receiving an extra user if the user count is not evenly divisible by worker count (assuming workers dont disconnect/connect during the test run).