CPU Affinity

#1
my server has 4 cores, what should i set the CPU Affinity too based on best performance? my site has quite heavy content.

cheers
 

lucasrolff

Active Member
Staff member
#2
Hi @adzkii

I suggest that you se tthe CPU Affinity to 1, this makes each worker stick to it's own core, so all traffic that worker will receive will always be served from the same CPU core, this increases the overall performance because the web server will be able to utilize the local CPU cache.

By setting it to 1, you'll see your 4 worker processes being assigned to 4 different cores.

You can verify this by running:

Code:
ps -eF | grep litespeed
The 4th column will be the core it's assigned to, like as following:

Code:
$ ps -eF | grep litespeed
root     16116     1  0 39337 109780  0 11:54 ?        00:00:22 litespeed (lshttpd - main)
nobody   16162 16116  4 376097 700492 0 11:54 ?        00:13:46 litespeed (lshttpd - #01)
In this case the lshttpd - main is assigned to core 0, and #01 being assigned to core 4.
 
#3
Hi @adzkii

I suggest that you se tthe CPU Affinity to 1, this makes each worker stick to it's own core, so all traffic that worker will receive will always be served from the same CPU core, this increases the overall performance because the web server will be able to utilize the local CPU cache.

By setting it to 1, you'll see your 4 worker processes being assigned to 4 different cores.

You can verify this by running:

Code:
ps -eF | grep litespeed
The 4th column will be the core it's assigned to, like as following:

Code:
$ ps -eF | grep litespeed
root     16116     1  0 39337 109780  0 11:54 ?        00:00:22 litespeed (lshttpd - main)
nobody   16162 16116  4 376097 700492 0 11:54 ?        00:13:46 litespeed (lshttpd - #01)
In this case the lshttpd - main is assigned to core 0, and #01 being assigned to core 4.
i'll set it too 1, what about leaving it empty? what happens?

cheers
 

lucasrolff

Active Member
Staff member
#4
If it's left empty it will use the default value (0), this will disable pinning a given process to a core.

What this means is that whenever a process idle (which it does a lot), the OS can then assign the process to another core at any given time.
 

Deepblue

Active Member
#5
If it's left empty it will use the default value (0), this will disable pinning a given process to a core.

What this means is that whenever a process idle (which it does a lot), the OS can then assign the process to another core at any given time.
My server has 16 cores still you suggest set it to 1 ?
 

lucasrolff

Active Member
Staff member
#6
My server has 16 cores still you suggest set it to 1 ?
It doesn’t matter how many cores you have, when setting it to 1, you’re telling the process (or processes), to pin themselves to a specific core, if you have a license with two workers then they’ll pin themselves to two individual cores.

The benefit in pinning the processes to specific cores is that you’re keeping data local at a given core, so you’ll be able to use the CPU cache more efficiently. As well as lowering your interrupts slightly, which matters a lot in a high traffic environment.
 

Deepblue

Active Member
#7
It doesn’t matter how many cores you have, when setting it to 1, you’re telling the process (or processes), to pin themselves to a specific core, if you have a license with two workers then they’ll pin themselves to two individual cores.

The benefit in pinning the processes to specific cores is that you’re keeping data local at a given core, so you’ll be able to use the CPU cache more efficiently. As well as lowering your interrupts slightly, which matters a lot in a high traffic environment.
I have license with 2 cores so what is best option for me 1 or 2 ? or dont set it at all?
 

lucasrolff

Active Member
Staff member
#8
I have license with 2 cores so what is best option for me 1 or 2 ? or dont set it at all?
The best option would be 1 in any case, it means it pins each worker to it's own process and thus utilizing the CPU cache most efficiently.

The default will generally also be fine, you have to push quite a lot of traffic before you'll see the benefits of pinning.
 

Deepblue

Active Member
#9
The best option would be 1 in any case, it means it pins each worker to it's own process and thus utilizing the CPU cache most efficiently.

The default will generally also be fine, you have to push quite a lot of traffic before you'll see the benefits of pinning.
Thank you very much.
 
Top