How do I implement a spike test with Locust?

Viewed 1059

I would like to run a spike test using Locust.IO where a large of number of requests are made in parallel to my service.

I have experimented with locust and this is type of command I would like to run:

locust -f locustfile.py --headless --host https://example.com --users 1000 --hatch-rate 1000 --run-time 5s

While running this test no requests are made. I have also tried extending the run time to 60 seconds and no requests are made.

Is there a way of running this type of test in locust?

1 Answers

Here is an example of how to make Users wait until they have all been started.

This way you can have a more reasonable hatch rate (maybe 50/s per load gen) but still have all your users to start the same second (more or less).

class MyUser(HttpUser):
    @task
    def t(self):
        while self.environment.runner.user_count < self.environment.runner.target_user_count:
            time.sleep(1)
        # do your stuff

You may still encounter Python/OS/network related problems related to creating too many outgoing network connections in a short period, so you may need to combine this with multiple processes and maybe even multiple load gens (https://docs.locust.io/en/stable/running-locust-distributed.html)

You might be able to work around this if you first do a dummy request against the server before the sleep so that the connection is already established (although this may reduce the realism of your test a little)

You might also want to consider subclassing FastHttpUser instead of HttpUser: https://docs.locust.io/en/stable/increase-performance.html

Related