Skip to content

FastAPI with async/await background tasks (ARQ, SAQ, FastStream, Celery) + Prometheus + Grafana

Notifications You must be signed in to change notification settings

ipakeev/fastapi-async-tasks

Repository files navigation

FastAPI with async background tasks + Prometheus + Grafana

This project provides a way to setup and run asynchronous (async/await) tasks using these libraries:

This way can also be useful for testing your code with eager execution. You can see it in tests/conftest.py.

Finally, it shows how to monitor FastAPI app and execution of tasks with Prometheus + Grafana using these libraries:


Installation

Clone the repository:

git clone https://github.com/ipakeev/fastapi-async-tasks

Usage

Create .env file and adjust it:

cp example.env .env

Build app image:

docker build -t fastapi-async-tasks .

Run all containers:

docker-compose up

Now you have access to these services:

Raw metrics are available here:


Benchmark

You can test the performance of the application and run a benchmark using locust:

env endpoint={endpoint} locust --config locust/master.conf -f locust/benchmark.py -u 10 -i 1000
env endpoint={endpoint} locust --config locust/master.conf -f locust/background.py -u 10 -i 1000

Available {endpoint}s:

  • io/simple
  • io/sync
  • io/thread
  • cpu/simple
  • cpu/process

About

FastAPI with async/await background tasks (ARQ, SAQ, FastStream, Celery) + Prometheus + Grafana

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages