配置文件中的worker_cpu_affinity可以用来绑定每个nginx进程所使用的CPU
官方的解释是:
#----------------------------引用文字-开始----------------------------
Syntax: worker_cpu_affinity cpumask [cpumask...]
Default: none
Linux only.
With this option you can bind the worker process to a CPU, it calls sched_setaffinity().
For example,
worker_processes 4;
worker_cpu_affinity 0001 0010 0100 1000;
Bind each worker process to one CPU only.
worker_processes 2;
worker_cpu_affinity 0101 1010;
Bind the first worker to CPU0/CPU2, bind the second worker to CPU1/CPU3. This is suitable for HTT.
#----------------------------引用文字-结束----------------------------
最关键的地方没说清楚,怎样来表示每个CPU?
经过漫天的搜索和多次尝试发现
那么,16核的cpu每个进程分配到一个cpu就应该是
测试一下,用别的服务器发出大量请求
ab -n 20000 -k http://您的ip或域名/index.php
在被测试的服务器上查看cpu状态
top
然后按1
可以看到每个cpu都在工作了