]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
MINOR: compression: tune.comp.maxlevel
authorWilliam Lallemand <wlallemand@exceliance.fr>
Fri, 9 Nov 2012 11:33:10 +0000 (12:33 +0100)
committerWilly Tarreau <w@1wt.eu>
Sat, 10 Nov 2012 16:47:07 +0000 (17:47 +0100)
This option allows you to set the maximum compression level usable by
the compression algorithm. It affects CPU usage.

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

index c6eed082e8739519d11bef58d6936cd0a6750f21..f624abbbc931816cf94b04cf21703bd54b338c44 100644 (file)
@@ -465,6 +465,7 @@ The following keywords are supported in the "global" section :
    - spread-checks
    - tune.bufsize
    - tune.chksize
+   - tune.comp.maxlevel
    - tune.http.maxhdr
    - tune.maxaccept
    - tune.maxpollevents
@@ -753,6 +754,12 @@ tune.chksize <number>
   build time. It is not recommended to change this value, but to use better
   checks whenever possible.
 
+tune.comp.maxlevel <number>
+  Sets the maximum compression level. The compression level affects CPU
+  usage during compression. This value affects CPU usage during compression.
+  Each session using compression initializes the compression algorithm with
+  this value. The default value is 1.
+
 tune.http.maxhdr <number>
   Sets the maximum number of headers in a request. When a request comes with a
   number of headers greater than this value (including the first line), it is
index fa251f1b8a090c550dbef86b7da15ede875d7b93..da356ad0a562eb1e6b9ae9c2f40ef4ba689d5285 100644 (file)
@@ -44,6 +44,7 @@ struct comp_ctx {
        void *zlib_pending_buf;
        void *zlib_head;
 #endif /* USE_ZLIB */
+       int cur_lvl;
 };
 
 struct comp_algo {
index e4e317bd26f079d3e35aac01f2679a351af82dd0..cfb10d1f1f8a8047e27fc7d67ebdbf694c38768e 100644 (file)
@@ -117,6 +117,7 @@ struct global {
                int zlibmemlevel;    /* zlib memlevel */
                int zlibwindowsize;  /* zlib window size */
 #endif
+               int comp_maxlevel;    /* max HTTP compression level */
        } tune;
        struct {
                char *prefix;           /* path prefix of unix bind socket */
index d5ada1dcfff4d63ee1ce6c40b3fad8edcde1748d..5f22b2424841afa9501c5d2079df616cecdaf38d 100644 (file)
@@ -706,6 +706,22 @@ int cfg_parse_global(const char *file, int linenum, char **args, int kwm)
                goto out;
 #endif
        }
+       else if (!strcmp(args[0], "tune.comp.maxlevel")) {
+               if (*args[1]) {
+                       global.tune.comp_maxlevel = atoi(args[1]);
+                       if (global.tune.comp_maxlevel < 1 || global.tune.comp_maxlevel > 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 if (!strcmp(args[0], "uid")) {
                if (global.uid != 0) {
                        Alert("parsing [%s:%d] : user/uid already specified. Continuing.\n", file, linenum);
index d0e740b7db1718643ff62c2750b25c6172ae7a00..b322244fc4783efe033a7f75bce8e3345605b352 100644 (file)
@@ -131,6 +131,7 @@ struct global global = {
                .zlibmemlevel = 8,
                .zlibwindowsize = MAX_WBITS,
 #endif
+               .comp_maxlevel = 1,
 
 
        },
index 218e265f1fc25cc0cdd7d392c794aba4b40ab6ff..7f151076476462a3f92b6e153221318234abc410 100644 (file)
@@ -2088,9 +2088,11 @@ int select_compression_response_header(struct session *s, struct buffer *res)
        ctx.idx = 0;
 
        /* initialize compression */
-       if (s->comp_algo->init(&s->comp_ctx, 1) < 0)
+       if (s->comp_algo->init(&s->comp_ctx, global.tune.comp_maxlevel) < 0)
                goto fail;
 
+       s->comp_ctx.cur_lvl = global.tune.comp_maxlevel;
+
        /* remove Content-Length header */
        if ((msg->flags & HTTP_MSGF_CNT_LEN) && http_find_header2("Content-Length", 14, res->p, &txn->hdr_idx, &ctx))
                http_remove_header2(msg, &txn->hdr_idx, &ctx);