]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
OPTIM/MEDIUM: proxy: avoid main proxies list reordering on startup
authorAmaury Denoyelle <adenoyelle@haproxy.com>
Wed, 22 Jul 2026 14:13:42 +0000 (16:13 +0200)
committerAmaury Denoyelle <adenoyelle@haproxy.com>
Thu, 23 Jul 2026 14:03:20 +0000 (16:03 +0200)
Prior to this patch, proxies were added in front ot the visible proxies
list, resulting in the reverse order of their parsing. The list was then
reversed once parsing was completed to reflect the configuration order.
This was performed for performance reason, as visible proxies list was
simply linked.

This list has recently been converted to a doubly linked struct list.
Thus, it is now possible to append a newly parsed proxy at the end of
the list in constant time.

Thus, with this patch, a newly parsed instance is now directly inserted
at the end of main proxies list. This is implemented by updating
main_proxies_register() wrapper. Post-config performance are slightly
improved as reversal is now unneeded.

include/haproxy/proxy.h
src/cfgparse.c
src/proxy.c

index a1720566f8d789cf68a4238b1cc291828f3ed305..9b6fa5b9ea41fd0728b55d6ce3a4caa37f2a0f65 100644 (file)
@@ -314,13 +314,10 @@ static inline void increment_send_rate(uint64_t bytes, int splice)
        update_freq_ctr(&th_ctx->out_32bps, (bytes + 16) / 32);
 }
 
-/* Insert <px> at the front of the global list of visible proxies. This should
- * only be used during configuration parsing. At runtime, a newly added proxy
- * should be appended at the end of the list instead.
- */
+/* Append <px> at the end of the global list of visible proxies. */
 static inline void main_proxies_register(struct proxy *px)
 {
-       LIST_INSERT(&main_proxies, &px->el);
+       LIST_APPEND(&main_proxies, &px->el);
 }
 
 /* Returns first entry in main proxies list or NULL if empty. */
index 3a7a533fc9ad9ff54eafc8a3bbdb8cf2473cacf7..57d4bc54bed7fe1ca623b71de800f58649ae98b9 100644 (file)
@@ -2295,9 +2295,8 @@ static struct proxy *_get_next_proxy(void *head, struct proxy *cur)
  */
 int check_config_validity()
 {
-       struct list tmp_list = LIST_HEAD_INIT(tmp_list);
        int cfgerr = 0, ret;
-       struct proxy *defpx, *old;
+       struct proxy *defpx;
        void *init_proxies_list = NULL;
        struct stktable *t;
        struct server *newsrv = NULL;
@@ -2386,13 +2385,6 @@ int check_config_validity()
        if (err_code != ERR_NONE)
                goto out;
 
-       /* first, we will invert the proxy list order */
-       list_for_each_entry_safe(curproxy, old, &main_proxies, el) {
-               LIST_DELETE(&curproxy->el);
-               LIST_INSERT(&tmp_list, &curproxy->el);
-       }
-       LIST_SPLICE(&main_proxies, &tmp_list);
-
        /*
         * we must finish to initialize certain things on the servers,
         * as some of the fields may be accessed soon
index eaab91f6f5a42ea206e012a8005c46f05bf14492..af90dcbbf9f7e7359aa7b9f0199b920ce5740c63 100644 (file)
@@ -4977,8 +4977,11 @@ static int cli_parse_add_backend(char **args, char *payload, struct appctx *appc
        proxy_index_id(px);
        dynpx_next_id = px->uuid;
 
-       LIST_APPEND(&main_proxies, &px->el);
-
+       /* Insert <px> into <main_proxies> list of visible proxies. Note that
+        * insertion in <proxies> has already been performed in
+        * setup_new_proxy() via alloc_new_proxy().
+        */
+       main_proxies_register(px);
        thread_release();
 
        if (unlikely(!be_supports_dynamic_srv(px, &msg)))