]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
MEDIUM: counters: make EXTRA_COUNTERS_GET() consider tgid
authorWilly Tarreau <w@1wt.eu>
Wed, 25 Feb 2026 08:58:08 +0000 (09:58 +0100)
committerWilly Tarreau <w@1wt.eu>
Thu, 26 Feb 2026 16:03:53 +0000 (17:03 +0100)
Now we store and retrieve only counters for the current tgid when more
than one is supported. This allows to significantly reduce contention
on shared stats. The haterm utility saw its performance increase from
4.9 to 5.8M req/s in H1, and 6.0 to 7.6M for H2, both with 5 groups of
16 threads, showing that we don't necessarily need insane amounts of
groups.

include/haproxy/counters.h

index 1c4d7f1c94c4e19e49b87e786d089d30a3af8a11..b536215a75033e2bad7cb5c9d1b1a90858257425 100644 (file)
@@ -110,9 +110,13 @@ void counters_be_shared_drop(struct be_counters_shared *counters);
                ((void *)(*(counters)->datap + (mod)->counters_off[(counters)->type])) : \
                (trash_counters))
 
+/* retrieve the pointer to the extra counters storage for module <mod> for the
+ * current TGID.
+ */
 #define EXTRA_COUNTERS_GET(counters, mod) \
        (likely(counters) ? \
-               ((void *)(*(counters)->datap + (mod)->counters_off[(counters)->type])) : \
+               ((void *)(counters)->datap[(counters)->tgrp_step * (tgid - 1)] +    \
+                (mod)->counters_off[(counters)->type]) : \
                (trash_counters))
 
 #define EXTRA_COUNTERS_REGISTER(counters, ctype, alloc_failed_label, storage, step) \