myzhan / locust4j

Locust4j is a load generator for locust, written in Java.
MIT License
81 stars 30 forks source link

ThreadInterruptedException is not handled correctly in task #21

Closed alien11689 closed 4 years ago

alien11689 commented 4 years ago

When I set step load parameters on master (e.g. step users 100 and duration 60s), than master sends new hatch messsage with 60s interval, but old threads are not stopped.

It's because Abstract task executor swallows InterruptedException which is thrown by my task in Thread.sleep:

2020-07-31 12:38:31,514 [locust4j-worker#13] ERROR c.g.myzhan.locust4j.AbstractTask - Unknown exception when executing the task
java.lang.InterruptedException: sleep interrupted

and task thread cannot be stopped

To fix it I have to throw Error instead of InterruptedException what stops the task, but looks ugly.

myzhan commented 4 years ago

Can you show me the code?

alien11689 commented 4 years ago

I cannot show you the whole code, but to test it is enough to create locust worker like this:

public class HttpGetTask extends AbstractTask {
    @Override
    public void execute() throws Exception {
        Thread.sleep(1000);
        Locust.getInstance().recordSuccess("test", "with sleep", 1000, 0);
    }
}

and run master with step load:

locust --locustfile dummy.py \
    --master \
    --headless \
    --expect-workers 1 \
    --users 1000 \
    --hatch-rate 100 \
    --run-time 120s \
    --step-load \ 
    --step-users 100
    --step-time 10s

success rate should be linear, but because of InterruptedException old threads won't be stopped and at the end worker will report success from 5500 threads instead of 1000

myzhan commented 4 years ago

Thanks @alien11689 , it's a bug when working with --step-load. The master repeatly send hatch message instead of stopping previous tasks.

myzhan commented 4 years ago

See also https://github.com/myzhan/locust4j/commit/3004ae92e4fd2329f8ddf2286fc2e45458aa86c9

myzhan commented 4 years ago

Fixed in version 1.0.11