nginx

【nginx】nginx: worker process is

2022-05-26  本文已影响0人  Bogon

nginx -s reload之后, nginx 正在平滑的重启。

image.png

wroker有正在处理的连接,等处理结束,该worker就会退出(退出之前,该worker不会处理新的连接)。

等调用对应nginx 的进程结束之后,这个process就会重启了。

大约20分钟后,这些进程都变成了 'worker process' 了。

使用nginx作为前端代理,在reload nginx的时候,发现nginx会一直处于shutting状态,当reload nginx次数多了以后,cup会飙升到100%, gateway的状态也会处于busy状态。

现象如下:

image.png

跟踪socket连接发现,此 nginx 进程,一直保持跟gateway的连接。
当nginx reload的次数多的时候,gateway就会处于busy状态。

如果把gateway restart了,gateway的进程id会改变,nginx中的shutting down 状态的进程也会消失,但是gateway restart就断掉和客户端的连接了。

看起来nginx reload后不会断开连接,然后gateway reload也不会断开连接(gateway restart会断开连接),
然后二者仍然保持着连接。

nginx和gateway都reload,那么nginx会产生新的worker进程,但是应该shutdown的老进程因为和gateway还有连接,所以也不会销毁,这样时间长了会有很多处于shutting状态的进程,这些进程都会占用资源。

重启的话就会把客户端的连接断开重连,会把连接初始化时给客户端发送的消息重新发一遍。

nginx worker shutting down状态超时退出配置

nginx reload之后有时会遇到shutting down状态worker过多的现象,尤其是websocket连接的worker很长时间无法退出。

如何解决过多worker长时间处于shutting down状态,不退出问题呢?

image.png image.png

使用worker_shutdown_timeout配置,该配置配置在MAIN_CONF中,配置参数为时间。

如配置为1h,shutting down状态的worker一小时之后自动退出。

worker_shutdown_timeout 1h;
image.png
image.png

参考

谈谈 nginx 信号集
http://io.upyun.com/2017/08/19/nginx-signals

nginx: worker process is shutting down
https://www.cnblogs.com/felixzh/p/8670770.html
http://siwei.me/blog/posts/nginx-worker-is-shutting-down

worker_shutdown_timeout
https://nginx.org/en/docs/ngx_core_module.html#worker_shutdown_timeout

是什么让你的 nginx 服务退出这么慢?
https://zhuanlan.zhihu.com/p/34792840

从websocket服务的nginx配置说起
https://echizen.github.io/tech/2018/10-21-nginx-websocket

我眼里的 nginx
https://www.zhihu.com/column/nginxio

如何优雅地关闭worker进程?
https://blog.csdn.net/qq_27276045/article/details/103645876
https://blog.csdn.net/error311/article/details/104712237
https://cloud.tencent.com/developer/article/1558426

一次百万长连接压测Nginx内存溢出问题
https://www.51cto.com/article/612789.html

DevOps nginx: worker process is shutting down 原因解析
https://www.dazhuanlan.com/freelock/topics/1500064

nginx处理websocket连接
https://blog.csdn.net/weixin_43931358/article/details/111039750

NGINX as a WebSocket Proxy
https://www.nginx.com/blog/websocket-nginx

Nginx does not shut down when websocket connections are still open
https://github.com/phusion/passenger/issues/2211

nginx的graceful shutdown和worker shutdown timeout
https://cloud.tencent.com/developer/article/1162090

worker_shutdown_timeout 指令
https://www.hxstrive.com/subject/nginx.htm?id=785&p=757

关于k8s下使用Ingress保持长连接的异常情况排查
https://blog.jobshen.com/posts/eee2bd13.html

nginx热加载时已建立的websocket连接是否中断?
https://mp.weixin.qq.com/s/Nn44qLLQmJnzH-JLu_I-VA

Nginx reload了,连接怎么办?
https://mp.weixin.qq.com/s/i7DBCKF-ZouBihFEZKB6YQ

worker_shutdown_timeout" directive did not work websocket
https://github.com/Miss-you/apisix-book/issues/57

worker_shutdown_timeout(seconds) - Set the timeout for worker shutdown
https://docs.contrastsecurity.com/en/configure-with-puma.html

上一篇下一篇

猜你喜欢

热点阅读