您好,登錄后才能下訂單哦!
在高并發(fā)場景,需要啟動更多的Nginx進程以保證快速響應(yīng),以處理用戶的請求,避免造成阻塞。運行進程數(shù)多一些,響應(yīng)訪問請求時,Nginx就不會臨時啟動新的進程提供服務(wù),減少了系統(tǒng)的開銷,提升了服務(wù)速度,使用ps aux可以查看運行進程數(shù)的變化情況。
默認情況,Nginx的多個進程可能跑在一個CPU上, 可以分配不同的進程給不同的CPU處理,充分利用硬件多
核多CPU在一臺4核物理服務(wù)器可進行以下配置,將進程進行分配
Worker_cpu_affinity 0001 0010 0100 1000
[root@localhost nginx]# vim conf/nginx.conf
worker_processes 1; //進程數(shù)1
events {
worker_connections 1024; //一個進程處理的請求數(shù)
}
[root@localhost nginx]# ps aux | grep "nginx" //查看進程數(shù)
root 61991 0.0 0.0 20548 616 ? Ss 19:08 0:00 nginx: master process /usr/local/nginx/sbin/nginx
//主進程
nginx 61995 0.0 0.0 23076 1644 ? S 19:08 0:00 nginx: worker process //工作進程為1
root 62145 0.0 0.0 112728 968 pts/0 R+ 19:16 0:00 grep --color=auto nginx //ps命令的進程
[root@localhost nginx]#
[root@localhost ~]# cat /proc/cpuinfo
processor : 0
vendor_id : GenuineIntel
cpu family : 6
model : 158
model name : Intel(R) Core(TM) i7-9750H CPU @ 2.60GHz
stepping : 10
microcode : 0xaa
cpu MHz : 2591.568
........//省略部分內(nèi)容
processor : 1
vendor_id : GenuineIntel
cpu family : 6
model : 158
model name : Intel(R) Core(TM) i7-9750H CPU @ 2.60GHz
stepping : 10
microcode : 0xaa
cpu MHz : 2591.568
........//省略部分內(nèi)容
[root@localhost ~]# vim /usr/local/nginx/conf/nginx.conf
worker_processes 2; //進程數(shù)該為2
worker_cpu_affinity 01 10; //進程平均分配到兩個CPU上,01、10為二進制編號
events {
worker_connections 1024;
}
[root@localhost ~]# service nginx start //開啟服務(wù)
[root@localhost ~]# ps aux | grep "nginx"
root 2593 0.0 0.0 20548 612 ? Ss 13:57 0:00 nginx: master process /usr/local/nginx/sbin/nginx
nginx 2594 0.0 0.0 23076 1392 ? S 13:57 0:00 nginx: worker process //進程1
nginx 2595 0.0 0.0 23076 1376 ? S 13:57 0:00 nginx: worker process //進程2
root 2603 0.0 0.0 112728 968 pts/0 S+ 13:57 0:00 grep --color=auto nginx
[root@localhost ~]#
免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點不代表本網(wǎng)站立場,如果涉及侵權(quán)請聯(lián)系站長郵箱:is@yisu.com進行舉報,并提供相關(guān)證據(jù),一經(jīng)查實,將立刻刪除涉嫌侵權(quán)內(nèi)容。