Skip to content

silverstone1903/auto-load-testing

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Auto Load Test with locust for FastAPI


Used reco API for load testing.


Folder Structure

|   docker-compose.yml
|   readme.md
|   tree.txt
+---app
|       Dockerfile
|       main.py
|       requirements.txt
|       utils.py
+---assets
|       locust-1.jpg
|       locust-2.jpg
|       locust-3.jpg
+---data
|       customer_item_matrix.parquet
|       df.parquet
|       item_item_sim_matrix.parquet
|       user_user_sim_matrix.parquet
\---locust
        locustfile.py

Installation

There are only two prerequisites:


git clone https://github.com/silverstone1903/auto-load-testing

Usage

Settings

You can change load test values in docker-compose.yml. locust works with 50 users, 2 hatch rate and 10 seconds run time by default. When run time limit reached docker stopping locust container and then app looks unhealty. To prevent this I added --exit-code-from {container} command to run compose. When locust finishes compose stopping the remain container and shut downs the app.

command: -f /mnt/locust/locustfile.py --headless -u 50 -r 2 --run-time 10s --host http://fastapi:8000

Start

docker-compose up --exit-code-from locust

If you make any changes you can add --build.

docker-compose up --build --exit-code-from locust

Stopping containers

docker-compose down 

Container Logs

If you want to check locust results you can use logs. Uvicorn app works with --log-level critical so there won't be any fastapi related logs. You can easily check locust aggregated results.

docker-compose logs --tail 50

Blog post (in Turkish): Auto Load Testing - FastAPI + locust


Screenshots

Locust Results