Ruby Forum NGINX > Worker cpu affinity for 8 cores/cpus

Posted by Robert Gabriel (jinx)
on 05.09.2008 08:49
Hey, as everyone knows, if you have 1-2-4 cpus/cores, you can set the
worker_cpu_affinity.

For 2 cores/cpus is like this: worker_cpu_affinity 0101 1010;
For 4 cores/cpus is like this: worker_cpu_affinity 1000 0100 0010 0001;


But how about 8 cores/cpus?

Please let me know.
Posted by Robert Gabriel (jinx)
on 05.09.2008 08:50
Sorry for 4 cores/cpus is wrong from my side :)

But anyway how about 8 cores.
Posted by Igor Sysoev (Guest)
on 05.09.2008 09:07
(Received via mailing list)
On Fri, Sep 05, 2008 at 08:49:49AM +0200, Robert Gabriel wrote:

> Hey, as everyone knows, if you have 1-2-4 cpus/cores, you can set the
> worker_cpu_affinity.
> 
> For 2 cores/cpus is like this: worker_cpu_affinity 0101 1010;
> For 4 cores/cpus is like this: worker_cpu_affinity 1000 0100 0010 0001;
> 
> But how about 8 cores/cpus?

worker_cpu_affinity 1st_worker_mask 2nd_worker_mask ... ;

therefore

worker_cpu_affinity  00001111  11110000;

will run first worker on 0-3 CPUS and second worker on 4-7 CPUS.

However, please note that worker_cpu_affinity is currently broken and
it may not work correctly. Recently CPU affinity had appeared in
FreeBSD 7, so I will probably fix it to see how it may affect on 
perfomance.
Posted by Robert Gabriel (jinx)
on 05.09.2008 09:14
So work_cpu_affinity doesnt work on linux and nginx version 0.6.32?

P.S. what about the other post with the helpdesk stuff and the logs?! :)
Posted by mike (Guest)
on 05.09.2008 09:21
(Received via mailing list)
On Thu, Sep 4, 2008 at 11:58 PM, Igor Sysoev <is@rambler-co.ru> wrote:

> However, please note that worker_cpu_affinity is currently broken and
> it may not work correctly. Recently CPU affinity had appeared in
> FreeBSD 7, so I will probably fix it to see how it may affect on perfomance.

does it work in linux?
Posted by Igor Sysoev (Guest)
on 05.09.2008 09:37
(Received via mailing list)
On Fri, Sep 05, 2008 at 12:14:04AM -0700, mike wrote:

> On Thu, Sep 4, 2008 at 11:58 PM, Igor Sysoev <is@rambler-co.ru> wrote:
> 
> > However, please note that worker_cpu_affinity is currently broken and
> > it may not work correctly. Recently CPU affinity had appeared in
> > FreeBSD 7, so I will probably fix it to see how it may affect on perfomance.
> 
> does it work in linux?

worker_cpu_affinity had been written for Linux only and currently
it's broken on Linux.
Posted by mike (Guest)
on 05.09.2008 09:41
(Received via mailing list)
ouch. so the logfile showing the SCHED_AFFINITY binding or whatever at
startup isn't actually happening?

when did it break? i swear i was able to see each worker properly
bound to one core when i examined it in the past.
Posted by Igor Sysoev (Guest)
on 05.09.2008 10:12
(Received via mailing list)
On Fri, Sep 05, 2008 at 12:35:31AM -0700, mike wrote:

> ouch. so the logfile showing the SCHED_AFFINITY binding or whatever at
> startup isn't actually happening?
> 
> when did it break? i swear i was able to see each worker properly
> bound to one core when i examined it in the past.

The problem that nginx says that it pass 32-bytes CPU mask to a kernel,
while actually it passes 4 valid bytes only. It depends on kernel
how it will treat this mask: if it has 2 or 4 CPUs it may work 
correctly.

Besides, there are several Linux kernel and glibc sched_setaffinity()
interfaces, so you may have a case that works.
Posted by Robert Gabriel (jinx)
on 05.09.2008 10:14
Hmm ok, one more stupid question, which version would you said its best 
for a productive system: 0.6.32 / 0.7.14 / 0.5.37 ?
Posted by Igor Sysoev (Guest)
on 05.09.2008 10:48
(Received via mailing list)
On Fri, Sep 05, 2008 at 10:14:55AM +0200, Robert Gabriel wrote:

> Hmm ok, one more stupid question, which version would you said its best 
> for a productive system: 0.6.32 / 0.7.14 / 0.5.37 ?

0.6.32.
Posted by Robert Gabriel (jinx)
on 05.09.2008 10:53
Thx very much!
Posted by rkmr.em@gmail.com (Guest)
on 05.09.2008 13:34
(Received via mailing list)
what is cpu worker affinity? can you pl. explain?
thanks!
Posted by Robert Gabriel (jinx)
on 05.09.2008 17:41
For example you have 2 workers, meaning to working processes of nginx, 
which will deal with the incoming requests. The workers randomly on the 
cores/cpus of the computer/server. With worker cpu affinity to tell the 
workers, each to work one on core/cpu 1 and second on core/cpu 2, or 
vice-versa. Of course this can be done with 4 cores/cpus or 8 cores/cpus 
and so on.

P.S. Im not that good eider with how the kernel and stuff like that 
handles everything, but I think I am right on this.
Posted by Robert Gabriel (jinx)
on 05.09.2008 17:43
Sorry, for some reason I have a lot of "grammar" mistakes :)
Posted by zoltarx (Guest)
on 06.09.2008 12:18
(Received via mailing list)
IMHO: Affinity is just a flag which tells kernel on what CPUs can run 
the
code of specified process (even thread) - in other words you could set
affinity for first process to CPU0 and second to CPU1 and they should be
working on different CPU's I don't know if Linux kernel supports that, 
but
windows should honour this setting. I don't think that this kind of
separation would make big difference in performance.
Greetings,
zoltarx

2008/9/5 Robert Gabriel <lists@ruby-forum.com>

> Sorry, for some reason I have a lot of "grammar" mistakes :)
> --
> Posted via http://www.ruby-forum.com/.
>
>


--
______________________________

Filip Golewski
e-mail: f.golewski@gmail.com
e-mail: zoltarx@o2.pl
Posted by Chris Savery (Guest)
on 06.09.2008 12:49
(Received via mailing list)
There's a decent explanation of it here:
http://www.linuxjournal.com/article/6799

It is complex but I think if can have worthwhile performance impacts as
without affinity the cache memory gets invalidated as processes move
from core to core. Avoiding that has got to have an effect. I haven't
seen any real benchmarks though.
Chris :)