gpt4 book ai didi

django - 重启时 uWSGI 停机时间

转载 作者:行者123 更新时间:2023-12-02 17:16:11 24 4
gpt4 key购买 nike

每当我有代码更新时重新启动服务器时,我都会遇到 uwsgi 问题。

  1. 当我使用“sudo restart accounting”重新启动 uwsgi 时,停止和启动实例之间存在一个小间隙,这会导致停机并停止所有当前请求。

  2. 当我尝试“sudo reload accounting”时,它起作用了,但我的内存增加了(双倍)。当我运行命令“ps aux | grep accounting”时,它显示我有 10 个正在运行的进程 (accounting.ini) 而不是 5 个,当内存达到极限时它会卡住我的服务器。

accounting.ini

enter image description here

我在运行

  • Ubuntu 14.04
  • Django 1.9
  • nginx 1.4.6
  • uwsgi 2.0.12

最佳答案

这就是 uwsgi 进行优雅重新加载的方式。在处理请求之前保留旧流程,并创建新流程来接管传入请求。

阅读Things that could go wrong

Do not forget, your workers/threads that are still running requests could block the reload (for various reasons) for more seconds than your proxy server could tolerate.

还有这个

Another important step of graceful reload is to avoid destroying workers/threads that are still managing requests. Obviously requests could be stuck, so you should have a timeout for running workers (in uWSGI it is called the “worker’s mercy” and it has a default value of 60 seconds).

所以我建议尝试 worker-reload-mercy

默认值是等待 60 秒,只需将其降低到您的服务器可以处理的时间即可。

告诉我它是否有效。


Uwsgi链重载

这是解决您的问题的另一种尝试。正如您提到的,您的 uwsgi worker 正在以下述方式重新启动:

  1. 发送SIGHUP信号给master
  2. 等待正在运行的 worker。
  3. 关闭除映射到套接字的文件描述符之外的所有文件描述符。
  4. 自行调用 exec()。

这种重新加载的缺点之一可能是 workers 卡住。此外,您报告当 uwsgi 维护 10 个进程(5 个旧进程和 5 个新进程)时您的服务器崩溃。

我建议尝试链重新加载。文档中的直接引用解释了这种重新加载:

When triggered, it will restart one worker at time, and the following worker is not reloaded until the previous one is ready to accept new requests.

这意味着您的服务器上不会有 10 个进程,而只有 5 个。

应该工作的配置:

# your .ini file
lazy-apps = true
touch-chain-reload = /path/to/reloadFile

部分链上reload等资源链接如下:

Chain reloading uwsgi docs

uWSGI graceful Python code deploy

关于django - 重启时 uWSGI 停机时间,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46147864/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com