]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
[MEDIUM] stats: add the "set maxconn" setting to the command line interface
authorWilly Tarreau <w@1wt.eu>
Wed, 7 Sep 2011 12:38:31 +0000 (14:38 +0200)
committerWilly Tarreau <w@1wt.eu>
Wed, 7 Sep 2011 20:47:41 +0000 (22:47 +0200)
This option permits to change the global maxconn setting within the
limit that was set by the initial value, which is now reported as the
hard maxconn value. This allows to immediately accept more concurrent
connections or to stop accepting new ones until the value passes below
the indicated setting.

The main use of this option is on systems where many haproxy instances
are loaded and admins need to re-adjust resource sharing at run time
to regain a bit of fairness between processes.

doc/configuration.txt
include/types/global.h
src/dumpstats.c

index 98d021e610388e097f7a45415c7f2d093cea586f..becdab745bff8ba0b977fec9bdd31ade6075fd99 100644 (file)
@@ -9561,6 +9561,14 @@ set maxconn frontend <frontend> <value>
   delayed until the threshold is reached. The frontend might be specified by
   either its name or its numeric ID prefixed with a sharp ('#').
 
+set maxconn global <maxconn>
+  Dynamically change the global maxconn setting within the range defined by the
+  initial global maxconn setting. If it is increased and connections were
+  pending, they will immediately be accepted. If it is lowered to a value below
+  the current number of connections, new connections acceptation will be
+  delayed until the threshold is reached. A value of zero restores the initial
+  setting.
+
 set timeout cli <delay>
   Change the CLI interface timeout for current connection. This can be useful
   during long debugging sessions where the user needs to constantly inspect
index 94e21a28b2a7c36e23a47bfd4405e53b94a8bb34..cdd1bc478e6b256eaf231b53a167b91ee92bbe87 100644 (file)
@@ -65,7 +65,7 @@ struct global {
        int uid;
        int gid;
        int nbproc;
-       int maxconn;
+       int maxconn, hardmaxconn;
        int maxpipes;           /* max # of pipes */
        int maxsock;            /* max # of sockets */
        int rlimit_nofile;      /* default ulimit-n value : 0=unset */
index feeb8509134e7a84d9d1cb578adeeb05deeb2a64..c9c40557a08a21b42008faab7ba8f233fbf58758 100644 (file)
@@ -1020,8 +1020,42 @@ static int stats_sock_parse_request(struct stream_interface *si, char *line)
 
                                return 1;
                        }
+                       else if (strcmp(args[2], "global") == 0) {
+                               int v;
+
+                               if (s->listener->perm.ux.level < ACCESS_LVL_ADMIN) {
+                                       si->applet.ctx.cli.msg = stats_permission_denied_msg;
+                                       si->applet.st0 = STAT_CLI_PRINT;
+                                       return 1;
+                               }
+
+                               if (!*args[3]) {
+                                       si->applet.ctx.cli.msg = "Expects an integer value.\n";
+                                       si->applet.st0 = STAT_CLI_PRINT;
+                                       return 1;
+                               }
+
+                               v = atoi(args[3]);
+                               if (v > global.hardmaxconn) {
+                                       si->applet.ctx.cli.msg = "Value out of range.\n";
+                                       si->applet.st0 = STAT_CLI_PRINT;
+                                       return 1;
+                               }
+
+                               /* check for unlimited values */
+                               if (v <= 0)
+                                       v = global.hardmaxconn;
+
+                               global.maxconn = v;
+
+                               /* Dequeues all of the listeners waiting for a resource */
+                               if (!LIST_ISEMPTY(&global_listener_queue))
+                                       dequeue_all_listeners(&global_listener_queue);
+
+                               return 1;
+                       }
                        else {
-                               si->applet.ctx.cli.msg = "'set maxconn' only supports 'frontend'.\n";
+                               si->applet.ctx.cli.msg = "'set maxconn' only supports 'frontend' and 'global'.\n";
                                si->applet.st0 = STAT_CLI_PRINT;
                                return 1;
                        }
@@ -1393,6 +1427,7 @@ static int stats_dump_raw_to_buffer(struct stream_interface *si)
                                     "Ulimit-n: %d\n"
                                     "Maxsock: %d\n"
                                     "Maxconn: %d\n"
+                                    "Hard_maxconn: %d\n"
                                     "Maxpipes: %d\n"
                                     "CurrConns: %d\n"
                                     "PipesUsed: %d\n"
@@ -1409,7 +1444,7 @@ static int stats_dump_raw_to_buffer(struct stream_interface *si)
                                     up,
                                     global.rlimit_memmax,
                                     global.rlimit_nofile,
-                                    global.maxsock, global.maxconn, global.maxpipes,
+                                    global.maxsock, global.maxconn, global.hardmaxconn, global.maxpipes,
                                     actconn, pipes_used, pipes_free,
                                     nb_tasks_cur, run_queue_cur,
                                     global.node, global.desc?global.desc:""