23

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.

binithb
  • 1,910
  • 4
  • 23
  • 44
  • apparently on the web interface you give a number of users and a rate, so I guess the time is a matter of a division. – njzk2 Aug 19 '14 at 20:55
  • 1
    May be I am completely in the dark or I phrased the question wrong, what I need is to run the load for a specific amount of time and after that the test should automatically stop - is that possible from the web interface – binithb Aug 20 '14 at 18:53

6 Answers6

24

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.

Cyberwiz
  • 11,027
  • 3
  • 20
  • 40
aztlan2k
  • 454
  • 5
  • 4
  • This answer is out of date. Locust now has a -t / --run-time parameter for specifying run time (as stated in other answers) – Cyberwiz Feb 21 '20 at 19:22
15

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
Cyberwiz
  • 11,027
  • 3
  • 20
  • 40
Abhishek Dalvi
  • 372
  • 3
  • 10
10

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.

Ema
  • 209
  • 2
  • 4
  • ah I wanted this feature, 0.9 is not released yet though, nor tagged in GitHub, so installing from `master` is still only option... explains why I didn't see this in the docs online – Anentropic Jul 27 '18 at 10:58
  • This should be the valid answer now, as `--num-requests` was removed See https://github.com/locustio/locust/pull/656 – Vafliik Oct 10 '18 at 10:24
  • This option only works with --no-web argument together. – Terry Lin Nov 06 '18 at 02:57
8

Pretty late to the party, but I stumbled upon this for stopping a test, it might be of help.

stop_timeout = 20 

in your locust class.

Oh, and it accepts it's value in seconds.

Izy-
  • 1,041
  • 2
  • 16
  • 29
  • 2
    To add to it, you need to put `stop_timeout=20` in your load test class that inherits from `Locust` or `HttpLocust` – Sylhare Jun 18 '19 at 15:15
6

it's possible to stop an individual greenlet ("locust") by throwing a StopLocust exception, so you could add a guard in your Task that checks the time

this is undocumented behaviour, and may change in future, but it works in 0.7.2!

http://lookonmyworks.co.uk/2015/03/13/stopping-a-locust/

grahamrhay
  • 2,046
  • 4
  • 19
  • 29
2

Here my solution as per locust 0.8.1, we can't do define how long it will run in CLI mode

timeout $TIME locust -f $YOUR_FILE --host=$YOUR_HOST_TARGET --no-web

Time can be in minutes or second

timeout 10s locust -f $YOUR_FILE --host=$YOUR_HOST_TARGET --no-web
timeout 10m locust -f $YOUR_FILE --host=$YOUR_HOST_TARGET --no-web
abmap
  • 141
  • 5