8000 GitHub - belinhacbr/flask-perf: Flask Sync vs. Async: Understanding the Performance Bottleneck in IO-Bound Tasks
[go: up one dir, main page]

Skip to content

belinhacbr/flask-perf

Repository files navigation

Flask Sync vs. Async

Experiments for my blog post "Flask Sync vs. Async: Understanding the Performance Bottleneck in IO-Bound Tasks".

Contents

  • 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

Requirements

  • Python 3.8+
  • Poetry or pip for dependency management
  • Make for task automation

Installation

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

Running experiments

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

Experiment Results

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.

Notes

  • Async endpoints in Flask are limited by WSGI.
  • FastAPI is ASGI-native and handles async more efficiently.

References

License

MIT License

About

Flask Sync vs. Async: Understanding the Performance Bottleneck in IO-Bound Tasks

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published
0