From: Aurelien DARRAGON Date: Wed, 4 Oct 2023 15:30:02 +0000 (+0200) Subject: MINOR: log/balance: support for the "random" lb algorithm X-Git-Tag: v2.9-dev8~60 X-Git-Url: http://git.haproxy.org/?a=commitdiff_plain;h=e0b46600150ceb67d3051cc6ed1150708f0ae7a1;p=haproxy-3.0.git MINOR: log/balance: support for the "random" lb algorithm In this patch we add basic support for the random algorithm: random algorithm picks a random server using the result of the statistical_prng() function as if it was a hash key to then compute the related server ID. There is no support for the parameter (which is implemented for tcp/http load-balancing), because we don't have the required metrics to evaluate server's load in log backends for the moment. Plus it would add more complexity to the __do_send_log_backend() function so we'll keep it this way for now but this might be needed in the future. --- diff --git a/doc/configuration.txt b/doc/configuration.txt index 6c903fc..d064357 100644 --- a/doc/configuration.txt +++ b/doc/configuration.txt @@ -8839,6 +8839,12 @@ log-balance [ ] goes back UP it is added at the end of the list so that the sticky server doesn't change until it becomes DOWN. + random A random number will be used as the key for the server + lookup. Random log balancing can be useful with large farms + or when servers are frequently added or removed from the + pool of available servers as it may avoid the hammering + effect that could result from roundrobin in this situation. + is an optional list of arguments which may be needed by some algorithms. diff --git a/src/backend.c b/src/backend.c index 8b76a93..e0b5a58 100644 --- a/src/backend.c +++ b/src/backend.c @@ -2849,8 +2849,12 @@ int backend_parse_log_balance(const char **args, char **err, struct proxy *curpr /* we use ALGO_FAS as "sticky" mode in log-balance context */ curproxy->lbprm.algo |= BE_LB_ALGO_FAS; } + else if (strcmp(args[0], "random") == 0) { + curproxy->lbprm.algo &= ~BE_LB_ALGO; + curproxy->lbprm.algo |= BE_LB_ALGO_RND; + } else { - memprintf(err, "only supports 'roundrobin', 'sticky' options"); + memprintf(err, "only supports 'roundrobin', 'sticky', 'random', options"); return -1; } return 0; diff --git a/src/log.c b/src/log.c index 6900407..53011f7 100644 --- a/src/log.c +++ b/src/log.c @@ -2116,6 +2116,10 @@ static inline void __do_send_log_backend(struct proxy *be, struct log_header hdr */ targetid = 0; } + else if ((be->lbprm.algo & BE_LB_ALGO) == BE_LB_ALGO_RND) { + /* random mode */ + targetid = statistical_prng() % nb_srv; + } skip_lb: