]> git.kaiwu.me - haproxy.git/commitdiff
MINOR: compression: add tune.comp.res.ring to disable the rings of responses
authorWilly Tarreau <w@1wt.eu>
Sun, 15 Nov 2026 21:49:19 +0000 (22:49 +0100)
committerWilly Tarreau <w@1wt.eu>
Mon, 16 Nov 2026 08:21:03 +0000 (09:21 +0100)
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.

doc/configuration.txt
src/compression.c

index ee08fca77f3f17cd01fbb94c091fe2d4aefb9859..e23f6ccce43074687b1403ec867503fa030be275 100644 (file)
@@ -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 <number>
   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 <dir>
   Adds <dir> to the list of directories searched for the separate debug files
   of stripped executables and libraries, whose symbols are used to name
index 7b1acfe0c3a4b501735829f01fb860dcf78f7f22..e9ad2e32fe3586701e5b2b1b74f8cbd2490be662 100644 (file)
@@ -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 <ctype> on the stream of <comp_ctx>
@@ -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 }
 }};