diff --git a/doc/configuration.txt b/doc/configuration.txt index 230747968..67f4337af 100644 --- a/doc/configuration.txt +++ b/doc/configuration.txt @@ -3037,11 +3037,17 @@ master-worker no-exit-on-failure max-threads-per-group Defines the maximum number of threads in a thread group. Unless the number - of thread groups is fixed with the thread-groups directive, haproxy will - create more thread groups if needed. The default and maximum value is 64. - Having a lower value means more groups will potentially be created, which - can help improve performances, as a number of data structures are per - thread group, and that will mean less contention + of thread groups is fixed with the "thread-groups" directive, haproxy will + create as many thread groups as needed to satisfy the requested number of + threads. Tha minimum value is 1, and the maximum value is 64 (on 64-bit + systems, or 32 on 32-bit systems). Lower values reduce contention caused by + atomic operations on shared states, but can increase the number of sockets + needed to create all listeners and to hold idle backend connections. Higher + values will reduce these costs, at the expense of higher CPU usage under + contented situations, and lower connection rates. The default value is 16, + which provides the best tradeoff that was experimentally found on various + tested systems, including x86_64 processors from multiple vendors, and large + Arm64 systems, both on bare metal and hypervisors. mworker-max-reloads In master-worker mode, this option limits the number of time a worker can diff --git a/include/haproxy/defaults.h b/include/haproxy/defaults.h index 2c9896047..54e733d12 100644 --- a/include/haproxy/defaults.h +++ b/include/haproxy/defaults.h @@ -49,6 +49,15 @@ #define MAX_THREADS_PER_GROUP __WORDSIZE +/* Default value for the maximum number of threads per group. Thread counts + * beyond this value will induce the creation of new thread groups and thus + * limit contention on highly accessed areas. The value may be changed between + * 1 and MAX_THREADS_PER_GROUP via the global "max-threads-per-group" setting. + */ +#ifndef DEF_MAX_THREADS_PER_GROUP +#define DEF_MAX_THREADS_PER_GROUP 16 +#endif + /* threads enabled, max_threads defaults to long bits for 1 tgroup or 4 times * long bits if more tgroups are enabled. */ diff --git a/src/haproxy.c b/src/haproxy.c index 39d1a0ac6..292679dfe 100644 --- a/src/haproxy.c +++ b/src/haproxy.c @@ -209,7 +209,7 @@ struct global global = { #endif /* by default allow clients which use a privileged port for TCP only */ .clt_privileged_ports = HA_PROTO_TCP, - .maxthrpertgroup = MAX_THREADS_PER_GROUP, + .maxthrpertgroup = DEF_MAX_THREADS_PER_GROUP, /* others NULL OK */ };