]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
MINOR: stats: Add an option to disable the calculation of max counters
authorOlivier Houchard <ohouchard@haproxy.com>
Mon, 2 Mar 2026 16:01:58 +0000 (17:01 +0100)
committerOlivier Houchard <cognet@ci0.org>
Thu, 5 Mar 2026 14:39:42 +0000 (15:39 +0100)
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
include/haproxy/counters.h
include/haproxy/global-t.h
src/cli.c

index 7905e181563318f05eb8fb3497763ae9ed85cbc1..a816666b6b3b634e241e7e2262c5e944b03880e8 100644 (file)
@@ -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 <connections>
   By default, the stats socket is limited to 10 concurrent connections. It is
   possible to change this value with "stats maxconn".
index 6850e7b84d42a2eb43d1ab461176c20265f96e61..599b732fffcf774ae0de021ba47b3f59bc75b54a 100644 (file)
@@ -26,6 +26,7 @@
 
 #include <haproxy/counters-t.h>
 #include <haproxy/guid-t.h>
+#include <haproxy/global.h>
 
 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 */
index 6b3ba5cd504f0f090a49d814b4c30be0bb94e793..212b62bf78f530055d8c383bf88bd93aeaae2e43 100644 (file)
@@ -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)
index 312e2a2cb005dcc6200d480a824b9d99a31069f1..55a514d090fddaaaf5e35c87819352500c500100 100644 (file)
--- 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;