]> git.ipfire.org Git - thirdparty/haproxy.git/commit
OPTIM: sink: try to merge "dropped" messages faster
authorWilly Tarreau <w@1wt.eu>
Fri, 1 Mar 2024 16:59:59 +0000 (17:59 +0100)
committerWilly Tarreau <w@1wt.eu>
Sat, 9 Mar 2024 10:23:52 +0000 (11:23 +0100)
commiteb7b2ec83a7f2e0894c9c1a1b3cc0a29aeeeb767
tree123e89f56d339d3c01580d4acb0b7e1cd569e9fb
parent571232535a6ae48cf95532610fad41a46509497b
OPTIM: sink: try to merge "dropped" messages faster

When a reader doesn't read fast enough and causes drops, subsequent
threads try to produce a "dropped" message. But it takes time to
produce and emit this message, in part due to the use of chunk_printf()
that relies on vfprintf() which has to parse the printf format, and
during this time other threads may continue to increment the counter.
This is the reason why this is currently performed in a loop. When
reading what is received, it's common to see a large count followed
by one or two single-digit counts, indicating that we could possibly
have improved that by writing faster.

Let's improve the situation a little bit. First we're now using a
static message prefixed with enough space to write the digits, and a
call to ultoa_r() fills these digits from right to left so that we
don't have to process a format string nor perform a copy of the message.

Second, we now re-check the counter immediately after having prepared
the message so that we still get an opportunity for updating it. In
order to avoid too long loops, this is limited to 10 iterations.

Tests show that the number of single-digit "dropped" counters on output
now dropped roughly by 15-30%. Also, it was observed that with 8 threads,
there's almost never more than one retry.
src/sink.c