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:
-
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?
-
As you see I still run this project with
python manage.py runserver ...
in DockerFile and it run it ondaphne
. is it a good approach for production? Doesrunserver
a bad idea for production? -
last and important question. what is your recommended combination for better performance? Does it significantly improve performance to use
Nginx
withDaphne
? what is best practice you use?