From 5d02d33ee1e2143587e8b891af04eb56a228ab4d Mon Sep 17 00:00:00 2001 From: Olivier Houchard Date: Mon, 2 Mar 2026 17:01:58 +0100 Subject: [PATCH] MINOR: stats: Add an option to disable the calculation of max counters Add a new option, "stats calculate-max-counters [on|off]". It makes it possible to disable the calculation of max counters, as they can have a performance cost. --- doc/configuration.txt | 5 +++++ include/haproxy/counters.h | 4 +++- include/haproxy/global-t.h | 1 + src/cli.c | 12 +++++++++++- 4 files changed, 20 insertions(+), 2 deletions(-) diff --git a/doc/configuration.txt b/doc/configuration.txt index 7905e1815..a816666b6 100644 --- a/doc/configuration.txt +++ b/doc/configuration.txt @@ -3604,6 +3604,11 @@ ssl-skip-self-issued-ca certificates. It's useless for BoringSSL, .issuer is ignored because ocsp bits does not need it. Requires at least OpenSSL 1.0.2. +stats calculate-max-counters [on|off] + Activates or deactivates the calculation of stats max counters. If you + don't need them, deactivating them may increase performances a bit. + The default is on. + stats maxconn By default, the stats socket is limited to 10 concurrent connections. It is possible to change this value with "stats maxconn". diff --git a/include/haproxy/counters.h b/include/haproxy/counters.h index 6850e7b84..599b732ff 100644 --- a/include/haproxy/counters.h +++ b/include/haproxy/counters.h @@ -26,6 +26,7 @@ #include #include +#include extern THREAD_LOCAL void *trash_counters; @@ -105,7 +106,8 @@ void counters_be_shared_drop(struct be_counters_shared *counters); #define COUNTERS_UPDATE_MAX(counter, count) \ do { \ - HA_ATOMIC_UPDATE_MAX(counter, count); \ + if (!(global.tune.options & GTUNE_NO_MAX_COUNTER)) \ + HA_ATOMIC_UPDATE_MAX(counter, count); \ } while (0) /* Manipulation of extra_counters, for boot-time registrable modules */ diff --git a/include/haproxy/global-t.h b/include/haproxy/global-t.h index 6b3ba5cd5..212b62bf7 100644 --- a/include/haproxy/global-t.h +++ b/include/haproxy/global-t.h @@ -86,6 +86,7 @@ #define GTUNE_LISTENER_MQ_OPT (1<<28) #define GTUNE_LISTENER_MQ_ANY (GTUNE_LISTENER_MQ_FAIR | GTUNE_LISTENER_MQ_OPT) #define GTUNE_NO_KTLS (1<<29) +#define GTUNE_NO_MAX_COUNTER (1<<30) /* subsystem-specific debugging options for tune.debug */ #define GDBG_CPU_AFFINITY (1U<< 0) diff --git a/src/cli.c b/src/cli.c index 312e2a2cb..55a514d09 100644 --- a/src/cli.c +++ b/src/cli.c @@ -616,12 +616,22 @@ static int cli_parse_global(char **args, int section_type, struct proxy *curpx, } global.cli_fe->maxconn = maxconn; } + else if (strcmp(args[1], "calculate-max-counters") == 0) { + if (!strcasecmp(args[2], "on")) + return 0; + else if (!strcasecmp(args[2], "off")) { + global.tune.options |= GTUNE_NO_MAX_COUNTER; + return 0; + } + memprintf(err, "'%s' only supports 'on' and 'off', received '%s'", args[1], args[2]); + return -1; + } else if (strcmp(args[1], "bind-process") == 0) { memprintf(err, "'%s %s' is not supported anymore.", args[0], args[1]); return -1; } else { - memprintf(err, "'%s' only supports 'socket', 'maxconn', 'bind-process' and 'timeout' (got '%s')", args[0], args[1]); + memprintf(err, "'%s' only supports 'socket', 'maxconn', 'bind-process', 'calculate-max-counters' and 'timeout' (got '%s')", args[0], args[1]); return -1; } return 0;