By Default, without setting worker_cpu_affinity directive in nginx.conf, linux kernel will spread all nginx’s worker all over CPUs.
I have 4 logical CPUs on my server, which is CPU0 – CPU3
1 | Cpu0 : 2.9%us, 0.9%sy, 0.0%ni, 88.9%id, 7.2%wa, 0.0%hi, 0.2%si, 0.0%st |
2 | Cpu1 : 1.8%us, 0.6%sy, 0.0%ni, 95.3%id, 2.2%wa, 0.0%hi, 0.1%si, 0.0%st |
3 | Cpu2 : 2.4%us, 0.7%sy, 0.0%ni, 94.3%id, 2.5%wa, 0.0%hi, 0.1%si, 0.0%st |
4 | Cpu3 : 1.9%us, 0.7%sy, 0.0%ni, 96.7%id, 0.6%wa, 0.0%hi, 0.0%si, 0.0%st |
Using default setting, nginx’s worker always bind to those 4 logical CPUs. which is has “f” bitmask
2 | pid 25748's current affinity mask: f |
4 | pid 25749's current affinity mask: f |
6 | pid 25751's current affinity mask: f |
8 | pid 25752's current affinity mask: f |
10 | pid 25753's current affinity mask: f |
CPU affinity is represented as a bitmask (given in hexadecimal), with the lowest order bit corresponding to the first logical CPU and the highest order bit corresponding to the last logical CPU.
Examples: