简体   繁体   English

如何配置django频道?

[英]How to profile django channels?

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. 我的技术堆栈是Redis作为通道后端,Postgresql作为数据库,Daphne作为ASGI服务器,Nginx作为整个应用程序。 Everything is deployed using Docker Swarm, with only Redis and Database outside. 使用Docker Swarm部署所有内容,只有Redis和数据库外部。 I have about 20 virtual hosts, with 20 interface servers, 40 http workers and 20 websocket workers. 我有大约20个虚拟主机,20个接口服务器,40个http工作者和20个websocket工作者。 Load balancing is done using Ingress overlay Docker network. 使用Ingress覆盖Docker网络完成负载平衡。

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. 大多数请求的处理时间不到400毫秒,但有时请求可能需要2-3秒,即使在非常小的负载下也是如此。 Profiling workers with Django Debug Toolbar or middleware-based profilers shows nothing (timing 0.01s or so) 使用Django Debug Toolbar或基于中间件的分析器的分析工作程序什么都不显示(时间0.01s左右)

My question: is there any good method of profiling a whole request path with django-channels? 我的问题:有什么好方法可以用django-channels分析整个请求路径吗? I would like how much time each phase takes, ie when request was processed by Daphne, when worker started processing, when it finished, when interface server sent response to the client. 我希望每个阶段花费多少时间,即当Daphne处理请求时,当工作者开始处理时,当它完成时,当接口服务器向客户端发送响应时。 Currently, I have no idea how to solve this. 目前,我不知道如何解决这个问题。

Why not stick a monitoring tool something like Kibana or New Relic and monitor why and what's taking so long for a small payload response. 为什么不坚持使用像Kibana或New Relic这样的监控工具,并监控为什么以及为了实现小负载响应所花费的时间。 It can tell you the time spent on Python, PostgreSQL and Memcache (Redis). 它可以告诉你在Python,PostgreSQL和Memcache(Redis)上花费的时间。

Django-silk might be helpful to you in profiling the request and database searching time with following reasons: Django-silk可能对您分析请求和数据库搜索时间有所帮助,原因如下:

  1. It is easy to set by simply adding the configs on settings.py of your Django project. 只需在Django项目的settings.py上添加配置即可轻松设置。
  2. Can be customised: by using the provided decorator, you can profile the function or methods and get their running performance. 可以自定义:通过使用提供的装饰器,您可以分析功能或方法并获得其运行性能。
  3. Dynamic setting: you can choose to dynamically allocate silk to methods and also set the profiling rate you want during the running time. 动态设置:您可以选择动态地为方法分配丝绸,还可以在运行时设置所需的分析速率。

As the documentation states: 正如文件所述:

Silk is a live profiling and inspection tool for the Django framework. Silk是Django框架的实时分析和检查工具。 Silk intercepts and stores HTTP requests and database queries before presenting them in a user interface for further inspection Silk会在将HTTP请求和数据库查询呈现在用户界面中以进行进一步检查之前拦截并存储它们

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 https://github.com/jazzband/django-silk

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM