From 4f1aeec8532dae7399cfd41068edd7558a8a566c Mon Sep 17 00:00:00 2001 From: Gabriel Barberini Date: Sat, 15 Mar 2025 21:44:46 -0300 Subject: [PATCH] setup uvloop uvicorn worker --- Dockerfile | 2 +- src/settings/gunicorn.py | 5 +++++ 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/Dockerfile b/Dockerfile index ce53e71..074269d 100644 --- a/Dockerfile +++ b/Dockerfile @@ -16,4 +16,4 @@ RUN apt-get update && \ COPY ./src /app/src -CMD ["gunicorn", "-c", "src/settings/gunicorn.py", "-w", "1", "--threads=2", "-k", "uvicorn.workers.UvicornWorker", "src.api:app", "--log-level", "Debug", "-b", "0.0.0.0:3000", "--timeout", "60"] +CMD ["gunicorn", "-c", "src/settings/gunicorn.py", "-w", "1", "--threads=2", "-k", "src.settings.gunicorn.UvloopUvicornWorker", "src.api:app", "--log-level", "Debug", "-b", "0.0.0.0:3000", "--timeout", "60"] diff --git a/src/settings/gunicorn.py b/src/settings/gunicorn.py index f2b92cd..7d3def1 100644 --- a/src/settings/gunicorn.py +++ b/src/settings/gunicorn.py @@ -1,5 +1,6 @@ import uptrace from opentelemetry.instrumentation.fastapi import FastAPIInstrumentor +from uvicorn.workers import UvicornWorker from src.secrets import Secrets @@ -15,3 +16,7 @@ def post_fork(server, worker): # pylint: disable=unused-argument ) FastAPIInstrumentor.instrument_app(fastapi_server) + + +class UvloopUvicornWorker(UvicornWorker): + CONFIG_KWARGS = {"loop": "uvloop"}