Gunicorn:所有容器上的工人超时和工人退出
Gunicorn: worker timeout and worker exiting on all containers
关于我的问题的一些背景知识:
我有以下 Gunicorn 配置文件:gunicorn_cofig.py
pidfile = 'app.pid'
worker_tmp_dir = '/dev/shm'
worker_class = 'gthread'
workers = 1
worker_connections = 1000
timeout = 30
keepalive = 1
threads = 2
proc_name = 'app'
bind = '0.0.0.0:8080'
backlog = 2048
accesslog = '-'
errorlog = '-'
最初,我 运行 在 Docker 中使用了一个 Flask 应用程序和 Nginx,而 Gunicorn 从来没有遇到过问题。后来我添加了另一个应用程序并将我的 Nginx 配置为将请求从不同的子域重定向到不同的端口(例如 mydomain.com -> 端口 81 和应用程序。mydomain.com -> 端口 5000)(如果我理解正确,因为我将所有子域绑定到同一个 IP(我使用 LetsEncrypt)来自所有子域的请求来到端口 443,然后 Nginx 将它们反向代理到各自的端口)。为此,我只是在新应用程序中复制粘贴了相同的 gunicorn_cofig.py
,它工作正常。
现在我添加了 6 个应用程序,我在所有应用程序中使用相同的配置文件,但出现以下错误:
app1 [2022-01-13 05:30:26 +0000] [1] [CRITICAL] WORKER TIMEOUT (pid:9)
app1 | [2022-01-13 05:30:26 +0000] [1] [CRITICAL] WORKER TIMEOUT (pid:10)
app1 | [2022-01-13 05:30:26 +0000] [1] [CRITICAL] WORKER TIMEOUT (pid:11)
app1 | [2022-01-13 05:30:26 +0000] [11] [INFO] Worker exiting (pid: 11)
app1 | [2022-01-13 05:30:26 +0000] [9] [INFO] Worker exiting (pid: 9)
app1 | [2022-01-13 05:30:26 +0000] [10] [INFO] Worker exiting (pid: 10)
app1 | [2022-01-13 05:30:27 +0000] [1] [WARNING] Worker with pid 9 was terminated due to signal 9
app1 | [2022-01-13 05:30:27 +0000] [1] [WARNING] Worker with pid 11 was terminated due to signal 9
app1 | [2022-01-13 05:30:27 +0000] [12] [INFO] Booting worker with pid: 12
app1 | [2022-01-13 05:30:27 +0000] [1] [WARNING] Worker with pid 10 was terminated due to signal 9
app1 | [2022-01-13 05:30:27 +0000] [13] [INFO] Booting worker with pid: 13
app2 | [2022-01-13 05:30:27 +0000] [1] [CRITICAL] WORKER TIMEOUT (pid:9)
app2 | [2022-01-13 05:30:27 +0000] [1] [CRITICAL] WORKER TIMEOUT (pid:10)
app2 | [2022-01-13 05:30:27 +0000] [10] [INFO] Worker exiting (pid: 10)
app2 | [2022-01-13 05:30:27 +0000] [1] [CRITICAL] WORKER TIMEOUT (pid:11)
app2 | [2022-01-13 05:30:27 +0000] [9] [INFO] Worker exiting (pid: 9)
app1 | [2022-01-13 05:30:27 +0000] [14] [INFO] Booting worker with pid: 14
依此类推,适用于每个应用程序。
我试图将 proc_name = 'app'
更改为不同的值,但发生了同样的事情。这是我的 docker 撰写文件的片段,其中我 运行 Gunicorn 的命令:
m:
build:
dockerfile: ./m/Dockerfile
context: ../../
command: gunicorn --bind 0.0.0.0:82 --workers 3 ${M_FLASK_APP}:app
environment:
- FLASK_ENV=${FLASK_ENV}
- PYTHONUNBUFFERED=1
ports:
- 82:82
volumes:
- ./m/src:/opt/m
p:
build:
dockerfile: ./p/Dockerfile
context: ../../
command: gunicorn --bind 0.0.0.0:83 --workers 3 ${P_FLASK_APP}:app
environment:
- FLASK_ENV=${FLASK_ENV}
- PYTHONUNBUFFERED=1
ports:
- 83:83
volumes:
- ./p/src:/opt/p
有人可以指导我正确的方向吗?是 gunicorn 配置问题还是 docker(因为我 运行 有 6 个应用程序和 1 个 nginx 服务器)?
我通过升级我的 Compute Engine 实例解决了这个问题(我正在使用 Google 云)。以前我有 2 CPU 个内核和 4GB RAM,并将其更改为 4 CPU 个内核和 4GB RAM CPU 优化机器。现在我可以在同一个实例上托管 6 个以上的应用程序,但成本要高得多。显然,上述错误的原因是硬件限制。
关于我的问题的一些背景知识:
我有以下 Gunicorn 配置文件:gunicorn_cofig.py
pidfile = 'app.pid'
worker_tmp_dir = '/dev/shm'
worker_class = 'gthread'
workers = 1
worker_connections = 1000
timeout = 30
keepalive = 1
threads = 2
proc_name = 'app'
bind = '0.0.0.0:8080'
backlog = 2048
accesslog = '-'
errorlog = '-'
最初,我 运行 在 Docker 中使用了一个 Flask 应用程序和 Nginx,而 Gunicorn 从来没有遇到过问题。后来我添加了另一个应用程序并将我的 Nginx 配置为将请求从不同的子域重定向到不同的端口(例如 mydomain.com -> 端口 81 和应用程序。mydomain.com -> 端口 5000)(如果我理解正确,因为我将所有子域绑定到同一个 IP(我使用 LetsEncrypt)来自所有子域的请求来到端口 443,然后 Nginx 将它们反向代理到各自的端口)。为此,我只是在新应用程序中复制粘贴了相同的 gunicorn_cofig.py
,它工作正常。
现在我添加了 6 个应用程序,我在所有应用程序中使用相同的配置文件,但出现以下错误:
app1 [2022-01-13 05:30:26 +0000] [1] [CRITICAL] WORKER TIMEOUT (pid:9)
app1 | [2022-01-13 05:30:26 +0000] [1] [CRITICAL] WORKER TIMEOUT (pid:10)
app1 | [2022-01-13 05:30:26 +0000] [1] [CRITICAL] WORKER TIMEOUT (pid:11)
app1 | [2022-01-13 05:30:26 +0000] [11] [INFO] Worker exiting (pid: 11)
app1 | [2022-01-13 05:30:26 +0000] [9] [INFO] Worker exiting (pid: 9)
app1 | [2022-01-13 05:30:26 +0000] [10] [INFO] Worker exiting (pid: 10)
app1 | [2022-01-13 05:30:27 +0000] [1] [WARNING] Worker with pid 9 was terminated due to signal 9
app1 | [2022-01-13 05:30:27 +0000] [1] [WARNING] Worker with pid 11 was terminated due to signal 9
app1 | [2022-01-13 05:30:27 +0000] [12] [INFO] Booting worker with pid: 12
app1 | [2022-01-13 05:30:27 +0000] [1] [WARNING] Worker with pid 10 was terminated due to signal 9
app1 | [2022-01-13 05:30:27 +0000] [13] [INFO] Booting worker with pid: 13
app2 | [2022-01-13 05:30:27 +0000] [1] [CRITICAL] WORKER TIMEOUT (pid:9)
app2 | [2022-01-13 05:30:27 +0000] [1] [CRITICAL] WORKER TIMEOUT (pid:10)
app2 | [2022-01-13 05:30:27 +0000] [10] [INFO] Worker exiting (pid: 10)
app2 | [2022-01-13 05:30:27 +0000] [1] [CRITICAL] WORKER TIMEOUT (pid:11)
app2 | [2022-01-13 05:30:27 +0000] [9] [INFO] Worker exiting (pid: 9)
app1 | [2022-01-13 05:30:27 +0000] [14] [INFO] Booting worker with pid: 14
依此类推,适用于每个应用程序。
我试图将 proc_name = 'app'
更改为不同的值,但发生了同样的事情。这是我的 docker 撰写文件的片段,其中我 运行 Gunicorn 的命令:
m:
build:
dockerfile: ./m/Dockerfile
context: ../../
command: gunicorn --bind 0.0.0.0:82 --workers 3 ${M_FLASK_APP}:app
environment:
- FLASK_ENV=${FLASK_ENV}
- PYTHONUNBUFFERED=1
ports:
- 82:82
volumes:
- ./m/src:/opt/m
p:
build:
dockerfile: ./p/Dockerfile
context: ../../
command: gunicorn --bind 0.0.0.0:83 --workers 3 ${P_FLASK_APP}:app
environment:
- FLASK_ENV=${FLASK_ENV}
- PYTHONUNBUFFERED=1
ports:
- 83:83
volumes:
- ./p/src:/opt/p
有人可以指导我正确的方向吗?是 gunicorn 配置问题还是 docker(因为我 运行 有 6 个应用程序和 1 个 nginx 服务器)?
我通过升级我的 Compute Engine 实例解决了这个问题(我正在使用 Google 云)。以前我有 2 CPU 个内核和 4GB RAM,并将其更改为 4 CPU 个内核和 4GB RAM CPU 优化机器。现在我可以在同一个实例上托管 6 个以上的应用程序,但成本要高得多。显然,上述错误的原因是硬件限制。