From: Willy Tarreau Date: Sun, 15 Nov 2026 21:49:19 +0000 (+0100) Subject: MINOR: compression: add tune.comp.res.ring to disable the rings of responses X-Git-Tag: v3.5-dev13~69 X-Git-Url: https://git.kaiwu.me/web/%22data:,/doc/static/%7B@url%7D?a=commitdiff_plain;h=66e486d51d091d845842ac9c9f25c1c357d868de;p=haproxy.git MINOR: compression: add tune.comp.res.ring to disable the rings of responses Some algorithms may need a ring to keep a history between flushes for some responses, such as the upcoming support of server-sent events with SLZ's event content type, which costs about 4 kB per stream. This new global setting "tune.comp.res.ring" will allow to disable it ('off') to save that memory, in which case these responses are compressed as if their type were unknown. It is enabled by default ('on'). It's not used yet, the next commit will make use of it. The keyword is accepted whatever the algorithms and libraries, so that a configuration doesn't depend on the build options. --- diff --git a/doc/configuration.txt b/doc/configuration.txt index ee08fca77..e23f6ccce 100644 --- a/doc/configuration.txt +++ b/doc/configuration.txt @@ -1946,6 +1946,7 @@ The following keywords are supported in the "global" section : - tune.bufsize.small - tune.cli.max-payload-size - tune.comp.maxlevel + - tune.comp.res.ring - tune.debug-file-directory - tune.defaults.purge - tune.disable-elf-symbols @@ -4567,6 +4568,18 @@ tune.comp.maxlevel Each stream using compression initializes the compression algorithm with this value. The default value is 1. +tune.comp.res.ring { on | off } + Enables ('on') or disables ('off') the allocation of a ring for compressed + responses which benefit from a history kept between flushes, which is + currently the case of server-sent events ("text/event-stream") with the + "gzip", "deflate" and "raw-deflate" algorithms when haproxy is built with + SLZ. Such events are flushed one at a time and usually repeat most of the + previous ones, which the ring allows to compress to a few percent of their + size instead of slightly inflating them. The ring costs about 4 kB per + stream, which may be saved this way, in which case these responses are + compressed as if their contents were of an unknown type. The ring is + never allocated for requests. It is enabled by default. + tune.debug-file-directory Adds to the list of directories searched for the separate debug files of stripped executables and libraries, whose symbols are used to name diff --git a/src/compression.c b/src/compression.c index 7b1acfe0c..e9ad2e32f 100644 --- a/src/compression.c +++ b/src/compression.c @@ -331,6 +331,9 @@ static int comp_identity_end(struct comp_ctx **comp_ctx) } +/* "tune.comp.res.ring": rings may be allocated for responses (default) */ +static int comp_res_ring __read_mostly = 1; + #ifdef USE_SLZ /* Selects SLZ's content type matching on the stream of @@ -874,6 +877,24 @@ static int zlib_parse_global_windowsize(char **args, int section_type, struct pr #endif /* USE_ZLIB */ +/* config parser for global "tune.comp.res.ring" */ +static int comp_parse_global_res_ring(char **args, int section_type, struct proxy *curpx, + const struct proxy *defpx, const char *file, int line, + char **err) +{ + if (too_many_args(1, args, err, NULL)) + return -1; + + if (strcmp(args[1], "on") == 0) + comp_res_ring = 1; + else if (strcmp(args[1], "off") == 0) + comp_res_ring = 0; + else { + memprintf(err, "'%s' expects 'on' or 'off'.", args[0]); + return -1; + } + return 0; +} /* config keyword parsers */ static struct cfg_kw_list cfg_kws = {ILH, { @@ -881,6 +902,7 @@ static struct cfg_kw_list cfg_kws = {ILH, { { CFG_GLOBAL, "tune.zlib.memlevel", zlib_parse_global_memlevel }, { CFG_GLOBAL, "tune.zlib.windowsize", zlib_parse_global_windowsize }, #endif + { CFG_GLOBAL, "tune.comp.res.ring", comp_parse_global_res_ring }, { 0, NULL, NULL } }};