]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
MINOR: servers: Add a counter for the number of currently used connections.
authorOlivier Houchard <cognet@ci0.org>
Wed, 25 Mar 2020 18:41:03 +0000 (19:41 +0100)
committerOlivier Houchard <cognet@ci0.org>
Sun, 29 Mar 2020 22:30:01 +0000 (00:30 +0200)
Add a counter to know the current number of used connections, as well as the
max, this will be used later to refine the algorithm used to kill idle
connections, based on current usage.

include/proto/connection.h
include/proto/server.h
include/types/server.h
src/backend.c

index f05a4524a427cf77b1b152e3908d9ce9826b45a2..30730f0ce19e8264d2286512f9b76e410497c3f5 100644 (file)
@@ -479,6 +479,11 @@ static inline void conn_free(struct connection *conn)
                _HA_ATOMIC_SUB(&srv->curr_idle_conns, 1);
                _HA_ATOMIC_SUB(conn->flags & CO_FL_SAFE_LIST ? &srv->curr_safe_nb : &srv->curr_idle_nb, 1);
                _HA_ATOMIC_SUB(&srv->curr_idle_thr[tid], 1);
+       } else {
+               struct server *srv = objt_server(conn->target);
+
+               if (srv)
+                       _HA_ATOMIC_SUB(&srv->curr_used_conns, 1);
        }
 
        conn_force_unsubscribe(conn);
index 575e922811bd401b27a807b7eefe5f4b5736a354..2847a8cf254269d8fd51647ded72e2c391693828 100644 (file)
@@ -261,6 +261,7 @@ static inline int srv_add_to_idle_list(struct server *srv, struct connection *co
                        _HA_ATOMIC_SUB(&srv->curr_idle_conns, 1);
                        return 0;
                }
+               _HA_ATOMIC_SUB(&srv->curr_used_conns, 1);
                MT_LIST_DEL(&conn->list);
                conn->idle_time = now_ms;
                if (is_safe) {
index 0ffebb4752d1dd2122d24e4c94aeff0fd0b16574..1e5e031a7d25bc392e281ef74df893b0c47efb2e 100644 (file)
@@ -230,6 +230,8 @@ struct server {
        unsigned int curr_idle_conns;           /* Current number of orphan idling connections, both the idle and the safe lists */
        unsigned int curr_idle_nb;              /* Current number of connections in the idle list */
        unsigned int curr_safe_nb;              /* Current number of connections in the safe list */
+       unsigned int curr_used_conns;           /* Current number of used connections */
+       unsigned int max_used_conns;            /* Max number of used connections (the counter is resetted at each connection purges */
        unsigned int *curr_idle_thr;            /* Current number of orphan idling connections per thread */
        int max_reuse;                          /* Max number of requests on a same connection */
        struct eb32_node idle_node;             /* When to next do cleanup in the idle connections */
index d500a8ae72180dbd2033a0c239a8126610e50b5e..ccf06b8171a5301ea52c36538eae019e84ac33d9 100644 (file)
@@ -1350,6 +1350,14 @@ int connect_server(struct stream *s)
                srv_cs = NULL;
        }
 
+       if (srv_conn && srv) {
+               _HA_ATOMIC_ADD(&srv->curr_used_conns, 1);
+               /* It's ok not to do that atomically, we don't need an
+                * exact max.
+                */
+               if (srv->max_used_conns < srv->curr_used_conns)
+                       srv->max_used_conns = srv->curr_used_conns;
+       }
        if (!srv_conn || !sockaddr_alloc(&srv_conn->dst)) {
                if (srv_conn)
                        conn_free(srv_conn);