MINOR: compression: tune.comp.maxlevel

This option allows you to set the maximum compression level usable by
the compression algorithm. It affects CPU usage.
This commit is contained in:
William Lallemand 2012-11-09 12:33:10 +01:00 committed by Willy Tarreau
parent 0a410e81fb
commit f3747837e5
6 changed files with 29 additions and 1 deletions

View 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

View File

@ -44,6 +44,7 @@ struct comp_ctx {
void *zlib_pending_buf;
void *zlib_head;
#endif /* USE_ZLIB */
int cur_lvl;
};
struct comp_algo {

View 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 */

View 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);

View File

@ -131,6 +131,7 @@ struct global global = {
.zlibmemlevel = 8,
.zlibwindowsize = MAX_WBITS,
#endif
.comp_maxlevel = 1,
},

View 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);