lnmp 多核cpu服务器/云服务器nginx.conf配置优化,worker_processes和worker_cpu_affinity参数如何设置?

worker_processes和worker_cpu_affinity参数如何设置?

首先使用以下命令查看自己cpu的核心数

1
lscpu

或使用命令

1
grep 'model name' /proc/cpuinfo |wc -l

示例
Architecture: x86_64
CPU op-mode(s): 32-bit, 64-bit
Byte Order: Little Endian
Address sizes: 48 bits physical, 48 bits virtual
CPU(s): 2
On-line CPU(s) list: 0,1
Thread(s) per core: 1
Core(s) per socket: 2
Socket(s): 1
NUMA node(s): 1
Vendor ID: AuthenticAMD
CPU family: 23
Model: 1
Model name: AMD EPYC Processor
Stepping: 2
CPU MHz: 1999.996
BogoMIPS: 3999.99
Hypervisor vendor: KVM
Virtualization type: full
L1d cache: 128 KiB
L1i cache: 128 KiB
L2 cache: 1 MiB
NUMA node0 CPU(s): 0,1
Vulnerability Itlb multihit: Not affected
Vulnerability L1tf: Not affected
Vulnerability Mds: Not affected
Vulnerability Meltdown: Not affected
Vulnerability Spec store bypass: Vulnerable
Vulnerability Spectre v1: Mitigation; usercopy/swapgs barriers and __user pointer sanitization
Vulnerability Spectre v2: Mitigation; Full AMD retpoline, STIBP disabled, RSB filling
Vulnerability Srbds: Not affected
Vulnerability Tsx async abort: Not affected
Flags: fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 clflush mmx fxsr sse sse2 ht syscall nx mmxext fxsr_o
pt pdpe1gb rdtscp lm rep_good nopl cpuid extd_apicid tsc_known_freq pni pclmulqdq ssse3 fma cx16 sse4_1 sse4_2 x2apic movbe p
opcnt aes xsave avx f16c rdrand hypervisor lahf_lm cmp_legacy cr8_legacy abm sse4a misalignsse 3dnowprefetch osvw vmmcall fsg
sbase bmi1 avx2 smep bmi2 rdseed adx smap clflushopt sha_ni xsaveopt xsavec xgetbv1 arat

其中CPU(s):2即为两个核心

lnmp默认安装后的nginx.conf配置文件中,一般针对多核心设置的是auto,如下

1
2
worker_processes auto;
worker_cpu_affinity auto;

针对多核心可以自己手动设置,修改配置文件以上两个参数

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
#2核cpu,开启2个进程
worker_processes     2;
worker_cpu_affinity 01 10;

#2核cpu,开启4个进程,
worker_processes     4;
worker_cpu_affinity 01 10 01 10;

#4核cpu,开启2个进程,0101表示开启第一个和第三个内核,1010表示开启第二个和第四个内核;
worker_processes     2;
worker_cpu_affinity 0101 1010;

#4个cpu,开启4个进程
worker_processes     4;
worker_cpu_affinity 0001 0010 0100 1000;

#8核cpu,开启8个进程
worker_processes     8;
worker_cpu_affinity 00000001 00000010 00000100 00001000 00010000 00100000 01000000 10000000;

#16核cpu,开启16个进程
worker_processes 16;
worker_cpu_affinity 0000000000000001 0000000000000010 0000000000000100 0000000000001000 0000000000010000 0000000000100000 0000000001000000 0000000010000000 0000000100000000 0000001000000000
 0000010000000000 0000100000000000 0001000000000000 0010000000000000 0100000000000000 1000000000000000;
原文链接:https://xiaohost.com/3696.html,转载请注明出处。
0

评论0

请先