changing a server's weight on the fly will have no effect,
but this can be changed using "hash-type".
+ random A random number will be used as the key for the consistent
+ hashing function. This means that the servers' weights are
+ respected, dynamic weight changes immediately take effect, as
+ well as new server additions. Random load balancing can be
+ useful with large farms or when servers are frequently added
+ or removed. The hash-balance-factor directive can be used to
+ further improve fairness of the load balancing, especially
+ in situations where servers show highly variable response
+ times.
+
rdp-cookie
rdp-cookie(<name>)
The RDP cookie <name> (or "mstshash" if omitted) will be
lower <factor> means that more servers will be checked on average, affecting
performance. Reasonable values are from 125 to 200.
+ This setting is also used by "balance random" which internally relies on the
+ consistent hashing mechanism.
+
See also : "balance" and "hash-type".
#define BE_LB_HASH_PRM 0x00002 /* hash HTTP URL parameter */
#define BE_LB_HASH_HDR 0x00003 /* hash HTTP header value */
#define BE_LB_HASH_RDP 0x00004 /* hash RDP cookie value */
+#define BE_LB_HASH_RND 0x00008 /* hash a random value */
/* BE_LB_RR_* is used with BE_LB_KIND_RR */
#define BE_LB_RR_DYN 0x00000 /* dynamic round robin (default) */
#define BE_LB_RR_STATIC 0x00001 /* static round robin */
+#define BE_LB_RR_RANDOM 0x00002 /* random round robin */
/* BE_LB_CB_* is used with BE_LB_KIND_CB */
#define BE_LB_CB_LC 0x00000 /* least-connections */
*/
#define BE_LB_ALGO_NONE (BE_LB_KIND_NONE | BE_LB_NEED_NONE) /* not defined */
#define BE_LB_ALGO_RR (BE_LB_KIND_RR | BE_LB_NEED_NONE) /* round robin */
+#define BE_LB_ALGO_RND (BE_LB_KIND_RR | BE_LB_NEED_NONE | BE_LB_RR_RANDOM) /* random value */
#define BE_LB_ALGO_LC (BE_LB_KIND_CB | BE_LB_NEED_NONE | BE_LB_CB_LC) /* least connections */
#define BE_LB_ALGO_FAS (BE_LB_KIND_CB | BE_LB_NEED_NONE | BE_LB_CB_FAS) /* first available server */
#define BE_LB_ALGO_SRR (BE_LB_KIND_RR | BE_LB_NEED_NONE | BE_LB_RR_STATIC) /* static round robin */
return map_get_server_hash(px, hash);
}
+/* random value */
+static struct server *get_server_rnd(struct stream *s)
+{
+ unsigned int hash = 0;
+ struct proxy *px = s->be;
+
+ /* tot_weight appears to mean srv_count */
+ if (px->lbprm.tot_weight == 0)
+ return NULL;
+
+ /* ensure all 32 bits are covered as long as RAND_MAX >= 65535 */
+ hash = ((uint64_t)random() * ((uint64_t)RAND_MAX + 1)) ^ random();
+ return chash_get_server_hash(px, hash);
+}
+
/*
* This function applies the load-balancing algorithm to the stream, as
* defined by the backend it is assigned to. The stream is then marked as
case BE_LB_LKUP_CHTREE:
case BE_LB_LKUP_MAP:
if ((s->be->lbprm.algo & BE_LB_KIND) == BE_LB_KIND_RR) {
- if (s->be->lbprm.algo & BE_LB_LKUP_CHTREE)
+ if ((s->be->lbprm.algo & BE_LB_PARM) == BE_LB_RR_RANDOM)
+ srv = get_server_rnd(s);
+ else if (s->be->lbprm.algo & BE_LB_LKUP_CHTREE)
srv = chash_get_next_server(s->be, prev_srv);
else
srv = map_get_server_rr(s->be, prev_srv);
curproxy->lbprm.algo &= ~BE_LB_ALGO;
curproxy->lbprm.algo |= BE_LB_ALGO_LC;
}
+ else if (!strcmp(args[0], "random")) {
+ curproxy->lbprm.algo &= ~BE_LB_ALGO;
+ curproxy->lbprm.algo |= BE_LB_ALGO_RND;
+ }
else if (!strcmp(args[0], "source")) {
curproxy->lbprm.algo &= ~BE_LB_ALGO;
curproxy->lbprm.algo |= BE_LB_ALGO_SH;
if ((curproxy->lbprm.algo & BE_LB_PARM) == BE_LB_RR_STATIC) {
curproxy->lbprm.algo |= BE_LB_LKUP_MAP;
init_server_map(curproxy);
+ } else if ((curproxy->lbprm.algo & BE_LB_PARM) == BE_LB_RR_RANDOM) {
+ curproxy->lbprm.algo |= BE_LB_LKUP_CHTREE | BE_LB_PROP_DYN;
+ chash_init_server_tree(curproxy);
} else {
curproxy->lbprm.algo |= BE_LB_LKUP_RRTREE | BE_LB_PROP_DYN;
fwrr_init_server_groups(curproxy);