]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
[MEDIUM] don't limit peers nor stats socket to maxconn nor maxconnrate
authorWilly Tarreau <w@1wt.eu>
Wed, 7 Sep 2011 16:00:47 +0000 (18:00 +0200)
committerWilly Tarreau <w@1wt.eu>
Wed, 7 Sep 2011 20:47:42 +0000 (22:47 +0200)
The peers and the stats socket are control sockets, they must not be
limited by traffic rules.

include/types/protocols.h
src/cfgparse.c
src/dumpstats.c
src/haproxy.c
src/peers.c
src/session.c
src/stream_sock.c

index 80c1a6e02374ae37e56de516dab4db41b2193310..212ecef955ae8cd33858e27dc69b2fa357e34e2d 100644 (file)
@@ -84,6 +84,11 @@ enum {
 #define LI_O_TCP_RULES  0x0010  /* run TCP rules checks on the incoming connection */
 #define LI_O_CHK_MONNET 0x0020  /* check the source against a monitor-net rule */
 #define LI_O_ACC_PROXY  0x0040  /* find the proxied address in the first request line */
+#define LI_O_UNLIMITED  0x0080  /* listener not subject to global limits (peers & stats socket) */
+
+/* Note: if a listener uses LI_O_UNLIMITED, it is highly recommended that it adds its own
+ * maxconn setting to the global.maxsock value so that its resources are reserved.
+ */
 
 /* The listener will be directly referenced by the fdtab[] which holds its
  * socket. The listener provides the protocol-specific accept() function to
index f098a3158a243d6f235bde7d749285d2c3e9c328..45d9677d8cd653c1ca9b047d94d76aaee4fac0fb 100644 (file)
@@ -1278,6 +1278,8 @@ int cfg_parse_peers(const char *file, int linenum, char **args, int kwm)
                                curpeers->peers_fe->listen->frontend =  ((struct proxy *)curpeers->peers_fe);
                                curpeers->peers_fe->listen->handler = process_session;
                                curpeers->peers_fe->listen->analysers |=  ((struct proxy *)curpeers->peers_fe)->fe_req_ana;
+                               curpeers->peers_fe->listen->options |= LI_O_UNLIMITED; /* don't make the peers subject to global limits */
+                               global.maxsock += curpeers->peers_fe->listen->maxconn;
                        }
                }
        } /* neither "peer" nor "peers" */
index 6d97f5da5a9cb17b113b991d095c609404071529..964ba83b3629f6d94aa7d4c21fc21ad5239d0392 100644 (file)
@@ -206,7 +206,7 @@ static int stats_parse_global(char **args, int section_type, struct proxy *curpx
                }
 
                global.stats_sock.state = LI_INIT;
-               global.stats_sock.options = LI_O_NONE;
+               global.stats_sock.options = LI_O_UNLIMITED;
                global.stats_sock.accept = session_accept;
                global.stats_fe->accept = stats_accept;
                global.stats_sock.handler = process_session;
index 7aa9fd451d3f931a903d39ccac3be56ab3b263dd..f783c3d90689a0bdcdc0d43dad98e0f0b1ba3978 100644 (file)
@@ -68,6 +68,7 @@
 #include <types/global.h>
 #include <types/proto_tcp.h>
 #include <types/acl.h>
+#include <types/peers.h>
 
 #include <proto/auth.h>
 #include <proto/acl.h>
@@ -603,6 +604,18 @@ void init(int argc, char **argv)
        global.maxsock += global.maxconn * 2; /* each connection needs two sockets */
        global.maxsock += global.maxpipes * 2; /* each pipe needs two FDs */
 
+       if (global.stats_fe)
+               global.maxsock += global.stats_fe->maxconn;
+
+       if (peers) {
+               /* peers also need to bypass global maxconn */
+               struct peers *p = peers;
+
+               for (p = peers; p; p = p->next)
+                       if (p->peers_fe)
+                               global.maxsock += p->peers_fe->maxconn;
+       }
+
        if (global.tune.maxpollevents <= 0)
                global.tune.maxpollevents = MAX_POLL_EVENTS;
 
index 26a3154b7942f547c2e0118e0d735ef66d867970..bbe99d4935bbabf0926372aa957141a9d298e638 100644 (file)
@@ -1271,7 +1271,8 @@ static struct session *peer_session_create(struct peer *peer, struct peer_sessio
        l->nbconn++; /* warning! right now, it's up to the handler to decrease this */
        p->feconn++;/* beconn will be increased later */
        jobs++;
-       actconn++;
+       if (!(s->listener->options & LI_O_UNLIMITED))
+               actconn++;
        totalconn++;
 
        return s;
index a9dfef8e956d2f69e2f5d34f4bb8a1bb488b97aa..5032d889bb2327e1dec61c9dc2cf471334d2b0d3 100644 (file)
@@ -2086,7 +2086,8 @@ struct task *process_session(struct task *t)
        s->fe->feconn--;
        if (s->flags & SN_BE_ASSIGNED)
                s->be->beconn--;
-       actconn--;
+       if (!(s->listener->options & LI_O_UNLIMITED))
+               actconn--;
        jobs--;
        s->listener->nbconn--;
        if (s->listener->state == LI_FULL)
index 365f52b97f3fe6bb8021f5fab457fb1fff0de736..d673aba7d73fa9ea08b69b446f31b4a1f3f8db2f 100644 (file)
@@ -1156,7 +1156,7 @@ int stream_sock_accept(int fd)
                return 0;
        }
 
-       if (global.cps_lim) {
+       if (global.cps_lim && !(l->options & LI_O_UNLIMITED)) {
                int max = freq_ctr_remain(&global.conn_per_sec, global.cps_lim, 0);
 
                if (unlikely(!max)) {
@@ -1193,7 +1193,7 @@ int stream_sock_accept(int fd)
                struct sockaddr_storage addr;
                socklen_t laddr = sizeof(addr);
 
-               if (unlikely(actconn >= global.maxconn)) {
+               if (unlikely(actconn >= global.maxconn) && !(l->options & LI_O_UNLIMITED)) {
                        limit_listener(l, &global_listener_queue);
                        task_schedule(global_listener_queue_task, tick_add(now_ms, 1000)); /* try again in 1 second */
                        return 0;
@@ -1252,12 +1252,14 @@ int stream_sock_accept(int fd)
                }
 
                /* increase the per-process number of cumulated connections */
-               update_freq_ctr(&global.conn_per_sec, 1);
-               if (global.conn_per_sec.curr_ctr > global.cps_max)
-                       global.cps_max = global.conn_per_sec.curr_ctr;
+               if (!(l->options & LI_O_UNLIMITED)) {
+                       update_freq_ctr(&global.conn_per_sec, 1);
+                       if (global.conn_per_sec.curr_ctr > global.cps_max)
+                               global.cps_max = global.conn_per_sec.curr_ctr;
+                       actconn++;
+               }
 
                jobs++;
-               actconn++;
                totalconn++;
                l->nbconn++;
 
@@ -1273,8 +1275,9 @@ int stream_sock_accept(int fd)
                         * error due to a resource shortage, and we must stop the
                         * listener (ret < 0).
                         */
+                       if (!(l->options & LI_O_UNLIMITED))
+                               actconn--;
                        jobs--;
-                       actconn--;
                        l->nbconn--;
                        if (ret == 0) /* successful termination */
                                continue;