official locustio documentation tells about how to write simple locust tasks which run indefinitely.
Couldn't find out how to run load which lasts for a specific amount of time, so that the test will automatically stop after the specified interval.
I dont need it from the web interface, command line/code option will be just great.
This answer is out of date. Locust now has a -t / --run-time parameter for specifying run time. See https://docs.locust.io/en/latest/running-locust-without-web-ui.html#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.