|
| 1 | +[id='router-performance-optimizations-{context}'] |
| 2 | += Router performance optimizations |
| 3 | + |
| 4 | +*Setting the maximum number of connections* |
| 5 | + |
| 6 | +One of the most important tunable parameters for HAProxy scalability is the |
| 7 | +`maxconn` parameter, which sets the maximum per-process number of concurrent |
| 8 | +connections to a given number. Adjust this parameter by editing the |
| 9 | +`ROUTER_MAX_CONNECTIONS` environment variable in the {product-title} HAProxy |
| 10 | +router's deployment configuration file. |
| 11 | + |
| 12 | +[NOTE] |
| 13 | +==== |
| 14 | +A connection includes the front end and internal back end. This counts as two |
| 15 | +connections. Be sure to set `ROUTER_MAX_CONNECTIONS` to double than the number |
| 16 | +of connections you intend to create. |
| 17 | +==== |
| 18 | + |
| 19 | +*CPU and interrupt affinity* |
| 20 | + |
| 21 | +In {product-title}, the HAProxy router runs as a single process. The |
| 22 | +{product-title} HAProxy router typically performs better on a system with fewer |
| 23 | +but high frequency cores, rather than on an symmetric multiprocessing (SMP) |
| 24 | +system with a high number of lower frequency cores. |
| 25 | + |
| 26 | +Pinning the HAProxy process to one CPU core and the network interrupts to |
| 27 | +another CPU core tends to increase network performance. Having processes and |
| 28 | +interrupts on the same non-uniform memory access (NUMA) node helps avoid memory |
| 29 | +accesses by ensuring a shared L3 cache. However, this level of control is |
| 30 | +generally not possible on a public cloud environment. On bare metal hosts, |
| 31 | +`irqbalance` automatically handles peripheral component interconnect (PCI) |
| 32 | +locality and NUMA affinity for interrupt request lines (IRQs). On a cloud |
| 33 | +environment, this level of information is generally not provided to the |
| 34 | +operating system. |
| 35 | + |
| 36 | +CPU pinning is performed either by `taskset` or by using HAProxy's `cpu-map` |
| 37 | +parameter. This directive takes two arguments: the process ID and the CPU core |
| 38 | +ID. For example, to pin HAProxy process `1` onto CPU core `0`, add the following |
| 39 | +line to the global section of HAProxy's configuration file: |
| 40 | + |
| 41 | +---- |
| 42 | + cpu-map 1 0 |
| 43 | +---- |
| 44 | + |
| 45 | +*Increasing the number of threads* |
| 46 | + |
| 47 | +The HAProxy router comes with support for multithreading in {product-title}. On |
| 48 | +a multiple CPU core system, increasing the number of threads can help the |
| 49 | +performance, especially when terminating SSL on the router. |
| 50 | + |
| 51 | +*Impacts of buffer increases* |
| 52 | + |
| 53 | +The {product-title} HAProxy router request buffer configuration limits the size |
| 54 | +of headers in incoming requests and responses from applications. The HAProxy |
| 55 | +parameter `tune.bufsize` can be increased to allow processing of larger headers |
| 56 | +and to allow applications with very large cookies to work, such as those |
| 57 | +accepted by load balancers provided by many public cloud providers. However, |
| 58 | +this affects the total memory use, especially when large numbers of connections |
| 59 | +are open. With very large numbers of open connections, the memory usage will be |
| 60 | +nearly proportionate to the increase of this tunable parameter. |
| 61 | + |
| 62 | +*Optimizations for HAProxy reloads* |
| 63 | + |
| 64 | +Long-lasting connections, such as WebSocket connections, combined with |
| 65 | +long client/server HAProxy timeouts and short HAProxy |
| 66 | +reload intervals, can cause instantiation of many HAProxy processes. |
| 67 | +These processes must handle old connections, which were started |
| 68 | +before the HAProxy configuration reload. A large number of these processes is |
| 69 | +undesirable, as it will exert unnecessary load on the system and can |
| 70 | +lead to issues, such as out of memory conditions. |
| 71 | + |
| 72 | +Router environment variables affecting this |
| 73 | +behavior are `ROUTER_DEFAULT_TUNNEL_TIMEOUT`, `ROUTER_DEFAULT_CLIENT_TIMEOUT`, |
| 74 | +`ROUTER_DEFAULT_SERVER_TIMEOUT`, and `RELOAD_INTERVAL` in particular. |
0 commit comments