]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
MINOR: backend: move hash_balance_factor out of chash
authorWilly Tarreau <w@1wt.eu>
Mon, 14 Jan 2019 15:50:58 +0000 (16:50 +0100)
committerWilly Tarreau <w@1wt.eu>
Mon, 14 Jan 2019 18:33:17 +0000 (19:33 +0100)
This one is a proxy option which can be inherited from defaults even
if the LB algo changes. Move it out of the lb_chash struct so that we
don't need to keep anything separate between these structs. This will
allow us to merge them into an union later. It even takes less room
now as it fills a hole and removes another one.

include/types/backend.h
include/types/lb_chash.h
src/cfgparse-listen.c
src/cfgparse.c
src/lb_chash.c

index e67f0be54adde62951054634d4c5e967cef129c8..ea38ed2c2a4c89cb8276f9cd8ffd70b9c5871446 100644 (file)
@@ -144,6 +144,7 @@ struct lbprm {
        int tot_used;                   /* total number of servers used for LB */
        int wmult;                      /* ratio between user weight and effective weight */
        int wdiv;                       /* ratio between effective weight and user weight */
+       int hash_balance_factor;        /* load balancing factor * 100, 0 if disabled */
        char *arg_str;                  /* name of the URL parameter/header/cookie used for hashing */
        int   arg_len;                  /* strlen(arg_str), computed only once */
        int   arg_opt1;                 /* extra option 1 for the LB algo (algo-specific) */
index b711636e245e36a35179a1fa687bba3fe42519c7..5991ce961b7a519bea707b7ff46b0883d01656dd 100644 (file)
@@ -30,7 +30,6 @@ struct lb_chash {
        struct eb_root act;     /* weighted chash entries of active servers */
        struct eb_root bck;     /* weighted chash entries of backup servers */
        struct eb32_node *last; /* last node found in case of round robin (or NULL) */
-       int balance_factor;     /* load balancing factor * 100, 0 if disabled */
 };
 
 #endif /* _TYPES_LB_CHASH_H */
index 7514a47efb9d318114fb8effc0a23c8300da1e7c..1af86ded4f0b4122bc840946b759b3195550e77d 100644 (file)
@@ -426,7 +426,7 @@ int cfg_parse_listen(const char *file, int linenum, char **args, int kwm)
 
                if (curproxy->cap & PR_CAP_BE) {
                        curproxy->lbprm.algo = defproxy.lbprm.algo;
-                       curproxy->lbprm.chash.balance_factor = defproxy.lbprm.chash.balance_factor;
+                       curproxy->lbprm.hash_balance_factor = defproxy.lbprm.hash_balance_factor;
                        curproxy->fullconn = defproxy.fullconn;
                        curproxy->conn_retries = defproxy.conn_retries;
                        curproxy->redispatch_after = defproxy.redispatch_after;
@@ -3654,8 +3654,8 @@ stats_error_parsing:
                        err_code |= ERR_ALERT | ERR_FATAL;
                        goto out;
                }
-               curproxy->lbprm.chash.balance_factor = atol(args[1]);
-               if (curproxy->lbprm.chash.balance_factor != 0 && curproxy->lbprm.chash.balance_factor <= 100) {
+               curproxy->lbprm.hash_balance_factor = atol(args[1]);
+               if (curproxy->lbprm.hash_balance_factor != 0 && curproxy->lbprm.hash_balance_factor <= 100) {
                        ha_alert("parsing [%s:%d] : '%s' must be 0 or greater than 100.\n", file, linenum, args[0]);
                        err_code |= ERR_ALERT | ERR_FATAL;
                        goto out;
index 7c316df05c17483a4031ab0f24e5465646063ca1..31698b9b7bab883d5d8b9c5dd08ed8225ea10ec4 100644 (file)
@@ -453,7 +453,6 @@ void init_default_instance()
        defproxy.maxconn = cfg_maxpconn;
        defproxy.conn_retries = CONN_RETRIES;
        defproxy.redispatch_after = 0;
-       defproxy.lbprm.chash.balance_factor = 0;
        defproxy.options = PR_O_REUSE_SAFE;
        defproxy.max_out_conns = MAX_SRV_LIST;
 
index 186e87a5fa5eefe42f97f93855476cb7279de735..a35351e96fbb5ad12f97900195005280c142b2b3 100644 (file)
@@ -290,7 +290,7 @@ int chash_server_is_eligible(struct server *s)
        /* The total number of slots to allocate is the total number of outstanding requests
         * (including the one we're about to make) times the load-balance-factor, rounded up.
         */
-       unsigned tot_slots = ((s->proxy->served + 1) * s->proxy->lbprm.chash.balance_factor + 99) / 100;
+       unsigned tot_slots = ((s->proxy->served + 1) * s->proxy->lbprm.hash_balance_factor + 99) / 100;
        unsigned slots_per_weight = tot_slots / s->proxy->lbprm.tot_weight;
        unsigned remainder = tot_slots % s->proxy->lbprm.tot_weight;
 
@@ -368,7 +368,7 @@ struct server *chash_get_server_hash(struct proxy *p, unsigned int hash, const s
        }
 
        loop = 0;
-       while (nsrv == avoid || (p->lbprm.chash.balance_factor && !chash_server_is_eligible(nsrv))) {
+       while (nsrv == avoid || (p->lbprm.hash_balance_factor && !chash_server_is_eligible(nsrv))) {
                next = eb32_next(next);
                if (!next) {
                        next = eb32_first(root);