title | layout | filename |
---|---|---|
FastAPI performance optimisation |
template |
index.md |
FastAPI is a great, high performance web framework but far from perfect. This document is intended to provide some tips and ideas to get the most out of it
- All the tests were run on GitHub Actions
- Application is built into a container, you can build it like this:
docker-compose build
- The container has two CPU cores allocated in order to preserve resource for the test client:
app:
container_name: fastapi-performance-optimization
build:
context: app_files
dockerfile: Dockerfile
image: fastapi-performance-optimization:latest
cpus: 2
restart: always
- All the tests were run with the same ab tool configuration available here
- ab config:
ab -q -c 100 -n 1000 -T 'application/json' ...
- ab config:
- All tests were run 3 times and average has been calculated
- Before test run the container has been pre-warmed with small amount of queries, result didn't count in the measurement
- Versions used for these measurements is in the Dockerfile
- Interested in re-running the tests in your environment?
git clone [email protected]:KissPeter/fastapi-performance-optimization.git
pip3 install -r test_files/requirements.txt
pytest -vv -rP test_files/