]> git.kaiwu.me - haproxy.git/commit
MEDIUM: compression/slz: use the event content type for server-sent events
authorWilly Tarreau <w@1wt.eu>
Mon, 16 Nov 2026 08:05:39 +0000 (09:05 +0100)
committerWilly Tarreau <w@1wt.eu>
Mon, 16 Nov 2026 08:21:10 +0000 (09:21 +0100)
commitaa39e1b101fecf80cea9c6e7cd8eb8bf5e08a7c4
treee6d9c98fa94ccbdef8e51e7b01da76343166b517
parent66e486d51d091d845842ac9c9f25c1c357d868de
MEDIUM: compression/slz: use the event content type for server-sent events

libslz's SLZ_CT_EVENT content type keeps the last 2 kB of a stream and its
reference table between calls, in a ring which the application allocates
(slz_ring_size bytes, zeroed) and sets in the stream. Server-sent events
now compress to ~4% instead of ~102% (inflating by ~2%).

A new pool "slz_ring" is created at boot with the size exported by
libslz, aligned on a cache line. The slz init functions allocate a zeroed
ring from it for COMP_CT_EVENT, unless "tune.comp.res.ring" is off, and
select SLZ_CT_EVENT, and comp_rfc195x_end() releases it. The pool is
created before the configuration is parsed, but stays empty when the
setting is off. If the pool or the ring can't be allocated, or the
compression level is 0, the default encoding is used, as the text tree
would have to send its header after each event. The support is detected
by the slz_ring_size macro, for older external versions of libslz.

Through haproxy, 942 events of a real capture from llama-server sent
10 ms apart, with gzip compression:

  Content-Type        output    ratio
  text/x-sse          265120  101.75% # previous default text compression
  text/event-stream    10578    4.06%

Synthetic tests using the sse-latency tool shows this with 1000 tiny
messages:
           bytes in    bytes out    ratio
  before:    227584       199829      88%
  after:     227584        20680       9%
src/compression.c