From: Willy Tarreau Date: Wed, 25 Feb 2026 08:58:08 +0000 (+0100) Subject: MEDIUM: counters: make EXTRA_COUNTERS_GET() consider tgid X-Git-Tag: v3.4-dev6~66 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=b604064980ff4bd80cb829dfcc50eb26b975edec;p=thirdparty%2Fhaproxy.git MEDIUM: counters: make EXTRA_COUNTERS_GET() consider tgid 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. --- diff --git a/include/haproxy/counters.h b/include/haproxy/counters.h index 1c4d7f1c9..b536215a7 100644 --- a/include/haproxy/counters.h +++ b/include/haproxy/counters.h @@ -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 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) \