]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
MAJOR: backend: enable connection reuse
authorWilly Tarreau <w@1wt.eu>
Sun, 15 Dec 2013 15:33:46 +0000 (16:33 +0100)
committerWilly Tarreau <w@1wt.eu>
Mon, 16 Dec 2013 01:23:54 +0000 (02:23 +0100)
This commit allows an existing server-side connection to be reused if
it matches the same target. Basic controls are performed ; right now
we do not allow to reuse a connection when dynamic source binding is
in use or when the destination address or port is dynamic (eg: proxy
mode). Later we'll have to also disable connection sharing when PROXY
protocol is being used or when non-idempotent requests are processed.

src/backend.c

index 657da9d256960791b4138fac5b347ee49ee33e5e..7eeed8dc08eefe7f61ed3fdd010b6cfae7edbbe4 100644 (file)
@@ -982,10 +982,33 @@ static void assign_tproxy_address(struct session *s)
 int connect_server(struct session *s)
 {
        struct connection *cli_conn;
-       struct connection *srv_conn = si_alloc_conn(s->req->cons, 0);
+       struct connection *srv_conn;
        struct server *srv;
+       int reuse = 0;
        int err;
 
+       srv_conn = objt_conn(s->req->cons->end);
+       if (srv_conn)
+               reuse = s->target == srv_conn->target;
+
+       if (reuse) {
+               /* Disable connection reuse if a dynamic source is used.
+                * As long as we don't share connections between servers,
+                * we don't need to disable connection reuse on no-idempotent
+                * requests nor when PROXY protocol is used.
+                */
+               srv = objt_server(s->target);
+               if (srv && srv->conn_src.opts & CO_SRC_BIND) {
+                       if ((srv->conn_src.opts & CO_SRC_TPROXY_MASK) == CO_SRC_TPROXY_DYN)
+                               reuse = 0;
+               }
+               else if (s->be->conn_src.opts & CO_SRC_BIND) {
+                       if ((s->be->conn_src.opts & CO_SRC_TPROXY_MASK) == CO_SRC_TPROXY_DYN)
+                               reuse = 0;
+               }
+       }
+
+       srv_conn = si_alloc_conn(s->req->cons, reuse);
        if (!srv_conn)
                return SN_ERR_RESOURCE;