]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
MINOR: compression: memlevel and windowsize
authorWilliam Lallemand <wlallemand@exceliance.fr>
Wed, 7 Nov 2012 15:54:34 +0000 (16:54 +0100)
committerWilly Tarreau <w@1wt.eu>
Thu, 8 Nov 2012 14:23:29 +0000 (15:23 +0100)
The window size and the memlevel of the zlib are now configurable using
global options tune.zlib.memlevel and tune.zlib.windowsize.

It affects the memory consumption of the zlib.

doc/configuration.txt
include/types/compression.h
include/types/global.h
src/cfgparse.c
src/compression.c
src/haproxy.c

index 225acb7238e2d443defff90a462c537b8d34bf57..eb249889b9d9c7e65e3a0bd0d72a80a165d04005 100644 (file)
@@ -474,6 +474,8 @@ The following keywords are supported in the "global" section :
    - tune.rcvbuf.server
    - tune.sndbuf.client
    - tune.sndbuf.server
+   - tune.zlib.memlevel
+   - tune.zlib.windowsize
 
  * Debugging
    - debug
@@ -816,6 +818,18 @@ tune.sndbuf.server <number>
   to the kernel waiting for a large part of the buffer to be read before
   notifying haproxy again.
 
+tune.zlib.memlevel <number>
+  Sets the memLevel parameter in zlib initialization for each session. It
+  defines how much memory should be allocated for the intenal compression
+  state. A value of 1 uses minimum memory but is slow and reduces compression
+  ratio, a value of 9 uses maximum memory for optimal speed.  Can be a value
+  between 1 and 9. The default value is 8.
+
+tune.zlib.windowsize <number>
+  Sets the window size (the size of the history buffer) as a parameter of the
+  zlib initialization for each session. Larger values of this parameter result
+  in better compression at the expense of memory usage.  Can be a value between
+  8 and 15.  The default value is 15.
 
 3.3. Debugging
 --------------
index 6f418fa0574159728b0b81cb3688f45f41c4918e..097c42c4a6ed38026fbdd3e0d7893192f8d9e211 100644 (file)
@@ -44,7 +44,7 @@ struct comp_ctx {
 struct comp_algo {
        char *name;
        int name_len;
-       int (*init)(struct comp_ctx *comp_ctx, int);
+       int (*init)(struct comp_ctx *comp_ctx, int level);
        int (*add_data)(struct comp_ctx *comp_ctx, const char *in_data, int in_len, char *out_data, int out_len);
        int (*flush)(struct comp_ctx *comp_ctx, struct buffer *out, int flag);
        int (*reset)(struct comp_ctx *comp_ctx);
index 28632b7224dfa4d70ec121c33a00dd781af12eb5..2f41be5589b1a35234ffb1c566660492df6287dd 100644 (file)
@@ -111,6 +111,10 @@ struct global {
                int max_http_hdr;  /* max number of HTTP headers, use MAX_HTTP_HDR if zero */
 #ifdef USE_OPENSSL
                int sslcachesize;  /* SSL cache size in session, defaults to 20000 */
+#endif
+#ifdef USE_ZLIB
+               int zlibmemlevel;    /* zlib memlevel */
+               int zlibwindowsize;  /* zlib window size */
 #endif
        } tune;
        struct {
index d1f18f7ab7b8cdc1a34e00f89b0acb7f8fd6cfd3..2b451225dc3137a16440a6f8da8e4092de31d936 100644 (file)
@@ -662,6 +662,50 @@ int cfg_parse_global(const char *file, int linenum, char **args, int kwm)
                }
                global.tune.max_http_hdr = atol(args[1]);
        }
+       else if (!strcmp(args[0], "tune.zlib.memlevel")) {
+#ifdef USE_ZLIB
+               if (*args[1]) {
+                       global.tune.zlibmemlevel = atoi(args[1]);
+                       if (global.tune.zlibmemlevel < 1 || global.tune.zlibmemlevel > 9) {
+                               Alert("parsing [%s:%d] : '%s' expects a numeric value between 1 and 9\n",
+                                     file, linenum, args[0]);
+                               err_code |= ERR_ALERT | ERR_FATAL;
+                               goto out;
+                       }
+               } else {
+                       Alert("parsing [%s:%d] : '%s' expects a numeric value between 1 and 9\n",
+                             file, linenum, args[0]);
+                       err_code |= ERR_ALERT | ERR_FATAL;
+                       goto out;
+               }
+#else
+               Alert("parsing [%s:%d] : '%s' is not implemented.\n", file, linenum, args[0]);
+               err_code |= ERR_ALERT | ERR_FATAL;
+               goto out;
+#endif
+       }
+       else if (!strcmp(args[0], "tune.zlib.windowsize")) {
+#ifdef USE_ZLIB
+               if (*args[1]) {
+                       global.tune.zlibwindowsize = atoi(args[1]);
+                       if (global.tune.zlibwindowsize < 8 || global.tune.zlibwindowsize > 15) {
+                               Alert("parsing [%s:%d] : '%s' expects a numeric value between 8 and 15\n",
+                                     file, linenum, args[0]);
+                               err_code |= ERR_ALERT | ERR_FATAL;
+                               goto out;
+                       }
+               } else {
+                       Alert("parsing [%s:%d] : '%s' expects a numeric value between 8 and 15\n",
+                             file, linenum, args[0]);
+                       err_code |= ERR_ALERT | ERR_FATAL;
+                       goto out;
+               }
+#else
+               Alert("parsing [%s:%d] : '%s' is not implemented.\n", file, linenum, args[0]);
+               err_code |= ERR_ALERT | ERR_FATAL;
+               goto out;
+#endif
+       }
        else if (!strcmp(args[0], "uid")) {
                if (global.uid != 0) {
                        Alert("parsing [%s:%d] : user/uid already specified. Continuing.\n", file, linenum);
index 1f12df9aec78e9dffebb08de71358ff6d9dae6d3..c20a4495ebc87748d3eebfd4e8b9792d61b7ddb1 100644 (file)
@@ -329,7 +329,7 @@ int gzip_init(struct comp_ctx *comp_ctx, int level)
        strm->zfree = Z_NULL;
        strm->opaque = Z_NULL;
 
-       if (deflateInit2(&comp_ctx->strm, level, Z_DEFLATED, MAX_WBITS + 16, 8, Z_DEFAULT_STRATEGY) != Z_OK)
+       if (deflateInit2(&comp_ctx->strm, level, Z_DEFLATED, global.tune.zlibwindowsize + 16, global.tune.zlibmemlevel, Z_DEFAULT_STRATEGY) != Z_OK)
                return -1;
 
        return 0;
index c6933c33d4a59076e7ad852916a3645c45317b56..d85a46afeed72af8426ac835379cd37650058e68 100644 (file)
@@ -126,6 +126,12 @@ struct global global = {
 #ifdef USE_OPENSSL
                .sslcachesize = 20000,
 #endif
+#ifdef USE_ZLIB
+               .zlibmemlevel = 8,
+               .zlibwindowsize = MAX_WBITS,
+#endif
+
+
        },
 #ifdef USE_OPENSSL
 #ifdef DEFAULT_MAXSSLCONN