标签:cee read list cache grep 多个 div apr zomb
1,worker_processes应设置为多少?
worker_processes 4;
如何设置这个值:
worker_processes默认值是1,一般要设置为cpu的核心数量或核心数量x2
注意:是核心的数量,不是cpu的数量,一颗cpu可能有多个核心
2,如何查看核心的数量:用lscpu命令
[root@blog conf]$ lscpu Architecture: x86_64 CPU op-mode(s): 32-bit, 64-bit Byte Order: Little Endian CPU(s): 4 On-line CPU(s) list: 0-3 Thread(s) per core: 2 Core(s) per socket: 2 ...
CPU(s): 一栏标明是4个core
3,如何查看核心的数量:执行top命令查看
执行top命令后,按1打开cpu的核心列表
[root@blog conf]$ top top - 18:45:32 up 105 days, 8:41, 3 users, load average: 0.00, 0.00, 0.00 Tasks: 153 total, 1 running, 145 sleeping, 7 stopped, 0 zombie %Cpu0 : 0.0 us, 0.0 sy, 0.0 ni,100.0 id, 0.0 wa, 0.0 hi, 0.0 si, 0.0 st %Cpu1 : 0.0 us, 0.0 sy, 0.0 ni,100.0 id, 0.0 wa, 0.0 hi, 0.0 si, 0.0 st %Cpu2 : 0.0 us, 0.0 sy, 0.0 ni,100.0 id, 0.0 wa, 0.0 hi, 0.0 si, 0.0 st %Cpu3 : 0.0 us, 0.0 sy, 0.0 ni,100.0 id, 0.0 wa, 0.0 hi, 0.0 si, 0.0 st MiB Mem : 15355.3 total, 838.1 free, 1154.0 used, 13363.1 buff/cache MiB Swap: 0.0 total, 0.0 free, 0.0 used. 13873.0 avail Mem
...
4,配置worker_processes后的效果
应该有四个worker进程:
我们用ps命令查看:
[root@blog ~]# ps auxfww | grep nginx root 29616 0.0 0.0 50412 3292 ? Ss Apr24 0:00 nginx: master process /usr/local/openresty/nginx/sbin/nginx nginx 29617 0.0 0.0 81896 5968 ? S Apr24 0:00 \_ nginx: worker process nginx 29618 0.0 0.0 81896 5996 ? S Apr24 0:00 \_ nginx: worker process nginx 29619 0.0 0.0 81896 5968 ? S Apr24 0:00 \_ nginx: worker process nginx 29620 0.0 0.0 81896 7164 ? S Apr24 0:00 \_ nginx: worker process
说明:可以看到有4个worker process
5, master process与worker process不同,
master process负责绑定端口、调度进程等,不负责业务的处理
而worker process是业务进程,负责业务的处理
1, worker_connections的作用?
worker_connections 20480
worker_connections是每个worker进程允许的最多连接数,
每台nginx 服务器的最大连接数为:worker_processes*worker_connections
例子:
events { worker_connections 16383; }
2,如何设置worker_connections的值?
系统的最大打开文件数>= worker_connections*worker_process
3,如何查看系统的最大打开文件数:
[root@blog ~]# ulimit -n 65535
如果worker_process = 4,
则 worker_connections应该小于等于16383
考虑到进程间分配不平衡,可以设置到 20480
说明:ulimit -n给出的系统的用户最大打开文件数可以调整,
参见这一篇:
https://www.cnblogs.com/architectforest/p/12794818.html
worker_rlimit_nofile 65535;
这个指令是指一个nginx worker进程打开的最多文件描述符数目,
理论值应该是最多打开文件数(ulimit -n)与nginx进程数相除,
因为nginx分配请求未必很均匀,所以最好与ulimit -n的值保持一致
说明:
如果worker_rlimit_nofile的值小于worker_connections的值,会报如下错误:
worker_connections exceed open file resource limit: xxx
例子:
2020/04/26 14:04:40 [warn] 1402#1402: 2048 worker_connections exceed open file resource limit: 1024
[root@blog ~]# /usr/local/openresty/nginx/sbin/nginx -v nginx version: openresty/1.15.8.2
nginx优化:worker_processes/worker_connections/worker_rlimit_nofile
标签:cee read list cache grep 多个 div apr zomb
原文地址:https://www.cnblogs.com/architectforest/p/12795040.html