This project sets up API performance testing using Locust—a scalable, open-source load testing tool that lets you simulate thousands of concurrent users to test the performance of your API endpoints.
Locust is a modern load testing tool that allows you to write test scenarios in Python. It's developer-friendly, supports real-time web UI monitoring, and integrates easily with CI/CD pipelines.
- Concurrent user load on REST APIs
- Response time under load
- RPS (Requests Per Second) benchmarking
- Performance regressions
- Load limits and bottlenecks
- Apply Custom Load shapes
pip install -r requirements.txt
- Go to project directory and Create a virtual environment using
python -m venv venv
- Type
venv\Scripts\activate.bat
and hit enter - Create a requirements.txt file and add the required library. For Ex: To install locust, add locust==2.24.0 in the file. (This i have added alerady)
- Run the command to install the library.
pip install -r requirements.txt
. - Run the application
locust -f getorder.py
locust -f locustfile.py --host=http://localhost:8000
Enter load parameters:
Number of users (e.g., 100) Spawn rate (e.g., 10 users/sec) Click Start Swarming
📈 Using Custom Load Shape For more control over traffic patterns (e.g., ramp-up, plateau, ramp-down), use a custom load shape defined in customshapes/collectionlist-bellcurve.py
✅ Run with Custom Load Shape locust -f locustfile.py load_shape.py --host=http://localhost:8000
🛠️ Headless Mode (CI/CD) locust -f locustfile.py --host=http://localhost:8000 --headless -u 100 -r 10 -t 2m
📊 Metrics Observed Requests per second (RPS)
Average and percentile response times (p50, p95)
Failure rates
Active users and throughput over time