diff --git a/doc/configuration.txt b/doc/configuration.txt index c6eed082e..f624abbbc 100644 --- a/doc/configuration.txt +++ b/doc/configuration.txt @@ -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 build time. It is not recommended to change this value, but to use better checks whenever possible. +tune.comp.maxlevel + 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 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 diff --git a/include/types/compression.h b/include/types/compression.h index fa251f1b8..da356ad0a 100644 --- a/include/types/compression.h +++ b/include/types/compression.h @@ -44,6 +44,7 @@ struct comp_ctx { void *zlib_pending_buf; void *zlib_head; #endif /* USE_ZLIB */ + int cur_lvl; }; struct comp_algo { diff --git a/include/types/global.h b/include/types/global.h index e4e317bd2..cfb10d1f1 100644 --- a/include/types/global.h +++ b/include/types/global.h @@ -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 */ diff --git a/src/cfgparse.c b/src/cfgparse.c index d5ada1dcf..5f22b2424 100644 --- a/src/cfgparse.c +++ b/src/cfgparse.c @@ -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); diff --git a/src/haproxy.c b/src/haproxy.c index d0e740b7d..b322244fc 100644 --- a/src/haproxy.c +++ b/src/haproxy.c @@ -131,6 +131,7 @@ struct global global = { .zlibmemlevel = 8, .zlibwindowsize = MAX_WBITS, #endif + .comp_maxlevel = 1, }, diff --git a/src/proto_http.c b/src/proto_http.c index 218e265f1..7f1510764 100644 --- a/src/proto_http.c +++ b/src/proto_http.c @@ -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);