From 43961d523fe6748487be7e82ac5d38b537938bfe Mon Sep 17 00:00:00 2001 From: Willy Tarreau Date: Mon, 4 Oct 2010 20:39:20 +0200 Subject: [PATCH] [MINOR] global: add "tune.chksize" to change the default check buffer size HTTP content-based health checks will be involved in searching text in pages. Some pages may not fit in the default buffer (16kB) and sometimes it might be desired to have larger buffers in order to find patterns. Running checks on smaller URIs is always preferred of course. (cherry picked from commit 043f44aeb835f3d0b57626c4276581a73600b6b1) --- doc/configuration.txt | 8 ++++++++ include/types/global.h | 1 + src/cfgparse.c | 10 +++++++++- src/checks.c | 6 +++--- src/haproxy.c | 1 + 5 files changed, 22 insertions(+), 4 deletions(-) diff --git a/doc/configuration.txt b/doc/configuration.txt index 9a7c0e37a..04cd5c90e 100644 --- a/doc/configuration.txt +++ b/doc/configuration.txt @@ -454,6 +454,7 @@ The following keywords are supported in the "global" section : - nosplice - spread-checks - tune.bufsize + - tune.chksize - tune.maxaccept - tune.maxpollevents - tune.maxrewrite @@ -672,6 +673,13 @@ tune.bufsize possibly causing the system to run out of memory. At least the global maxconn parameter should be decreased by the same factor as this one is increased. +tune.chksize + Sets the check buffer size to this size (in bytes). Higher values may help + find string or regex patterns in very large pages, though doing so may imply + more memory and CPU usage. The default value is 16384 and can be changed at + build time. It is not recommended to change this value, but to use better + checks whenever possible. + tune.maxaccept Sets the maximum number of consecutive accepts that a process may perform on a single wake up. High values give higher priority to high connection rates, diff --git a/include/types/global.h b/include/types/global.h index fdc151632..4469ef86b 100644 --- a/include/types/global.h +++ b/include/types/global.h @@ -91,6 +91,7 @@ struct global { int client_rcvbuf; /* set client rcvbuf to this value if not null */ int server_sndbuf; /* set server sndbuf to this value if not null */ int server_rcvbuf; /* set server rcvbuf to this value if not null */ + int chksize; /* check buffer size in bytes, defaults to BUFSIZE */ } tune; struct listener stats_sock; /* unix socket listener for statistics */ struct proxy *stats_fe; /* the frontend holding the stats settings */ diff --git a/src/cfgparse.c b/src/cfgparse.c index 91d134fa3..3cf1e4af0 100644 --- a/src/cfgparse.c +++ b/src/cfgparse.c @@ -496,6 +496,14 @@ int cfg_parse_global(const char *file, int linenum, char **args, int kwm) } global.tune.maxaccept = atol(args[1]); } + else if (!strcmp(args[0], "tune.chksize")) { + if (*(args[1]) == 0) { + Alert("parsing [%s:%d] : '%s' expects an integer argument.\n", file, linenum, args[0]); + err_code |= ERR_ALERT | ERR_FATAL; + goto out; + } + global.tune.chksize = atol(args[1]); + } else if (!strcmp(args[0], "tune.bufsize")) { if (*(args[1]) == 0) { Alert("parsing [%s:%d] : '%s' expects an integer argument.\n", file, linenum, args[0]); @@ -3786,7 +3794,7 @@ stats_error_parsing: } /* Allocate buffer for partial check results... */ - if ((newsrv->check_data = calloc(BUFSIZE, sizeof(char))) == NULL) { + if ((newsrv->check_data = calloc(global.tune.chksize, sizeof(char))) == NULL) { Alert("parsing [%s:%d] : out of memory while allocating check buffer.\n", file, linenum); err_code |= ERR_ALERT | ERR_ABORT; goto out; diff --git a/src/checks.c b/src/checks.c index 502d90586..cd4dd30d9 100644 --- a/src/checks.c +++ b/src/checks.c @@ -890,8 +890,8 @@ static int event_srv_chk_r(int fd) */ done = 0; - for (len = 0; s->check_data_len < BUFSIZE; s->check_data_len += len) { - len = recv(fd, s->check_data + s->check_data_len, BUFSIZE - s->check_data_len, 0); + for (len = 0; s->check_data_len < global.tune.chksize; s->check_data_len += len) { + len = recv(fd, s->check_data + s->check_data_len, global.tune.chksize - s->check_data_len, 0); if (len <= 0) break; } @@ -915,7 +915,7 @@ static int event_srv_chk_r(int fd) /* Intermediate or complete response received. * Terminate string in check_data buffer. */ - if (s->check_data_len < BUFSIZE) + if (s->check_data_len < global.tune.chksize) s->check_data[s->check_data_len] = '\0'; else { s->check_data[s->check_data_len - 1] = '\0'; diff --git a/src/haproxy.c b/src/haproxy.c index 2298ee141..c8f0a38f1 100644 --- a/src/haproxy.c +++ b/src/haproxy.c @@ -117,6 +117,7 @@ struct global global = { .tune = { .bufsize = BUFSIZE, .maxrewrite = MAXREWRITE, + .chksize = BUFSIZE, }, /* others NULL OK */ };