Worker进程 处理请求, Master进程管理Worker进程。
多进程模式避免了多线程共享同一个地址空间,某一个模块引发了段错误时,在地址越界出现时,会导致整个Nginx不可用。 因此Nginx采用多进程,在设计上保证了高可用。
建议Worker进程数量 = CPU核数。 Nginx 期望一个worker进程使用一颗cpu, 把某个worker进程和某个cpu绑定在一起,可以更好地使用cpu上的缓存,来减少缓存失效的命中率。
[root@VM-0-7-centos artisan_ng]# cat /root/ng/artisan_ng/conf/nginx.conf |grep worker_processes
worker_processes 2;
[root@VM-0-7-centos artisan_ng]#
这里我们设置的 worker_processes 为 2
[root@VM-0-7-centos artisan_ng]# ./sbin/nginx -c ./conf/nginx.conf
[root@VM-0-7-centos artisan_ng]#
[root@VM-0-7-centos artisan_ng]# ps -ef|grep nginx |grep -v grep
root 994792 1 0 23:10 ? 00:00:00 nginx: master process ./sbin/nginx -c ./conf/nginx.conf
root 994793 994792 0 23:10 ? 00:00:00 nginx: worker process
root 994794 994792 0 23:10 ? 00:00:00 nginx: worker process
root 994795 994792 0 23:10 ? 00:00:00 nginx: cache manager process
root 994796 994792 0 23:10 ? 00:00:00 nginx: cache loader process
[root@VM-0-7-centos artisan_ng]#
可以看到worker process 有2个 。
其中master的pid 为 994792 , 两个worker进程是由master进程启动的, 其中 pid 分别为 994793 和 994794
信号说明: 重识Nginx - 05 热部署_不停机更换新版本的nginx & nginx信号说明
[root@VM-0-7-centos ~]# ps -ef|grep nginx
root 994792 1 0 23:10 ? 00:00:00 nginx: master process ./sbin/nginx -c ./conf/nginx.conf
root 994793 994792 0 23:10 ? 00:00:00 nginx: worker process
root 994794 994792 0 23:10 ? 00:00:00 nginx: worker process
root 994795 994792 0 23:10 ? 00:00:00 nginx: cache manager process
root 996157 996087 0 23:19 pts/5 00:00:00 grep --color=auto nginx
[root@VM-0-7-centos ~]#
[root@VM-0-7-centos ~]#
[root@VM-0-7-centos ~]# cd /root/ng/artisan_ng
[root@VM-0-7-centos artisan_ng]# ./sbin/nginx -s reload
[root@VM-0-7-centos artisan_ng]# ps -ef|grep nginx |grep -v grep
root 994792 1 0 23:10 ? 00:00:00 nginx: master process ./sbin/nginx -c ./conf/nginx.conf
root 996231 994792 0 23:20 ? 00:00:00 nginx: worker process
root 996232 994792 0 23:20 ? 00:00:00 nginx: worker process
root 996233 994792 0 23:20 ? 00:00:00 nginx: cache manager process
[root@VM-0-7-centos artisan_ng]#
[root@VM-0-7-centos artisan_ng]#
ng reload不会中断业务的使用, 新旧worker同时并存,其中旧worker仍然是原进程,它通过epoll_ctl将监听socket从epoll中移出,之前正在处理的TCP连接不受影响,当处理完(对于http请求,就是发完response,其他协议与语义相关)后旧worker正常退出。因此新建立的TCP连接就会由新worker处理。
重载配置文件
[root@VM-0-7-centos ~]# ps -ef|grep nginx |grep -v grep
root 994792 1 0 23:10 ? 00:00:00 nginx: master process ./sbin/nginx -c ./conf/nginx.conf
root 996231 994792 0 23:20 ? 00:00:00 nginx: worker process
root 996232 994792 0 23:20 ? 00:00:00 nginx: worker process
root 996233 994792 0 23:20 ? 00:00:00 nginx: cache manager process
[root@VM-0-7-centos ~]#
[root@VM-0-7-centos ~]#
[root@VM-0-7-centos ~]# kill -SIGHUP 994792
[root@VM-0-7-centos ~]#
[root@VM-0-7-centos ~]# ps -ef|grep nginx |grep -v grep
root 994792 1 0 23:10 ? 00:00:00 nginx: master process ./sbin/nginx -c ./conf/nginx.conf
root 997941 994792 0 23:32 ? 00:00:00 nginx: worker process
root 997942 994792 0 23:32 ? 00:00:00 nginx: worker process
root 997943 994792 0 23:32 ? 00:00:00 nginx: cache manager process
[root@VM-0-7-centos ~]#
要求Nginx立刻关闭服务
[root@VM-0-7-centos ~]# ps -ef|grep nginx |grep -v grep
root 994792 1 0 23:10 ? 00:00:00 nginx: master process ./sbin/nginx -c ./conf/nginx.conf
root 997941 994792 0 23:32 ? 00:00:00 nginx: worker process
root 997942 994792 0 23:32 ? 00:00:00 nginx: worker process
root 997943 994792 0 23:32 ? 00:00:00 nginx: cache manager process
[root@VM-0-7-centos ~]# ^C
[root@VM-0-7-centos ~]#
[root@VM-0-7-centos ~]#
[root@VM-0-7-centos ~]#
[root@VM-0-7-centos ~]#
[root@VM-0-7-centos ~]#
[root@VM-0-7-centos ~]# kill -SIGTERM 997942
[root@VM-0-7-centos ~]#
[root@VM-0-7-centos ~]#
[root@VM-0-7-centos ~]# ps -ef|grep nginx |grep -v grep
root 994792 1 0 23:10 ? 00:00:00 nginx: master process ./sbin/nginx -c ./conf/nginx.conf
root 997941 994792 0 23:32 ? 00:00:00 nginx: worker process
root 997943 994792 0 23:32 ? 00:00:00 nginx: cache manager process
root 998267 994792 0 23:34 ? 00:00:00 nginx: worker process
[root@VM-0-7-centos ~]#
kill -SIGTERM关闭worker进程后,会重新起一个worker进程. 该命令是worker提供给master的,通常管理员只需要操作master进程就可以,如果一定要操作worker进程,那么一定是可以确认某一个worker进程出问题了,且信号对应的功能可以解决该问题
master是worker进程的父进程,在Linux中,子进程退出时,会向父进程发送信号SIGCHLD,所以master进程可以感知到,这才能重新fork拉起新的worker子进程
文章浏览阅读8.4k次。前面写了篇入坑指南,介绍了下开发微信公众号的基本流程。最近又捣鼓了一阵,发现这开发工具的选择对于提高开发效率真是有莫大的帮助,所谓“只要工具选得好,月底奖金跑不了”。今天得空,笔者就给各位老哥列举几个绝对能派上用场的小工具,保证没毛病!微信公众平台技术文档这货实际上是必需品,没了它,您还真是寸步难行。官方文档包含了一个产品最直接也最全面的说明,在微信公众平台技术文档中,详细说明了微信公众号开发的概念_微信公众号开发工具
文章浏览阅读612次。获得硬盘的序列号(ID/机器码)的C++源码_硬盘id获取 c++
文章浏览阅读1w次,点赞5次,收藏60次。1.VRRP的工作原理2.Master路由器和Backup路由器3.VRRP报文格式4.虚拟路由器中的虚拟IP地址和虚拟MAC 地址_vrrp是什么协议
文章浏览阅读2.9k次,点赞2次,收藏15次。 本文主要对GEE中的栅格代数与波段计算操作加以介绍。本文是谷歌地球引擎(Google Earth Engine,GEE)系列教学文章的第六篇,更多GEE文章请参考专栏:GEE学习与应用(https://blog.csdn.net/zhebushibiaoshifu/category_11081040.html)。 首先,依据第二篇GEE教学博客(https://blog.csdn.net/zhebushibiaoshifu/article/details/117296956)中内容,我们将Lands_gee波段计算
文章浏览阅读1.3k次,点赞33次,收藏36次。组件化编码流程: (1).拆分静态组件:组件要按照功能点拆分,命名不要与html元素冲突。 (2).实现动态组件:考虑好数据的存放位置,数据是一个组件在用,还是一些组件在用: 1).一个组件在用:放在组件自身即可。放在他们共同的父组件上(状态提升)。 (3).实现交互:从绑定事件开始。props适用于: (1).父组件 ==> 子组件 通信 (2).子组件 ==> 父组件 通信(要求父先给子一个函数)_vue2对应的脚手架版本
文章浏览阅读1.5k次。大数据可视化设计师丹尼斯 重点 (Top highlight)I hit a point in my life where I could take my career in countless directions. I left my job in the summer of 2019 and began my venture as a freelancer. I work part-time..._hit a point
文章浏览阅读152次。在如今的时代,运维不学Python,迟早会被淘汰!如果你想要专业的学习Python开发技术,更多需要的是付出时间和精力,应该根据自己的实际需求去实地看一下,下面总结了50到面试试题参考,希望能给你带来帮助。1. 2017 校招真题这部分包含了 37 道 2017 年的校招真题。每个题目都配备相应的 Python 实现。例如我们来看一个有趣的例子:餐厅.py2. 剑指 offer这部分共包含了 68 道剑指真题。请看示例:变态青蛙跳.py3. 华为机试..._python面试bat
文章浏览阅读1k次。题目描述竞赛在排名时,一般是按做题数排名,但当做题数相同时,则按做各题所花总时间进行排名。下面编程实现时间的汇总。输入先输入一个n(1<=n<=10),表示总共做出了n题。然后输入n个做出各题所花的时间,格式为HH:MM:SS,其中,HH表示时(00<=HH<10),MM表示分(00<=MM<=59),SS表示秒(00<=SS<=59)。输出输出将..._竞赛在排名时,一般是按做题数排名,但当做题数相同时,则按做各题所花总时间进行排
文章浏览阅读1.7k次。Linux 启动时profile、bashrc、~/.bash_profile、~/.bashrc、~/.bash_profile执行顺序以及文件说明一、执行顺序登录linux时,/etc/profile、~/.bash_profile等几个文件的执行过程。如图所示:二、在登录Linux时要执行文件的过程如下:在刚登录Linux时,首先启动 /etc/profile 文件,然后再启动用户目录下的 ..._怎么运行profile文件
文章浏览阅读1.1w次,点赞7次,收藏16次。正则表达式中,group()用来提出分组截获的字符串,()用来分组import rea = "123abc456"print re.search("([0-9]*)([a-z]*)([0-9]*)",a).group(0) #123abc456,返回整体print re.search("([0-9]*)([a-z]*)([0-9]*)",a).group(1)
文章浏览阅读174次。在编写 jQuery 代码时,有时候会遇到使用双引号的情况,但双引号在 jQuery 中有特殊的含义。如果你使用的是 ES6 或更高版本的 JavaScript,你可以使用模板字符串来解决这个问题。这些是解决 jQuery 中使用双引号的常见方法。无论你选择哪种方法,都能解决在 HTML 方法中使用双引号的问题,并使你的代码能够正常工作。在上面的示例中,我们在双引号前添加了一个反斜杠,这样 jQuery 就能正确解析字符串。在上面的示例中,我们使用模板字符串来定义包含双引号的 HTML 字符串。_jquery 给元素赋值带双引号
文章浏览阅读9.7k次,点赞48次,收藏124次。HTTP是超文本传输协议(Hypertext Transfer Protocol)的缩写,是一种用于传输数据的协议。它是基于TCP/IP协议的应用层协议,通常用于Web浏览器和Web服务器之间的通信。HTTP协议的主要特点是简单、灵活、易于扩展和支持多媒体等不同类型的数据传输。_http传输流程