]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
MINOR: config: implement global setting tune.buffers.limit
authorWilly Tarreau <w@1wt.eu>
Tue, 23 Dec 2014 21:52:37 +0000 (22:52 +0100)
committerWilly Tarreau <w@1wt.eu>
Wed, 24 Dec 2014 22:47:33 +0000 (23:47 +0100)
This setting is used to limit memory usage without causing the alloc
failures caused by "-m". Unexpectedly, tests have shown a performance
boost of up to about 18% on HTTP traffic when limiting the number of
buffers to about 10% of the amount of concurrent connections.

tune.buffers.limit <number>
  Sets a hard limit on the number of buffers which may be allocated per process.
  The default value is zero which means unlimited. The minimum non-zero value
  will always be greater than "tune.buffers.reserve" and should ideally always
  be about twice as large. Forcing this value can be particularly useful to
  limit the amount of memory a process may take, while retaining a sane
  behaviour. When this limit is reached, sessions which need a buffer wait for
  another one to be released by another session. Since buffers are dynamically
  allocated and released, the waiting time is very short and not perceptible
  provided that limits remain reasonable. In fact sometimes reducing the limit
  may even increase performance by increasing the CPU cache's efficiency. Tests
  have shown good results on average HTTP traffic with a limit to 1/10 of the
  expected global maxconn setting, which also significantly reduces memory
  usage. The memory savings come from the fact that a number of connections
  will not allocate 2*tune.bufsize. It is best not to touch this value unless
  advised to do so by an haproxy core developer.

doc/configuration.txt
include/types/global.h
src/buffer.c
src/cfgparse.c

index d3f049eab70f0445301c558024e0f0ff05c471db..d8063babebc5273ff6ed3b69c10118d9e9588aeb 100644 (file)
@@ -891,6 +891,23 @@ spread-checks <0..50, in percent>
   and +/- 50%. A value between 2 and 5 seems to show good results. The
   default value remains at 0.
 
+tune.buffers.limit <number>
+  Sets a hard limit on the number of buffers which may be allocated per process.
+  The default value is zero which means unlimited. The minimum non-zero value
+  will always be greater than "tune.buffers.reserve" and should ideally always
+  be about twice as large. Forcing this value can be particularly useful to
+  limit the amount of memory a process may take, while retaining a sane
+  behaviour. When this limit is reached, sessions which need a buffer wait for
+  another one to be released by another session. Since buffers are dynamically
+  allocated and released, the waiting time is very short and not perceptible
+  provided that limits remain reasonable. In fact sometimes reducing the limit
+  may even increase performance by increasing the CPU cache's efficiency. Tests
+  have shown good results on average HTTP traffic with a limit to 1/10 of the
+  expected global maxconn setting, which also significantly reduces memory
+  usage. The memory savings come from the fact that a number of connections
+  will not allocate 2*tune.bufsize. It is best not to touch this value unless
+  advised to do so by an haproxy core developer.
+
 tune.buffers.reserve <number>
   Sets the number of buffers which are pre-allocated and reserved for use only
   during memory shortage conditions resulting in failed memory allocations. The
index 143b8647a395ea7bdbf15f89b5408ae1b838d658..22490b06b53d40a9882757d9dca2d78d58ddfae4 100644 (file)
@@ -129,6 +129,7 @@ struct global {
                int bufsize;       /* buffer size in bytes, defaults to BUFSIZE */
                int maxrewrite;    /* buffer max rewrite size in bytes, defaults to MAXREWRITE */
                int reserved_bufs; /* how many buffers can only be allocated for response */
+               int buf_limit;     /* if not null, how many total buffers may only be allocated */
                int client_sndbuf; /* set client sndbuf to this value if not null */
                int client_rcvbuf; /* set client rcvbuf to this value if not null */
                int server_sndbuf; /* set server sndbuf to this value if not null */
index c7326dcd63c566ebdfc73b255b37fa4095f48adf..e156991e6ce5a96a8ef5ba71a4e9e79c755a0862 100644 (file)
@@ -48,6 +48,8 @@ int init_buffer()
         * release a server connection).
         */
        pool2_buffer->minavail = MAX(global.tune.reserved_bufs, 3);
+       if (global.tune.buf_limit)
+               pool2_buffer->limit = global.tune.buf_limit;
 
        buffer = pool_refill_alloc(pool2_buffer, pool2_buffer->minavail - 1);
        if (!buffer)
index ad0b44bf86aa133063553dc3f114a2241480262e..99ac8a4266d6960bb07a163d849f4c7058193ce8 100644 (file)
@@ -696,6 +696,20 @@ int cfg_parse_global(const char *file, int linenum, char **args, int kwm)
                }
        }
 #endif
+       else if (!strcmp(args[0], "tune.buffers.limit")) {
+               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.buf_limit = atol(args[1]);
+               if (global.tune.buf_limit) {
+                       if (global.tune.buf_limit < 3)
+                               global.tune.buf_limit = 3;
+                       if (global.tune.buf_limit <= global.tune.reserved_bufs)
+                               global.tune.buf_limit = global.tune.reserved_bufs + 1;
+               }
+       }
        else if (!strcmp(args[0], "tune.buffers.reserve")) {
                if (*(args[1]) == 0) {
                        Alert("parsing [%s:%d] : '%s' expects an integer argument.\n", file, linenum, args[0]);
@@ -705,6 +719,8 @@ int cfg_parse_global(const char *file, int linenum, char **args, int kwm)
                global.tune.reserved_bufs = atol(args[1]);
                if (global.tune.reserved_bufs < 2)
                        global.tune.reserved_bufs = 2;
+               if (global.tune.buf_limit && global.tune.buf_limit <= global.tune.reserved_bufs)
+                       global.tune.buf_limit = global.tune.reserved_bufs + 1;
        }
        else if (!strcmp(args[0], "tune.bufsize")) {
                if (*(args[1]) == 0) {