uWSGI 在达到生命周期时重置 worker 导致停机

uWSGI resets worker on lifetime reached causes downtime

我有 uWSGI 运行 Django。我将我的 uWSGI worker 配置为具有 max-worker-lifetime=3600.

我看到的是,每 3600 秒,两个 uWSGI worker 一起终止,这会导致大约 10-15 秒的停机时间,所有服务器都失败,远程服务器返回 502。

这些是日志:

Everything normal

00:00:00 worker 1 lifetime reached, it was running for 3601 second(s)
00:00:00 worker 2 lifetime reached, it was running for 3601 second(s)

00:00:01 HTTP 502 (on the remote server)
00:00:01 HTTP 502 (on the remote server)
...
00:00:11 HTTP 502 (on the remote server)
00:00:11 HTTP 502 (on the remote server)

00:00:11 Respawned uWSGI worker 1 (new pid: 66)
00:00:11 Respawned uWSGI worker 2 (new pid: 67)

Everything goes back to normal

我不确定为什么会有这种行为。

这是使用的配置(仅相关部分):

    UWSGI_MASTER=true \
    UWSGI_WORKERS=2 \
    UWSGI_THREADS=8 \
    UWSGI_LISTEN=250 \
    UWSGI_LAZY_APPS=true \
    UWSGI_WSGI_ENV_BEHAVIOR=holy \
    UWSGI_MAX_WORKER_LIFETIME=3600 \
    UWSGI_RELOAD_ON_RSS=1024 \
    UWSGI_SINGLE_INTERPRETER=true \
    UWSGI_VACUUM=true

您应该使用最近通过社区贡献添加的参数max-worker-lifetime-delta

https://github.com/unbit/uwsgi/issues/2020

https://github.com/unbit/uwsgi/pull/2021

这将确保您的 worker 不会在如此接近的情况下重新启动。此外,由于您的 worker 加载时间很长,因此要有足够的 worker,以便 worker 重启不会产生很大影响。

您还使用了一个看起来很低的工作超时,您也应该尝试一下并将其增加到您认为更好的值