I was wondering if using Locust as a library is more efficent than the original way as you don't have to make system calls for a new process this way thus reducing the initial delay at startup. I need to run thousands of separate loadtests for my app so it does make a difference.
Yes it is more efficient. Starting Python, parsing all the imported dependencies etc takes some time.
How much faster is anyones guess though, and running thousands of individual load tests is not something I’ve seen anyone do, so I think you’ll have to test it yourself.
But if you are adding/removing replicas between tests, wont that be slower than restarting Locust anyway?
You can also run Locust in GUI mode and trigger a test by just sending an HTTP request to the /swarm endpoint, that should not have any significantly bigger start up time than library use.
Performance using Locust with a locustfile vs as a library