]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
OPTIM: sink: don't waste time calling sink_announce_dropped() if busy
authorWilly Tarreau <w@1wt.eu>
Thu, 18 Sep 2025 07:07:35 +0000 (09:07 +0200)
committerWilly Tarreau <w@1wt.eu>
Thu, 18 Sep 2025 07:07:35 +0000 (09:07 +0200)
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

index ebf7c66d4dcd789c0979fe34951494a3460a3c32..816901b133a3bf1ea58aaf84bcacc57ee137308d 100644 (file)
@@ -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) {