From 08c6bbb5424875dc4ea5ef1a536eeb8b50ce5805 Mon Sep 17 00:00:00 2001 From: Willy Tarreau Date: Thu, 18 Sep 2025 09:07:35 +0200 Subject: [PATCH] OPTIM: sink: don't waste time calling sink_announce_dropped() if busy If we see that another thread is already busy trying to announce the dropped counter, there's no point going there, so let's just skip all that operation from sink_write() and avoid disturbing the other thread. This results in a boost from 244 to 262k req/s. --- include/haproxy/sink.h | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/include/haproxy/sink.h b/include/haproxy/sink.h index ebf7c66d4..816901b13 100644 --- a/include/haproxy/sink.h +++ b/include/haproxy/sink.h @@ -54,8 +54,11 @@ static inline ssize_t sink_write(struct sink *sink, struct log_header hdr, size_t maxlen, const struct ist msg[], size_t nmsg) { ssize_t sent = 0; + uint dropped = HA_ATOMIC_LOAD(&sink->ctx.dropped); - if (unlikely(HA_ATOMIC_LOAD(&sink->ctx.dropped) > 0)) { + if (unlikely(dropped > 0)) { + if (dropped & 1) // another thread on it. + goto fail; sent = sink_announce_dropped(sink, hdr); if (!sent) {