Using Daphne (ASGI) for all requests. (workaround)

Hi,
recently moved our project in production and I see performance issue. the deployment is as below.

we use Daphne (Async) for every requests (both http and websocket):

setting.py

INSTALLED_APPS = [
    'daphne',
	.
	.
	]
	
WSGI_APPLICATION = 'core.wsgi.application'
ASGI_APPLICATION = 'core.asgi.application'
CHANNEL_LAYERS = {
    'default': {
        'BACKEND': 'channels.layers.InMemoryChannelLayer'
    }
}

asgi.py

import os
from channels.auth import AuthMiddlewareStack
from channels.routing import ProtocolTypeRouter, URLRouter
from channels.security.websocket import AllowedHostsOriginValidator
from django.core.asgi import get_asgi_application

os.environ.setdefault("DJANGO_SETTINGS_MODULE", "core.settings")
django_asgi_app = get_asgi_application()

import chat.routing

application = ProtocolTypeRouter(
    {
        "http": django_asgi_app,
        "websocket": AllowedHostsOriginValidator(
            AuthMiddlewareStack(
                URLRouter(chat.routing.websocket_urlpatterns))
        ),
    }
)

I run whole project on docker and running this part is with below Dockerfile (production)

FROM dock_nasim:latest

EXPOSE 80
STOPSIGNAL SIGTERM
CMD ["python", "manage.py", "runserver", "0.0.0.0:80"]

and below is logs

Django version 4.2.6, using settings 'core.settings'
Starting ASGI/Daphne version 4.0.0 development server at http://0.0.0.0:80/
Quit the server with CTRL-BREAK.

just to show that runserver is running Daphne.

besides database runing and ORM optimization and … I’m sure that most performance issue is because of deployment. I wonder:

  1. Is it a good approach to use only Daphne (ASGI) for every requests (including HTTP)? to ask this in another form, Is Django fully async now and doesn’t impact performance?

  2. As you see I still run this project with python manage.py runserver ... in DockerFile and it run it on daphne. is it a good approach for production? Does runserver a bad idea for production?

  3. last and important question. what is your recommended combination for better performance? Does it significantly improve performance to use Nginx with Daphne? what is best practice you use?

Yes, it’s an extremely bad idea.

Quoting directly from the docs for runserver:

DO NOT USE THIS SERVER IN A PRODUCTION SETTING.

Runserver should have no part in your production deployment.

We deploy behind nginx as a web/proxy server. We use uwsgi to run the Django code and Daphne to handle the websocket connections. (You can find a few posts in this topic talking about this type of deployment.)

Great, Implementing Nginx serving static files and forwarding websocket to Daphne and http to uWSGI improved performance. Thanks
now I’m looking for optimisation in Nginx, Daphne and uWSGI configurations