[PATCH 2 of 2] add support for setting worker processes and CPU affinity automatically

Joshua Zhu zhuzhaoyuan at gmail.com
Fri Jan 13 10:04:11 UTC 2012


Hi,

On Fri, Jan 13, 2012 at 1:53 AM, Valentin V. Bartenev <ne at vbart.ru> wrote:

> On Thursday 12 January 2012 19:37:15 Joshua Zhu wrote:
>

[snip]

Thank you very much for the review.

 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.
>

Setting CPU affinity is available on Linux systems only. Please correct me
if I'm wrong.


> 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.
>

This is mostly caused by the hyper-threading feature of some CPUs. I don't
think this is an issue if hyper-threading is turned on. Sure we need to
find a better way to detect the number of CPUs on a system.


> 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.
>

It's not 'optimal', but 'automatic'. This patch still supports setting
worker processes and CPU affinities mannually as what the standard Nginx
does ;)

Regards,

-- 
Joshua Zhu
Senior Software Engineer
Server Platforms Team at Taobao
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mailman.nginx.org/pipermail/nginx/attachments/20120113/ad96f235/attachment-0001.html>


More information about the nginx mailing list