# CPU Affinity - nbproc\>1 and nbthread\>1

**URL:** <https://discourse.haproxy.org/t/cpu-affinity-nbproc-1-and-nbthread-1/5675>\
**Category:** Help!\
**Created:** [September 2, 2020, 2:22pm UTC](https://discourse.haproxy.org/t/cpu-affinity-nbproc-1-and-nbthread-1/5675 "2020-09-02T14:22:28Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![montish](https://avatars.discourse-cdn.com/v4/letter/m/34f0e0/32.png) [@montish](https://discourse.haproxy.org/u/montish)\
**Post date:** [September 2, 2020, 2:22pm UTC](https://discourse.haproxy.org/t/cpu-affinity-nbproc-1-and-nbthread-1/5675/1 "2020-09-02T14:22:28Z")

</div>

When running HAProxy with more than one CPU socket, it is [recommended]([https://www.haproxy.com/documentation/hapee/2-1r1/configuration/system-tuning/#pin-network-interrupts-to-cores](https://www.haproxy.com/documentation/hapee/2-1r1/configuration/system-tuning/#pin-network-interrupts-to-cores)} that HAProxy should run with CPU affinity hence `nbproc=2` and each process with its NUMA cores:

```python
:~# lscpu 
Architecture: x86_64
CPU op-mode(s): 32-bit, 64-bit
CPU(s): 40
On-line CPU(s) list: 0-39
Thread(s) per core: 2
Core(s) per socket: 10
Socket(s): 2
NUMA node(s): 2
NUMA node0 CPU(s): 0,2,4,6,8,10,12,14,16,18,20,22,24,26,28,30,32,34,36,38
NUMA node1 CPU(s): 1,3,5,7,9,11,13,15,17,19,21,23,25,27,29,31,33,35,37,39

```

When trying to run my HAProxy with the following config:

```python
nbproc 2
nbthread 32
cpu-map auto:1/1-16 1 3 5 7 9 11 13 15 17 19 21 23 25 27 29 31
cpu-map auto:2/17-32 0 2 4 6 8 10 12 14 16 18 20 22 24 26 28 30

```

I get error:

> config : cannot enable multiple processes if multiple threads are configured. Please use either nbproc or nbthread but not both.

from the [source code](https://fossies.org/linux/haproxy/src/cfgparse.c), it is not possible to use nbproc\>1 and nbthread\>1:

```auto
 2213 if (global.nbproc > 1 && global.nbthread > 1) {
 2214 ha_alert("config : cannot enable multiple processes if multiple threads are configured. Please use either nbproc or nbthread but not both.\n");
 2215 err_code |= ERR_ALERT | ERR_FATAL;
 2216 goto out;
 2217 }

```

from [Haproxy nbthread config](http://cbonte.github.io/haproxy-dconv/2.2/configuration.html#3.1-nbthread) it states using nbthread \> **This is exclusive with “[nbproc](http://cbonte.github.io/haproxy-dconv/2.2/configuration.html#)”**.

I want to optimise Haproxy running on dual socket server and run it in 2 processes where each process is binded to it Numa cores and utilizing the CPU L3 cache. but it seems that it is now impossible in newer HAproxy version.

To get better performance I’m forced to use only one CPU and not both with:

```python
nbproc 1
nbthread 16
cpu-map auto:1/1-16 1 3 5 7 9 11 13 15 17 19 21 23 25 27 29 31

```

How can I optimise HAproxy on 2 sockets CPU and bind each to its own Numa cores?

---

<div class="post-metadata">

**Author:** ![lukastribus](https://avatars.discourse-cdn.com/v4/letter/l/7ea924/32.png) [@lukastribus](https://discourse.haproxy.org/u/lukastribus)\
**Post date:** [September 2, 2020, 3:55pm UTC](https://discourse.haproxy.org/t/cpu-affinity-nbproc-1-and-nbthread-1/5675/2 "2020-09-02T15:55:17Z")

</div>

You already accepted the disadvantages of running nbproc \> 1, so there is no point in running nbthread as well.

Just use a nbproc 40 with nbthread 1.

---

<div class="post-metadata">

**Author:** ![montish](https://avatars.discourse-cdn.com/v4/letter/m/34f0e0/32.png) [@montish](https://discourse.haproxy.org/u/montish)\
**Post date:** [September 2, 2020, 6:04pm UTC](https://discourse.haproxy.org/t/cpu-affinity-nbproc-1-and-nbthread-1/5675/3 "2020-09-02T18:04:16Z")

</div>

Thank you for you answer.  
using more so many nbproc is not recommended as stated by [Haproxy documentation](https://cbonte.github.io/haproxy-dconv/2.2/configuration.html#3.1-nbthread)

> is strongly encouraged  
> to migrate away from “nbproc” to “nbthread”.

if you meant using nbproc=1 and nbthread40 without CPU affinity, it id indeed utilizing all CPU cores but it has worse performance than running on single CPU with 16 cores…

---

<div class="post-metadata">

**Author:** ![lukastribus](https://avatars.discourse-cdn.com/v4/letter/l/7ea924/32.png) [@lukastribus](https://discourse.haproxy.org/u/lukastribus)\
**Post date:** [September 2, 2020, 9:01pm UTC](https://discourse.haproxy.org/t/cpu-affinity-nbproc-1-and-nbthread-1/5675/4 "2020-09-02T21:01:31Z")

</div>

Yes, but you are specifically asking to run with nbproc.

nbproc is not recommended, because nbthread has advantages over using nbproc. But there is no difference between using `nbproc 2` and `nbproc 40`. It would be recommended to not run nbproc at all, but you are specifically insisting to run nbproc because of NUMA, so it doesn’t make sense to not run it all the way.
