]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
MINOR: rhttp: add count of active conns per thread
authorAmaury Denoyelle <adenoyelle@haproxy.com>
Wed, 22 Nov 2023 16:55:58 +0000 (17:55 +0100)
committerAmaury Denoyelle <adenoyelle@haproxy.com>
Thu, 23 Nov 2023 16:43:01 +0000 (17:43 +0100)
Add a new member <nb_rhttp_conns> in thread_ctx structure. Its purpose
is to count the current number of opened reverse HTTP connections
regarding from their listeners membership.

This patch will be useful to support multi-thread for active reverse
HTTP, in order to select the less loaded thread.

Note that despite access to <nb_rhttp_conns> are only done by the
current thread, atomic operations are used. This is because once
multi-thread support will be added, external threads will also retrieve
values from others.

include/haproxy/tinfo-t.h
src/connection.c
src/proto_rhttp.c

index fc8514305d818bf8f862b7532e5b10906c6a1a76..357c4c0aae412be6a17dbd369c16bb7797e6c516 100644 (file)
@@ -141,6 +141,7 @@ struct thread_ctx {
        struct list quic_conns;             /* list of active quic-conns attached to this thread */
        struct list quic_conns_clo;         /* list of closing quic-conns attached to this thread */
        struct list queued_checks;          /* checks waiting for a connection slot */
+       unsigned int nb_rhttp_conns;        /* count of current conns used for active reverse HTTP */
 
        ALWAYS_ALIGN(2*sizeof(void*));
        struct list tasklets[TL_CLASSES];   /* tasklets (and/or tasks) to run, by class */
index 340fa4f22a2ae4b336c597e8eaca88bc36a66cf0..7930cc41c3f79f4db1b389bfbbf25d552fad0d08 100644 (file)
@@ -592,7 +592,12 @@ void conn_free(struct connection *conn)
        if (conn_reverse_in_preconnect(conn)) {
                struct listener *l = conn_active_reverse_listener(conn);
                rhttp_notify_preconn_err(l);
+               HA_ATOMIC_DEC(&th_ctx->nb_rhttp_conns);
        }
+       else if (conn->flags & CO_FL_REVERSED) {
+               HA_ATOMIC_DEC(&th_ctx->nb_rhttp_conns);
+       }
+
 
        conn_force_unsubscribe(conn);
        pool_free(pool_head_connection, conn);
index a60caa7d6e60ca33140a44d29ea1652ffcf4dd40..52d45441fee7f2cf70331dfe3d11229d99203b68 100644 (file)
@@ -56,6 +56,8 @@ static struct connection *new_reverse_conn(struct listener *l, struct server *sr
        if (!conn)
                goto err;
 
+       HA_ATOMIC_INC(&th_ctx->nb_rhttp_conns);
+
        conn_set_reverse(conn, &l->obj_type);
 
        if (alloc_bind_address(&bind_addr, srv, srv->proxy, NULL) != SRV_STATUS_OK)
@@ -376,3 +378,14 @@ int rhttp_accepting_conn(const struct receiver *rx)
 }
 
 INITCALL1(STG_REGISTER, protocol_register, &proto_rhttp);
+
+/* perform minimal intializations */
+static void init_rhttp()
+{
+       int i;
+
+       for (i = 0; i < MAX_THREADS; i++)
+               ha_thread_ctx[i].nb_rhttp_conns = 0;
+}
+
+INITCALL0(STG_PREPARE, init_rhttp);