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 <draw> 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.
This commit is contained in:
Aurelien DARRAGON 2023-10-04 17:30:02 +02:00 committed by Christopher Faulet
parent 26f73dbcbb
commit e0b4660015
3 changed files with 15 additions and 1 deletions

View File

@ -8839,6 +8839,12 @@ log-balance <algorithm> [ <arguments> ]
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.
<arguments> is an optional list of arguments which may be needed by some
algorithms.

View File

@ -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;

View File

@ -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: