MINOR: config: automatically preset MAX_THREADS based on MAX_TGROUPS

MAX_THREADS was not changed when setting MAX_TGROUPS, which still limits
some possibilities. Let's preset it to 4 * LONGBITS when MAX_TGROUPS is
larger than 1, or LONGBITS when it's set to 1. This means that the new
default value is 256 threads.

The rationale behind this is that the main use of thread groups is
mostly to address NUMA issues and that we don't necessarily need large
thread counts when using many groups, and 256 threads is already plenty
even on quite large systems.

For now it's important not to go too far because some internal structs
are arrays of MAX_THREADS entries, for example accept_queue_ring, which
is around 8kB per thread. Such structures will need to become dynamic
before defaulting to large thread counts (at 4096 threads max the
accept queues would require 32 MB RAM alone).
This commit is contained in:
Willy Tarreau 2022-08-06 16:37:27 +02:00
parent c80bdb2da6
commit 693688e734

View File

@ -34,10 +34,6 @@
#define MAX_THREADS_PER_GROUP 1 #define MAX_THREADS_PER_GROUP 1
#else #else
/* threads enabled, max_threads defaults to long bits */
#ifndef MAX_THREADS
#define MAX_THREADS LONGBITS
#endif
/* theoretical limit is 64, though we'd rather not push it too far for now /* theoretical limit is 64, though we'd rather not push it too far for now
* as some structures might be enlarged to be indexed per group. Let's start * as some structures might be enlarged to be indexed per group. Let's start
@ -48,9 +44,18 @@
#ifndef MAX_TGROUPS #ifndef MAX_TGROUPS
#define MAX_TGROUPS 16 #define MAX_TGROUPS 16
#endif #endif
#define MAX_THREADS_PER_GROUP LONGBITS #define MAX_THREADS_PER_GROUP LONGBITS
/* threads enabled, max_threads defaults to long bits for 1 tgroup or 4 times
* long bits if more tgroups are enabled.
*/
#ifndef MAX_THREADS
#define MAX_THREADS ((((MAX_TGROUPS) > 1) ? 4 : 1) * (MAX_THREADS_PER_GROUP))
#endif #endif
#endif // USE_THREAD
/* /*
* BUFSIZE defines the size of a read and write buffer. It is the maximum * BUFSIZE defines the size of a read and write buffer. It is the maximum
* amount of bytes which can be stored by the proxy for each stream. However, * amount of bytes which can be stored by the proxy for each stream. However,