Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Stop locusts graceful #1062

Closed
xppt opened this issue Aug 8, 2019 · 10 comments
Closed

Stop locusts graceful #1062

xppt opened this issue Aug 8, 2019 · 10 comments

Comments

@xppt
Copy link

xppt commented Aug 8, 2019

Proposal
Add possibility to stop locusts without killing them (via Greenlet.kill). Currently executed tasks should continue, but no new tasks should be scheduled.

Motivation
My load test is a bit uncommon, since I'm using some prepopulation and an additional utility database (redis), which data should be consistent with application data. So my locustfile contains something like this:

def task():
    result = self.client.post('smth').json()  # (1)
    self.redis.set('key', result['value'])    # (2)

When I press [Stop] button, a few on-the-fly tasks are interrupted between (1) and (2). Unfortunately this means that data between application and redis become inconsistent and I'm no longer able to restart test. It forces me to start my prepopulation script again and waste a lot of time.

If locust tasks were stopped graceful, allowing them to return, there would be no problem.

@VitorCioletti
Copy link

Hi. Try using on_stop, it might help you. See the official docs.

@xppt
Copy link
Author

xppt commented Aug 9, 2019

on_stop handler, or even finally block could both be useful here, but they don't solve the problem in the general case.
If some greenlet was killed in the middle of line (1), It is impossible to understand if the application has commited current data already (maybe http request was not sent yet).

@VitorCioletti
Copy link

Not sure if I got it correctly, but task teardown only happens after on_stop, can't you just write a blocking code waiting all your ongoing tasks?

@xppt
Copy link
Author

xppt commented Aug 9, 2019

on_stop is called in the except GreenletExit block of locust (user) greenlet, so my request to the application is already killed. And I'm unable to figure out if it was successful or not.

@VitorCioletti
Copy link

Nice to know that. I'm sorry that won't help you.

@cyberw
Copy link
Collaborator

cyberw commented Oct 19, 2019

I'm trying to add this feature in #1099 . I just need to fix my bugs first :)

@xppt
Copy link
Author

xppt commented Oct 19, 2019

Awesome news! ;)
However I think it might be better to make locusts stop via an gevent.Event, not only by checking the flag before sleeping. It should reduce wait time in some cases.
I have even made a working draft of this idea here: xppt@7b8d2ad.

@cyberw
Copy link
Collaborator

cyberw commented Oct 19, 2019

Cool, I'll have a look at that!

@cyberw cyberw closed this as completed Oct 19, 2019
@cyberw cyberw reopened this Oct 19, 2019
@cyberw
Copy link
Collaborator

cyberw commented Oct 19, 2019

Oops, wrong button - I have been closing too many tickets :)

@cyberw
Copy link
Collaborator

cyberw commented Oct 26, 2019

@xppt Did #1099 solve your issue?

@cyberw cyberw closed this as completed Oct 31, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants