重启时 uWSGI 停机时间
uWSGI downtime when restart
每当我有代码更新时重新启动服务器时,uwsgi 都会出现问题。
当我使用 "sudo restart accounting" 重新启动 uwsgi 时,停止和启动实例之间存在一个小间隙,导致停机并停止所有当前请求。
当我尝试 "sudo reload accounting" 时,它有效,但我的内存增加了(双倍)。当我 运行 命令 "ps aux | grep accounting" 时,它显示我有 10 个 运行ning 进程(accounting.ini)而不是 5 个,当内存达到极限时它冻结了我的服务器.
accounting.ini
我是运行宁
- Ubuntu 14.04
- Django 1.9
- nginx 1.4.6
- uwsgi 2.0.12
这就是 uwsgi 进行优雅重新加载的方式。在处理请求之前保留旧流程,并创建新流程来接管传入请求。
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 正在以下述方式重新启动:
- 发送
SIGHUP
信号给master
- 等待 运行 个工作人员。
- 关闭除映射到套接字的文件描述符之外的所有文件描述符。
- 对自身调用 exec()。
这种重新加载的缺点之一可能是卡住工人。
此外,您报告当 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
链上重载和其他类型的一些资源在下面的链接中:
每当我有代码更新时重新启动服务器时,uwsgi 都会出现问题。
当我使用 "sudo restart accounting" 重新启动 uwsgi 时,停止和启动实例之间存在一个小间隙,导致停机并停止所有当前请求。
当我尝试 "sudo reload accounting" 时,它有效,但我的内存增加了(双倍)。当我 运行 命令 "ps aux | grep accounting" 时,它显示我有 10 个 运行ning 进程(accounting.ini)而不是 5 个,当内存达到极限时它冻结了我的服务器.
accounting.ini
我是运行宁
- Ubuntu 14.04
- Django 1.9
- nginx 1.4.6
- uwsgi 2.0.12
这就是 uwsgi 进行优雅重新加载的方式。在处理请求之前保留旧流程,并创建新流程来接管传入请求。
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 正在以下述方式重新启动:
- 发送
SIGHUP
信号给master - 等待 运行 个工作人员。
- 关闭除映射到套接字的文件描述符之外的所有文件描述符。
- 对自身调用 exec()。
这种重新加载的缺点之一可能是卡住工人。 此外,您报告当 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
链上重载和其他类型的一些资源在下面的链接中: