Centos – Assigning Processes to CPU Cores

apache-2.2centosprocesstuning

I have access to a CentOS 6 web server (a PHP/MySQL forum) running Apache 2.2.15 and MySQL 5.1.52. This box has dual oct-core Xeons.

What I find looking over the CPU graphs is that the first two cores (0 and 1) hit 90% usage whilst the other fourteen are only reaching 30-40% usage. Core 8, which I believe is the first core of the second processor, see's high usage (up to 90%) but then as mentioned, all others are low.

Apache fires up about 20 processes and I suspect in its default state, it can't understand, and make use of all the cores naturally. This should be the kernels job I think (can someone confirm?). However, with those cores maxing out, there is a noticable performance drop despite spare RAM and disk I/O.

Is there something I can tweak in Apache to "make it aware" of all the other cores, or perhaps a kernel peramater to assign certain process to certain cores? Can I exclude cores 0 and 1 for example, from being used for Apache and MySQL?

Best Answer

Tunning process affinity with taskset

e.g assign current process to cpu-core 0,1,3

$taskset -cp 0,1,3 $$

pid 21698's current affinity list: 0-7

pid 21698's new affinity list: 0,1,3

Isolate CPUs to run particular process only. Kernel parameter “isolcpus” can isolate particular CPUs from doing other tasks. Together with taskset, you can have particular CPUs to run designated tasks only. E.g put “isolcpus=2,3 “ in grub.conf will isolate CPU 2 and 3.

http://honglus.blogspot.com/2011/03/tune-interrupt-and-process-cpu-affinity.html