]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
MEDIUM: servers: Be smarter when switching connections.
authorOlivier Houchard <ohouchard@haproxy.com>
Fri, 28 Dec 2018 15:20:25 +0000 (16:20 +0100)
committerWilly Tarreau <w@1wt.eu>
Fri, 28 Dec 2018 15:34:03 +0000 (16:34 +0100)
When connecting to a server, and reusing a connection, always attempt to give
the owner of the previous session one of its own connections, so that one
session won't be responsible for too many connections.

This should be backported to 1.9.

src/backend.c

index c4711ead88bb1c01c1c17126412e5a5bc8334b1e..b6f08d5e7a38d0ea1b0fdbee40f9f9d45384caa2 100644 (file)
@@ -1245,27 +1245,20 @@ int connect_server(struct stream *s)
        /* We're about to use another connection, let the mux know we're
         * done with this one
         */
-       if (old_conn != srv_conn || !reuse) {
-
-               if (srv_conn && reuse) {
-                       struct session *sess = srv_conn->owner;
-
-                       if (sess) {
-                               if (old_conn &&
-                                   !(old_conn->flags & CO_FL_PRIVATE) &&
-                                   old_conn->mux != NULL &&
-                                   (old_conn->mux->avail_streams(old_conn) > 0) &&
-                                   (srv_conn->mux->avail_streams(srv_conn) == 1)) {
-                                       session_unown_conn(s->sess, old_conn);
-                                       old_conn->owner = sess;
-                                       if (!session_add_conn(sess, old_conn, s->target)) {
-                                               old_conn->owner = NULL;
-                                               old_conn->mux->destroy(old_conn);
-                                       } else
-                                               session_check_idle_conn(sess, old_conn);
-                               }
+       if (old_conn != srv_conn && old_conn && reuse && !reuse_orphan) {
+               struct session *sess = srv_conn->owner;
+
+               if (sess) {
+                       if (old_conn && !(old_conn->flags & CO_FL_PRIVATE) &&
+                           old_conn->mux != NULL) {
+                               session_unown_conn(s->sess, old_conn);
+                               old_conn->owner = sess;
+                               if (!session_add_conn(sess, old_conn, s->target)) {
+                                       old_conn->owner = NULL;
+                                       old_conn->mux->destroy(old_conn);
+                               } else
+                                       session_check_idle_conn(sess, old_conn);
                        }
-
                }
        }