From bd9a0a77816a95ae1ff5598f372d91df02764c95 Mon Sep 17 00:00:00 2001 From: Willy Tarreau Date: Sun, 23 Oct 2011 21:14:29 +0200 Subject: OPTIM/MINOR: make it possible to change pipe size (tune.pipesize) By default, pipes are the default size for the system. But sometimes when using TCP splicing, it can improve performance to increase pipe sizes, especially if it is suspected that pipes are not filled and that many calls to splice() are performed. This has an impact on the kernel's memory footprint, so this must not be changed if impacts are not understood. --- doc/configuration.txt | 9 +++++++++ include/common/compat.h | 5 +++++ include/types/global.h | 1 + src/cfgparse.c | 8 ++++++++ src/pipe.c | 4 ++++ 5 files changed, 27 insertions(+), 0 deletions(-) diff --git a/doc/configuration.txt b/doc/configuration.txt index 653f013..5cce3b4 100644 --- a/doc/configuration.txt +++ b/doc/configuration.txt @@ -461,6 +461,7 @@ The following keywords are supported in the "global" section : - tune.maxaccept - tune.maxpollevents - tune.maxrewrite + - tune.pipesize - tune.rcvbuf.client - tune.rcvbuf.server - tune.sndbuf.client @@ -753,6 +754,14 @@ tune.maxrewrite larger than that. This means you don't have to worry about it when changing bufsize. +tune.pipesize + Sets the kernel pipe buffer size to this size (in bytes). By default, pipes + are the default size for the system. But sometimes when using TCP splicing, + it can improve performance to increase pipe sizes, especially if it is + suspected that pipes are not filled and that many calls to splice() are + performed. This has an impact on the kernel's memory footprint, so this must + not be changed if impacts are not understood. + tune.rcvbuf.client tune.rcvbuf.server Forces the kernel socket receive buffer size on the client or the server side diff --git a/include/common/compat.h b/include/common/compat.h index e134d58..80e1dd2 100644 --- a/include/common/compat.h +++ b/include/common/compat.h @@ -69,6 +69,11 @@ #define MAXPATHLEN 128 #endif +/* On Linux, allows pipes to be resized */ +#ifndef F_SETPIPE_SZ +#define F_SETPIPE_SZ (1024 + 7) +#endif + #if defined(TPROXY) && defined(NETFILTER) #include #include diff --git a/include/types/global.h b/include/types/global.h index a5c7fa0..078a1d5 100644 --- a/include/types/global.h +++ b/include/types/global.h @@ -96,6 +96,7 @@ struct global { 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 */ + int pipesize; /* pipe size in bytes, system defaults if zero */ } tune; struct { char *prefix; /* path prefix of unix bind socket */ diff --git a/src/cfgparse.c b/src/cfgparse.c index 39a289a..ed64457 100644 --- a/src/cfgparse.c +++ b/src/cfgparse.c @@ -587,6 +587,14 @@ int cfg_parse_global(const char *file, int linenum, char **args, int kwm) } global.tune.server_sndbuf = atol(args[1]); } + else if (!strcmp(args[0], "tune.pipesize")) { + 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.pipesize = atol(args[1]); + } 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/pipe.c b/src/pipe.c index ee6c92c..76ab8f9 100644 --- a/src/pipe.c +++ b/src/pipe.c @@ -58,6 +58,10 @@ struct pipe *get_pipe() pool_free2(pool2_pipe, ret); return NULL; } +#ifdef F_SETPIPE_SZ + if (global.tune.pipesize) + fcntl(pipefd[0], F_SETPIPE_SZ, global.tune.pipesize); +#endif ret->data = 0; ret->prod = pipefd[1]; ret->cons = pipefd[0]; -- 1.7.2.3