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%