]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
MAJOR: backend: switch the default balancing algo to "random"
authorWilly Tarreau <w@1wt.eu>
Thu, 4 Sep 2025 06:23:30 +0000 (08:23 +0200)
committerWilly Tarreau <w@1wt.eu>
Thu, 4 Sep 2025 06:30:35 +0000 (08:30 +0200)
For many years, an unset load balancing algorithm would use "roundrobin".
It was shown several times that "random" with at least 2 draws (the
default) generally provides better performance and fairness in that
it will automatically adapt to the server's load and capacity. This
was further described with numbers in this discussion:

  https://www.mail-archive.com/haproxy@formilux.org/msg46011.html
  https://github.com/orgs/haproxy/discussions/3042

BTW there were no objection and only support for the change.

The goal of this patch is to change the default algo when none is
specified, from "roundrobin" to "random". This way, users who don't
care and don't set the load balancing algorithm will benefit from a
better one in most cases, while those who have good reasons to prefer
roundrobin (for session affinity or for reproducible sequences like used
in regtests) can continue to specify it.

The vast majority of users should not notice a difference.

doc/configuration.txt
src/backend.c
src/cfgparse.c

index b88de47e55ea4e1c1b5e040764dc497dbf8ff6d3..a364d7e13136646118780971359b0979c8cde4e7 100644 (file)
@@ -6010,7 +6010,7 @@ balance url_param <param> [check_post]
                 algorithms. Right now, only "url_param", "uri" and "log-hash"
                 support an optional argument.
 
-  The load balancing algorithm of a backend is set to roundrobin when no other
+  The load balancing algorithm of a backend is set to "random" when no other
   algorithm, mode nor option have been set. The algorithm may only be set once
   for each backend.
 
index 3b4aef681d1d65c879b71e056967744e690d6d35..aa5052936802e3013fb4b7e01bc5c80fcbaed01f 100644 (file)
@@ -3018,9 +3018,9 @@ const char *backend_lb_algo_str(int algo) {
 int backend_parse_balance(const char **args, char **err, struct proxy *curproxy)
 {
        if (!*(args[0])) {
-               /* if no option is set, use round-robin by default */
+               /* if no option is set, use random by default */
                curproxy->lbprm.algo &= ~BE_LB_ALGO;
-               curproxy->lbprm.algo |= BE_LB_ALGO_RR;
+               curproxy->lbprm.algo |= BE_LB_ALGO_RND;
                return 0;
        }
 
index 3880549b8ec4b2451c74e7af531fdd355cda70b8..e1b4933dca31c7c490fef1c2998bf3e8e1228736 100644 (file)
@@ -3064,10 +3064,10 @@ init_proxies_list_stage1:
                        else if (!(curproxy->options & (PR_O_TRANSP | PR_O_DISPATCH))) {
                                /* If no LB algo is set in a backend, and we're not in
                                 * transparent mode, dispatch mode nor proxy mode, we
-                                * want to use balance roundrobin by default.
+                                * want to use balance random by default.
                                 */
                                curproxy->lbprm.algo &= ~BE_LB_ALGO;
-                               curproxy->lbprm.algo |= BE_LB_ALGO_RR;
+                               curproxy->lbprm.algo |= BE_LB_ALGO_RND;
                        }
                }