My technology stack is Redis as a channels backend, Postgresql as a database, Daphne as an ASGI server, Nginx in front of a whole application. Everything is deployed using Docker Swarm, with only Redis and Database outside. I have about 20 virtual hosts, with 20 interface servers, 40 http workers and 20 websocket workers. Load balancing is done using Ingress overlay Docker network.
The problem is, sometimes very weird things happen regarding performance. Most of requests are handled in under 400ms, but sometimes request can take up to 2-3s, even during very small load. Profiling workers with Django Debug Toolbar or middleware-based profilers shows nothing (timing 0.01s or so)
My question: is there any good method of profiling a whole request path with django-channels? I would like how much time each phase takes, i.e when request was processed by Daphne, when worker started processing, when it finished, when interface server sent response to the client. Currently, I have no idea how to solve this.
It’s built on a Python specification called ASGI. Channels builds upon the native ASGI support in Django. Whilst Django still handles traditional HTTP, Channels gives you the choice to handle other connections in either a synchronous or asynchronous style.
Then Configure the CHANNEL_LAYERS by setting a default backend and routing: This uses a Redis backend which is also needed in production. Normally, Django uses HTTP to communicate between the client and server: The client sends an HTTP request to the server. Django parses the request, extracts a URL, and then matches it to a view.
Install Django, Django Channels, and ASGI Redis, and then create a new Django project and app: NOTE: During the course of this tutorial, we will create a variety of different files and folders.
Normally, Django uses HTTP to communicate between the client and server: The client sends an HTTP request to the server. Django parses the request, extracts a URL, and then matches it to a view.
Django-silk might be helpful to you in profiling the request and database searching time with following reasons:
settings.py
of your Django project. As the documentation states:
Silk is a live profiling and inspection tool for the Django framework. Silk intercepts and stores HTTP requests and database queries before presenting them in a user interface for further inspection
Note: silk may double your database searching time, so it may cause some trouble if you set it on your production environment. However, the increase from silk will be shown separately on the dash board.
https://github.com/jazzband/django-silk
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With