I would like to run these load testing through clicking a button, or something else. How to do this ? and also how to grab those result.
I've built a Jenkins pipeline to do a multi-step process of starting locust instances in AWS, run tests, shut down. Seems like the best approach, as you can add this to your Continuous Integration :)
Here's a short script. Hope this helps you. I agree it would have been nice to have this in the documentation, compared to having to read the source.
from argparse import Namespace
from locust import runners
import locustfile
options = Namespace()
options.host = "http://localhost"
options.num_clients = 10
options.hatch_rate = options.num_clients
options.num_requests = options.num_clients * 10
runners.locust_runner = runners.LocalLocustRunner([locustfile.MyUser], options)
runners.locust_runner.start_hatching(wait=True)
runners.locust_runner.greenlet.join()
for name, value in runners.locust_runner.stats.entries.items():
print(name,
value.min_response_time,
value.median_response_time,
value.max_response_time,
value.total_rps)
I wanted to do the same thing but also run load tests from AWS Lambda so I made a small wrapper for locust to make running it programatically easier:
https://github.com/FutureSharks/invokust
@FutureSharks , nice work! you should consider integrating something similar into the locust codebase... I think a general wrapper would be useful for many (with optional AWS Lambda support added to docs).
Thanks @cgoldberg. OK I'll have a look and see how it could be put into the locust code base.
Would love to see this feature in Locust natively (although @FutureSharks work seems great in the meantime).
@hukka 's response here uses LocalLocustRunner which requires the list of Locust classes as parameter.
However, the locust file I'm trying to run is not a module that's part of the current path, it's just a file sitting somewhere..
Is it possible to add a similar runner (say LocalLocustFileRunner) that takes in a list of files, rather than a list of classes?
Then that would do the same as locust.main.load_locustfile(...), or something like that..
PR #805 is a proposed fix for this but it is unlikely to be merged atm.
Most helpful comment
Here's a short script. Hope this helps you. I agree it would have been nice to have this in the documentation, compared to having to read the source.