Gunicorn 工人以信号 9 终止

Jod*_*iug 8 python flask gunicorn

我正在运行一个 Flask 应用程序,并将它从 Docker 容器托管在 Kubernetes 上。Gunicorn 正在管理回复 API 请求的工作人员。

以下警告消息是经常发生的,似乎由于某种原因请求被取消。在 Kubernetes 上,pod 没有表现出任何奇怪的行为或重新启动并保持在其内存和 CPU 限制的 80% 以内。

[2021-03-31 16:30:31 +0200] [1] [WARNING] Worker with pid 26 was terminated due to signal 9
Run Code Online (Sandbox Code Playgroud)

我们如何才能找出这些工人被杀害的原因?

小智 33

在我们的案例中,应用程序需要大约 5-7 分钟才能将 ML 模型和字典加载到内存中。所以添加 600 秒的超时时间就解决了我们的问题。

gunicorn main:app \
   --workers 1 \
   --worker-class uvicorn.workers.UvicornWorker \
   --bind 0.0.0.0:8443 \
   --timeout 600
Run Code Online (Sandbox Code Playgroud)


小智 10

I encountered the same warning message.

[WARNING] Worker with pid 71 was terminated due to signal 9
Run Code Online (Sandbox Code Playgroud)

I came across this faq, which says that "A common cause of SIGKILL is when OOM killer terminates a process due to low memory condition."

I used dmesg realized that indeed it was killed because it was running out of memory.

Out of memory: Killed process 776660 (gunicorn)
Run Code Online (Sandbox Code Playgroud)

  • 自从我们开始使用“--worker-class gevent”以来,我们的问题似乎已经消失了。我无法验证这个答案,但似乎“dmesg”是获取更多信息和诊断问题的好方法。感谢您的回答! (2认同)