This project benchmarks the performance of web frameworks in Python (FastAPI, Django DRF, Django Ninja) and Rust (Axum, Rocket, Actix) using the wrk
load testing tool. It measures Requests per Second (RPS) under varying concurrent connection loads and generates a comparative plot.
- Tests multiple web frameworks with configurable connection loads, durations, and thread counts.
- Supports three test modes:
fast
,full
, andstress
. - Generates a plot comparing RPS across frameworks.
- Automated setup and cleanup using Docker Compose and a Bash script.
- Saves results in JSON format for further analysis.
- Docker and Docker Compose
- Python 3.8+
- wrk (load testing tool)
- Bash (for running the test script on Unix-like systems)
├── docker-compose.yml # Defines services for Python and Rust frameworks
├── run_test.sh # Bash script to run tests and clean up
├── benchmark_wrk.py # Python script for benchmarking and plotting
├── python_apps/ # Directory with Python framework apps
│ ├── fastapi_app/
│ ├── drf_app/
│ └── ninja_app/
├── rust_apps/ # Directory with Rust framework apps
│ ├── rust_axum/
│ ├── rust_rocket/
│ └── rust_actix/
└── README.md # This file
-
Clone the Repository
git clone https://github.com/fzappa/benchmarking_apis.git cd benchmarking_api
-
Install Python Dependencies Install the required Python packages:
pip install -r requirements.txt
If a
requirements.txt
doesn't exist yet, install these manually:pip install matplotlib numpy tqdm
-
Install wrk
- On Ubuntu/Debian:
sudo apt-get install wrk
- On macOS:
brew install wrk
- See wrk's GitHub for other systems.
- On Ubuntu/Debian:
-
Ensure Docker is Running Verify Docker is installed and running:
docker --version docker compose version
The project includes a Bash script (run.sh
) to automate building, testing, and cleanup.
-
Run the Full Test
bash run.sh
This will:
- Build and start Docker containers for all frameworks.
- Run the
full
benchmark mode with 5 repetitions. - Stop and remove containers and images afterward.
- Generate a plot (
benchmark_wrk_result.png
) and save data (wrk_data.json
).
-
Customize the Test Modify
run_test.sh
or runbenchmark_wrk.py
directly with arguments:python benchmark_wrk.py --mode full --reps 5 --timestamp
--mode
:fast
,full
, orstress
(default:fast
).--reps
: Number of test repetitions (default: 3).--timestamp
: Append a timestamp to output files.
-
View Results
- Plot: Check
benchmark_wrk_result.png
(or a timestamped version if--timestamp
is used). - Data: Open
wrk_data.json
for raw RPS values.
- Plot: Check
fast
: Quick test with 1 and 10 connections, 3-second duration, 1 thread.full
: Comprehensive test with 1 to 1000 connections, 5-second duration, 8 threads.stress
: Stress test with 100 to 1000 connections, 20-second duration, 8 threads.
The docker-compose.yml
defines six services:
- FastAPI: Python, port
8001
- Django DRF: Python, port
8002
- Django Ninja: Python, port
8003
- Axum: Rust, port
3000
- Rocket: Rust, port
8000
- Actix: Rust, port
8080
Each service has its own Dockerfile in the respective python_apps/
or rust_apps/
directory.
After running the test, you’ll get:
- A plot comparing RPS across frameworks on a logarithmic scale.
- A JSON file with connection counts and RPS results.
- Fork the repository.
- Create a feature branch (
git checkout -b feature/your-feature
). - Commit your changes (
git commit -m "Add your feature"
). - Push to the branch (
git push origin feature/your-feature
). - Open a Pull Request.
This project is licensed under the GPLv3 License. See GPLv3 for details.
- Inspired by the need to compare Python and Rust web framework performance.
- Thanks to the
wrk
team for an excellent benchmarking tool.