Locust : How to make locust run for a specific amount of time

locust now supports run-time parameter --run-time=1h20m. I installed locust from the master branch. (see GitHub issue). I think this feature is officially released in 0.9v.


This answer is out of date. Locust now has a -t / --run-time parameter for specifying run time. See https://docs.locust.io/en/stable/running-without-web-ui.html?highlight=run-time#setting-a-time-limit-for-the-test

I recently started using locust myself and unfortunately locust 0.7.1 does not provide a way to terminate a test based on a length of time.

It does however provide a way to terminate the test based on the number of requests that have been issued. If you run locust using the CLI interface you can specify that it stop execution after a specified number of requests have been handled. From the locust --help output:

-n NUM_REQUESTS, --num-request=NUM_REQUESTS
       Number of requests to perform. Only used together with --no-web

So, you can start a session with something along the lines of:

# locust --clients=20 --hatch-rate=2 --num-request=500

and once 500 requests have been handled it should terminate the test.


It's probably too late to answer, but might be helpful for someone in future. Locust now supports -t or --run-time options to specify duration when running Locust with --headless option. From locust --help:

-t RUN_TIME, --run-time=RUN_TIME
                        Stop after the specified amount of time, e.g. (300s,
                        20m, 3h, 1h30m, etc.). Only used together with --no-
                        web