简体   繁体   English

Gunicorn 在 docker 容器中运行的 python django 服务陷入死锁

[英]Gunicorn is stuck in deadlock for python django service running in docker container

I am running a python django webhook application that runs via gunicorn server.我正在运行一个通过 gunicorn 服务器运行的 python django webhook 应用程序。 My setup is nginx + Gunicorn + Django. Here is what the config looks like: gunicorn app1.wsgi:application --bind 0.0.0.0:8000 --timeout=0我的设置是 nginx + Gunicorn + Django。这是配置的样子: gunicorn app1.wsgi:application --bind 0.0.0.0:8000 --timeout=0

The application runs perfectly for ~1 -2 million request, but after running for few hours the gunicorn shows in sleep state and then no more webhook event gets received root 3219 1.3 0.0 256620 61532? Sl 14:04 0:19 /usr/local/bin/python /usr/local/bin/gunicorn app1.wsgi:application --bind 0.0.0.0:8000 --timeout=0该应用程序完美运行约 1 -2 百万个请求,但运行几个小时后 gunicorn 显示睡眠 state 然后不再收到 webhook 事件root 3219 1.3 0.0 256620 61532? Sl 14:04 0:19 /usr/local/bin/python /usr/local/bin/gunicorn app1.wsgi:application --bind 0.0.0.0:8000 --timeout=0 root 3219 1.3 0.0 256620 61532? Sl 14:04 0:19 /usr/local/bin/python /usr/local/bin/gunicorn app1.wsgi:application --bind 0.0.0.0:8000 --timeout=0

The service is running in 4 different containers and within few hours this behavior is observed for 1 container and then it occurs for one or more containers in subsequent hours.该服务在 4 个不同的容器中运行,在几个小时内观察到 1 个容器的这种行为,然后在随后的几个小时内对一个或多个容器发生这种行为。

I tried sending a signal to reload gunicorn config which is able to bring the gunicorn process into running state.我尝试发送一个信号来重新加载 gunicorn 配置,它能够使 gunicorn 进程运行 state。

What is curious is that when I run 4 django containers, for few requests it works perfectly well.奇怪的是,当我运行 4 个 django 容器时,对于很少的请求,它运行得非常好。 But continuously receiving traffic causes this deadlock in one of the gunicorn worker's state and it keep on waiting for a trigger to start accepting traffic again while rest of the three gunicorn workers are healthy and running !但是连续接收流量会导致 gunicorn worker 中的一个 state 陷入僵局,它会继续等待触发以再次开始接受流量,而三个 gunicorn worker 中的 rest 健康且正在运行!

Question - Why does gunicorn worker process is going in sleep state(Sl)?问题 - 为什么 gunicorn worker 进程进入睡眠状态(Sl)? How can this behavior be fixed?如何解决此行为?

Try to put Nginx as reverse-proxy in front of gunicorn.尝试将 Nginx 作为反向代理放在 gunicorn 前面。 Perhaps gunicorn incorrectly handles invalid clients which results in deadlock.也许 gunicorn 不正确地处理了导致死锁的无效客户端。 Nginx by itself provides buffering which saves gunicorn from bad things like eternal opened TCP connections. Nginx 本身提供缓冲,可以避免 gunicorn 受到诸如永久打开的 TCP 连接之类的不良事件的影响。

See gunicorn documentation about proper deployment - https://docs.gunicorn.org/en/stable/deploy.html请参阅有关正确部署的 gunicorn 文档 - https://docs.gunicorn.org/en/stable/deploy.html

See this issue for problem discussion - https://github.com/benoitc/gunicorn/issues/2917请参阅此问题以进行问题讨论 - https://github.com/benoitc/gunicorn/issues/2917

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

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