The multi-threading model is a feature that allows HAProxy to start multiple threads within a single process.

Multi-process vs. Multi-threading

Previously, the multi-process model made it possible to start multiple HAproxy processes as a way of scaling user workloads.

This is done by using the configuration directive nbproc. It is also possible to map processes to individual CPU cores using cpu-map.

With the multi-threading model, on the other hand, HAProxy can automatically start a number of threads within a single process. In so doing, it can benefit from the following single-process features:

  • The HAProxy peers protocol, used to synchronize stick tables across HAProxy instances

  • Information sharing between HAProxy threads, such as configuration parameters, statistics, limits, and rates

  • Less health checking traffic

  • HAProxy Runtime API without loops

Configure multi-threading

By default, HAProxy starts one process and one thread. To start additional threads, you set the option nbthread in the global configuration section.

Note

The option nbthread is compatible with nbproc, which means that you can start multiple HAProxy processes in which each process can have multiple threads.

Next, you map processes and threads to CPU cores using the configuration directive cpu-map.

global
  nbproc 1
  nbthread 4
  cpu-map auto:1/1-4 0-3

For more details, refer to the HAProxy Configuration Guide in the following sections: