question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Only the first user class is being spawned when running locust as library

See original GitHub issue

Describe the bug

I’m running Locust as a library, when instantiating the environment, only the first user class gets spawn up

Expected behavior

All user classes should be span up with the right amount of stimulated users

Actual behavior

only the first specified used class in the environment is being spawned

Steps to reproduce

please see the code snippet

Environment

  • OS: MacOS
  • Python version: 3.7
  • Locust version: image “1.2.3”
  • Locust command line that you ran: running locust as a library in a main method
  • Locust file contents (anonymized if necessary):

user class A

class AUsers(HttpUser):
    host = os.environ.get("A_HOST")
    wait_time = constant_pacing(1)
    tasks = [ATask]

User class B

class BUser(HttpUser):
    host = os.environ.get("B_HOST")
    wait_time = constant_pacing(1)
    tasks = [Btasks]

Master main module :

    env = Environment(user_classes=[BUser,AUser])

    def run_manager(self):
        logging.info('*******************')
        logging.info('{}'.format("Starting Manager"))
        logging.info('*******************')
        self.env.step_load = True
        self.env.create_master_runner()
        self.env.create_web_ui("0.0.0.0", 8089)
        gevent.spawn(stats.stats_history, self.env.runner)
        self.env.runner.greenlet.join()

if __name__ == "__main__":
    manager = ManagerEnv()
    manager.run_manager()

Worker main module

    env = Environment(user_classes=[BUser,AUser])

    def run_worker(self):
        logging.info('*******************')
        logging.info('{}'.format("Starting Worker"))
        logging.info('*******************')
        self.env.create_worker_runner(os.environ.get('MANAGER_HOST'), 5557)
        gevent.spawn(stats_printer(self.env.stats))
        self.env.runner.greenlet.join()


if __name__ == "__main__":
    worker = Worker()
    worker.run_worker()

logs : /INFO/locust.runners: All users spawned: BUser: 1, AUser: 0 (4 already running)

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:12 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
rkhircommented, Dec 14, 2020

Thank you @mboutet, for elaborating. in that case the I can say my original issue is resolved and I can’t wait for it to be merged. nicely done!

0reactions
rkhircommented, Aug 9, 2021

@rkhir Just a trivial question. How do you set the MANAGER_HOST? Any fixed value?

@naveen-kinnal, it’s an environment variable for the Manager’s URL.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Writing a locustfile — Locust 1.2.3 documentation
A user class represents one user (or a swarming locust if you will). Locust will spawn one instance of the User class for...
Read more >
Not able to simulate 2 users after every 5 seconds at ...
And I need to change user spawning logic in runner.py and shape.py inside locust library. Reason: Locust does not spawn 2 full users...
Read more >
4 Useful Advanced Features in Locust | by Ng Wai Foong
Fortunately, Locust provides a LoadTestShape class which can be used to control the user count and spawn rate based on your needs. All...
Read more >
Performance testing using locust with parallel requests - Medium
The above code makes use of gevent library and spawns as many instances of requests needed for a single user and this is...
Read more >
Locust - Python based Performance Testing Tool (By Naveen ...
Demonstrating First Load Test using Locust 3. Results Analysis in Locust 4. Data Parameterization in Locust 5. Correlation in Locust 6.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found