If you are a developer that works in a field where you are asked to create or maintain REST API as your daily job, you'll surely have found yourself in the need of testing API performance at some point. I've found a very nice and simple tool to do that: Locust.
Locust has several nice features that I really like:
- Support distributed deployment. You can create a lot of clients, all managed by a single master, to general a lot of test calls.
- Python-based. The code to test target API is plain Python, all in one file ("locustfile.py"), with some specific objects made available by Locust to make life easier. I really like that.
- A single locust file can host more than one test, and each test can have its own weight so that you can exactly decide how to distribute workload
- Has a nice user interface that clearly shows Request Per Seconds over time and, in case, Exceptions and Failures
- Works very well with Docker and can be dockerized in less than 150 Megabytes
In order to use Locust in Azure in the simplest and easiest way possble, I've create a docker image on Docker Hub:
As I really wanted some really easy and simple to use, I decided to go for Azure Container Instances, and the repo with the script code to deploy Locust is available here:
If you are more inclined to use a more complex but more complete container orchestrator, of course Kubernetes could be better option.
In the mentioned repo, the script will take care of everything needed to run Locust on Azure:
- create a storage account to host to locust file
- create a storage share for the locust file
- upload the locust file
- deploy the master locust and the desired clients in Azure Container Instances
- configure master and clients correctly
- run the locust swarm
Easy and nice, I can now run test for stability and performance my API.