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.
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.
/* 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;
*/
targetid = 0;
}
+ else if ((be->lbprm.algo & BE_LB_ALGO) == BE_LB_ALGO_RND) {
+ /* random mode */
+ targetid = statistical_prng() % nb_srv;
+ }
skip_lb: