From b604064980ff4bd80cb829dfcc50eb26b975edec Mon Sep 17 00:00:00 2001 From: Willy Tarreau Date: Wed, 25 Feb 2026 09:58:08 +0100 Subject: [PATCH] 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. --- include/haproxy/counters.h | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) 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) \