[PATCH 2 of 2] add support for setting worker processes and CPU affinity automatically
Valentin V. Bartenev
ne at vbart.ru
Thu Jan 12 17:53:56 UTC 2012
On Thursday 12 January 2012 19:37:15 Joshua Zhu wrote:
> It's a little bit inconvenient to set the CPU affinities with
> many-core-system. For example, to fully utilize a 16-core Linux box, we
> have to write something like this:
> worker_processes 16;
> worker_cpu_affinity 1000000000000000 0100000000000000 0010000000000000
> 0001000000000000 0000100000000000 0000010000000000 0000001000000000
> 0000000100000000 0000000010000000 0000000001000000 0000000000100000
> 0000000000010000 0000000000001000 0000000000000100 0000000000000010
> 0000000000000001;
>
> This patch will make life much easier:
> worker_processes auto;
> worker_cpu_affinity auto;
>
> Please see the attachment for more detail.
>
You use "ngx_ncpu" global variable and for Linux you set it by
sysconf(_SC_NPROCESSORS_ONLN).
On freeBSD and MacOS systems it set by sysctls(hw.ncpu), and it is equal
to 1 on others.
Which means that your "auto" settings are very inaccurate. Sometimes the
"worker_processes" directive will be equal to 2 * cores or more, sometimes
it will be equal to 1, and if you're lucky, then it will be equal to real
CPU cores.
So, I don't think that this patch makes life easier. In fact, it creates a
false sense of optimal worker_processes setting. Even if ngx_ncpu would be
always equal to real hardware cores number, it wouldn't be optimal for every
use cases.
wbr, Valentin V. Bartenev
More information about the nginx
mailing list