Load testing : Part 2 (Hatch a tiny Locust)
After nearly a year I got back to load testing.
So , I thought I continue these posts based on new experiences and knowledge.
For starters , check this piece of python code that forms a simple load testing scenario . It should be simple to adjust it to your specific needs.
Note:
Locust is designed [read the documentation!] to hit a host continuously by randomly choosing where to hit [which url] from a set of tasks that it is provided. These tasks can be weighted [meaning: hit this url 10 times more often than the other].
I do not use the default behaviour in my example script. I wanted to have full control of each load test and know exactly what it is doing at every step . In the example test the scenario is executed one time. It is your responsibility to create code that uses many different users that execute the same script. Something like this...
When it is ready, you should open a terminal [preferably PyCharm's terminal, so you can make changes without changing windows] and type:
locust -f path/to/your/locustfile.py
If you wait a couple of seconds you should see this:
[2016-08-02 22:17:53,742] pc_name/INFO/locust.main: Starting web monitor at *:8089
[2016-08-02 22:17:53,746] pc_name/INFO/locust.main: Starting Locust 0.7.3
Now , if you go to your browser and visit localhost:8089 you should see this:
So, this is the starting point of every load testing attempt with Locust.
You have only two options .
The number of users you want to spawn and the rate that you want them to be spawned.
If you want to start gently you can set the hatch rate at 1/sec .
I usually use a hatch rate of 10/sec when I have a big amount of users to simulate.
By experimenting , you will note eventually a strange behaviour from Locust.
When it spawns all the users , it resets its stats . Don't ask me why, I don't know.
So you will find yourself missing users and requests at the end of the run.
My solution is to add a piece of code that adds a delay at the start of the test based on the number of the users that you want to spawn.
You can play with the maximum amount of locusts that you can throw to your app from your local machine.
Depending on your network bandwidth it can be 100 or 10.000. But at some point you are going to clog it and your locust stats dashboard [pending screenshot] will fill with failures.
At that point you should migrate to the master-slave [oh kinky :P] architecture.
In the following post I'll discuss the way to infinitely scale your load testing capabilities using AWS EC2 instances.
Till then , cheers! [..for more posts you can check my blog]
https://github.com/locustio/locust/issues/91 there's an explanation here as to why locust stats are reset after all locusts are hatched (Maybe 2 years too late but at least others may come across this in their research). It is intended behaviour designed to give more realistic performance test results.