locustio / locust

Write scalable load tests in plain Python 🚗💨
https://locust.cloud
MIT License
25.06k stars 3k forks source link

Run a sequence only once #1239

Closed ecraven closed 4 years ago

ecraven commented 4 years ago

Hello ;) We'd like to run load tests as follows: each "user" (locust) should fulfil a sequence of tasks once, then stop. I can do the "sequence" thing fine with @seq_task, but how do I tell the locust to not repeat the tasks? I'd like to start up 200, 300, 400, .. locusts, have them each run the one task (all in parallel), then just stop. Is there any simple way to do this?

cyberw commented 4 years ago

Hi! You can do raise StopLocust() at the end of the task.

cyberw commented 4 years ago

but be wary, starting >100 locusts at the same time may give you some issues - fast rampup is difficult (both for locust and the underlying OS), so you'll probably want to distribute the load (at least over multiple locust slave processes, ideally over multiple machines)

cyberw commented 4 years ago

Oh, and if you have more questions like this one, please use StackOverflow instead of filing a ticket :)

heyman commented 4 years ago

Please note that Locust users are not meant to ever stop/die by themselves. Raising StopLocust could work, but it could also have unintended consequences depending on how the tests are ran (distributed/non-distributed, with or without web UI).

alex4200 commented 3 years ago

Hello @cyberw, I have the same question (how to run a single task only once), but the suggestion to use

raise StopLocust()

does not work, as StopLocust() is not defined. And I cannot find that expression in the documentation.

Can you help me with that please?

cyberw commented 3 years ago

@alex4200 StopLocust has been renamed StopUser in locust 1.0!

alex4200 commented 3 years ago

@cyberw StopUser also neither works, nor is mentioned in the documentation.

cyberw commented 3 years ago

sorry, then I'm out of ideas. a brute force solution would be just

while True:
    time.sleep(1)
Apteryks commented 3 years ago

Raising a StopUser exception (from locust.exception import StopUser) works, but will lower the count of users (it really kills them!), which is perhaps not what is desired. I've tested the whlie True workaround, and it works great for my use case, with the caveat that the RPS count stays flat even when nothing happens anymore (a refresh problem, perhaps).