diff --git a/debian/geotrek-api.service b/debian/geotrek-api.service index 23c47332b3..d70d3b79b2 100644 --- a/debian/geotrek-api.service +++ b/debian/geotrek-api.service @@ -6,7 +6,7 @@ StartLimitIntervalSec=30 StartLimitBurst=2 [Service] -ExecStart=/opt/geotrek-admin/bin/gunicorn --config=/opt/geotrek-admin/var/conf/gunicorn-geotrek_api.conf.py geotrek.wsgi +ExecStart=/opt/geotrek-admin/bin/gunicorn --config=/opt/geotrek-admin/var/conf/gunicorn-geotrek_api.conf.py geotrek.asgi -k uvicorn.workers.UvicornWorker Restart=on-failure User=geotrek Group=geotrek diff --git a/debian/geotrek-ui.service b/debian/geotrek-ui.service index 6927d48af9..401bc854a4 100644 --- a/debian/geotrek-ui.service +++ b/debian/geotrek-ui.service @@ -6,7 +6,7 @@ StartLimitIntervalSec=30 StartLimitBurst=2 [Service] -ExecStart=/opt/geotrek-admin/bin/gunicorn --config=/opt/geotrek-admin/var/conf/gunicorn-geotrek.conf.py geotrek.wsgi +ExecStart=/opt/geotrek-admin/bin/gunicorn --config=/opt/geotrek-admin/var/conf/gunicorn-geotrek.conf.py geotrek.asgi -k uvicorn.workers.UvicornWorker Restart=on-failure User=geotrek Group=geotrek diff --git a/docker/Dockerfile b/docker/Dockerfile index 0bf0139a0f..a5d3ef0074 100644 --- a/docker/Dockerfile +++ b/docker/Dockerfile @@ -101,4 +101,4 @@ RUN apt-get update -qq && apt-get -yqq full-upgrade && \ USER geotrek -CMD ["gunicorn", "geotrek.wsgi:application", "--bind=0.0.0.0:8000"] +CMD ["sh", "-c", "gunicorn geotrek.asgi:application --bind=0.0.0.0:8000 -k uvicorn.workers.UvicornWorker --workers ${GUNICORN_WORKERS:-1}"] diff --git a/docs/changelog.rst b/docs/changelog.rst index 5c6e5e780d..76b802ee53 100644 --- a/docs/changelog.rst +++ b/docs/changelog.rst @@ -5,6 +5,10 @@ CHANGELOG 2.109.3+dev (XXXX-XX-XX) ---------------------------- +**Performances** + +- change deployment from standard WSGI to ASGI mode (asynchronous) + 2.109.3 (2024-10-29) ---------------------------- diff --git a/geotrek/asgi.py b/geotrek/asgi.py new file mode 100644 index 0000000000..4090e5e1e8 --- /dev/null +++ b/geotrek/asgi.py @@ -0,0 +1,14 @@ +""" +ASGI config for Overhead Cables And Birdlife backend project. +It exposes the ASGI callable as a module-level variable named ``application``. +For more information on this file, see +https://docs.djangoproject.com/en/4.0/howto/deployment/asgi/ +""" + +import os + +from django.core.asgi import get_asgi_application + +os.environ.setdefault("DJANGO_SETTINGS_MODULE", "geotrek.settings") + +application = get_asgi_application() diff --git a/requirements.txt b/requirements.txt index eb3f1f939b..8fcf012b9e 100644 --- a/requirements.txt +++ b/requirements.txt @@ -68,6 +68,7 @@ click==8.1.3 # click-repl # cligj # fiona + # uvicorn click-didyoumean==0.3.1 # via celery click-plugins==1.1.1 @@ -206,6 +207,8 @@ gpxpy==1.6.2 # via mapentity gunicorn==22.0.0 # via geotrek (setup.py) +h11==0.14.0 + # via uvicorn html5lib==1.1 # via weasyprint idna==3.7 @@ -362,6 +365,7 @@ typing-extensions==4.12.2 # asgiref # django-modeltranslation # kombu + # uvicorn tzdata==2024.2 # via # backports-zoneinfo @@ -375,6 +379,8 @@ urllib3==2.2.2 # via # requests # sentry-sdk +uvicorn==0.32.0 + # via geotrek (setup.py) vine==5.1.0 # via # amqp diff --git a/setup.py b/setup.py index b34032010c..d32ee3baad 100644 --- a/setup.py +++ b/setup.py @@ -73,6 +73,7 @@ def run(self): "django-treebeard", # prod, 'gunicorn', + 'uvicorn', 'sentry-sdk', 'easy-thumbnails[svg]', ],