Experiments for my blog post "Flask Sync vs. Async: Understanding the Performance Bottleneck in IO-Bound Tasks".
- Synchronous and asynchronous endpoints for I/O bound tasks
- Synchronous and asynchronous endpoints for CPU bound tasks (not included on post)
- Equivalent Flask and FastAPI endpoints
- Automated tests for concurrent requests
- Python 3.8+
- Poetry or pip for dependency management
- Make for task automation
To set up the project, you can use either Poetry or pip. If you prefer Poetry, run:
poetry install
or
pip install -r requirements.txt
To run the experiments, you can use the provided Makefile. make
will start both Flask and FastAPI applications and run the experiments concurrently.
Alternatively, you can run the Flask and FastAPI applications separately and then execute the experiments:
- To run the Flask app:
make flask-prod
- To run the FastAPI app:
make fastapi-prod
- To run experiments:
make experiments
Framework | Endpoint | Requests/sec |
---|---|---|
Flask | /io | 4 |
Flask | /async-io | 4 |
Flask | /async-io-multi | 8.3 |
FastAPI | /io | 48.3 |
FastAPI | /async-io | 93.5 |
FastAPI | /async-io-multi | 175.4 |
- Both frameworks running 4 workers with the same workload for each respective endpoint.
- Async endpoints in Flask are limited by WSGI.
- FastAPI is ASGI-native and handles async more efficiently.
MIT License