From a3187fe06c74c80a29a8c790b6d768e76dcb2b04 Mon Sep 17 00:00:00 2001 From: Amaury Denoyelle Date: Wed, 22 Nov 2023 17:55:58 +0100 Subject: [PATCH] MINOR: rhttp: add count of active conns per thread Add a new member 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 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 | 1 + src/connection.c | 5 +++++ src/proto_rhttp.c | 13 +++++++++++++ 3 files changed, 19 insertions(+) diff --git a/include/haproxy/tinfo-t.h b/include/haproxy/tinfo-t.h index fc8514305d..357c4c0aae 100644 --- a/include/haproxy/tinfo-t.h +++ b/include/haproxy/tinfo-t.h @@ -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 */ diff --git a/src/connection.c b/src/connection.c index 340fa4f22a..7930cc41c3 100644 --- a/src/connection.c +++ b/src/connection.c @@ -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); diff --git a/src/proto_rhttp.c b/src/proto_rhttp.c index a60caa7d6e..52d45441fe 100644 --- a/src/proto_rhttp.c +++ b/src/proto_rhttp.c @@ -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);