]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
MINOR: server: compute a "cumulative weight" to allow chash balancing to hit its...
authorAndrew Rodland <andrewr@vimeo.com>
Tue, 25 Oct 2016 16:49:45 +0000 (12:49 -0400)
committerWilly Tarreau <w@1wt.eu>
Tue, 25 Oct 2016 18:21:32 +0000 (20:21 +0200)
For active servers, this is the sum of the eweights of all active
servers before this one in the backend, and
[srv->cumulative_weight .. srv_cumulative_weight + srv_eweight) is a
space occupied by this server in the range [0 .. lbprm.tot_wact), and
likewise for backup servers with tot_wbck. This allows choosing a
server or a range of servers proportional to their weight, by simple
integer comparison.

Signed-off-by: Andrew Rodland <andrewr@vimeo.com>
include/types/server.h
src/backend.c

index ce138206b1d048fd4b6f909e84ec5fde75126ba5..5d89212823ce7f56559af661f56c362c089ebd63 100644 (file)
@@ -203,6 +203,7 @@ struct server {
        unsigned wscore;                        /* weight score, used during srv map computation */
        unsigned prev_eweight;                  /* eweight before last change */
        unsigned rweight;                       /* remainer of weight in the current LB tree */
+       unsigned cumulative_weight;             /* weight of servers prior to this one in the same group, for chash balancing */
        unsigned npos, lpos;                    /* next and last positions in the LB tree */
        struct eb32_node lb_node;               /* node used for tree-based load balancing */
        struct eb_root *lb_tree;                /* we want to know in what tree the server is */
index faf872c0b16345b305c257a592625bfeb292a805..573f054dc7a72a555bdec199a3890f7bb59fa5c5 100644 (file)
@@ -115,9 +115,11 @@ void recount_servers(struct proxy *px)
                            !(px->options & PR_O_USE_ALL_BK))
                                px->lbprm.fbck = srv;
                        px->srv_bck++;
+                       srv->cumulative_weight = px->lbprm.tot_wbck;
                        px->lbprm.tot_wbck += srv->eweight;
                } else {
                        px->srv_act++;
+                       srv->cumulative_weight = px->lbprm.tot_wact;
                        px->lbprm.tot_wact += srv->eweight;
                }
        }