Load testing is a key component of API development, and Locust is an easy-to-learn tool that employs Python scripts to "swarm" services. It consumes less local resources than most competing tools and has a clean UI via browser interface. This guide will walk you through the setup and sample loadtesting scenarios for Platform projects.
curl https://bootstrap.pypa.io/get-pip.py -o get-pip.py
...
python3 get-pip.py
WARNING: The scripts pip, pip3 and pip3.8 are installed in '/Users/Will/Library/Python/3.8/bin' which is not on PATH.
Consider adding this directory to PATH or, if you prefer to suppress this warning, use --no-warn-script-location.
NOTE: The current PATH contains path(s) starting with `~`, which may not be expanded by all applications.
sudo nano /etc/paths
- Add the directory from the previous command.
- Save the file and exit.
- Restart Terminal.
from locust import HttpUser, task
import uuid
class ServiceUser(HttpUser):
# wait_space = between(1, 5)
@task(1)
def hello_world(self):
self.client.get("{base}/health", name="/health")
Note: Replace {base}
with your service path.
Python has a limitation in that it can't run more than one core per process. However, Locust has the ability to use worker processes to increase its load. This is an important factor in nuking services.
2. For each worker process, open a new Terminal tab and run the command locust -f locustfile.py --worker
Each worker process will increase your requests per second (up to the number of cores in your machine). It's recommended to have at least 4 worker processes.