]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
MINOR: backend: add hash-balance-factor option for hash-type consistent
authorAndrew Rodland <andrewr@vimeo.com>
Tue, 25 Oct 2016 16:49:05 +0000 (12:49 -0400)
committerWilly Tarreau <w@1wt.eu>
Tue, 25 Oct 2016 18:21:32 +0000 (20:21 +0200)
0 will mean no balancing occurs; otherwise it represents the ratio
between the highest-loaded server and the average load, times 100 (i.e.
a value of 150 means a 1.5x ratio), assuming equal weights.

Signed-off-by: Andrew Rodland <andrewr@vimeo.com>
doc/configuration.txt
include/types/lb_chash.h
src/cfgparse.c

index d0475244ba668ccd0a284ab99ef9ef9a3fdccd98..a93c103800d80a595d4e5028efc3b8fc7b7b0bcf 100644 (file)
@@ -2205,6 +2205,32 @@ balance url_param <param> [check_post]
   See also : "dispatch", "cookie", "transparent", "hash-type" and "http_proxy".
 
 
+balance-factor <factor>
+  Specify the balancing factor for bounded-load consistent hashing
+  May be used in sections :   defaults | frontend | listen | backend
+                                 yes   |    no    |   no   |   yes
+  Arguments :
+    <factor> is the control for the maximum number of concurrent requests to
+             send to a server, expressed as a percentage of the average number
+            of concurrent requests across all of the active servers.
+
+  Specifying a "balance-factor" for a server with "hash-type consistent"
+  enables an algorithm that prevents any one server from getting too many
+  requests at once, even if some hash buckets receive many more requests than
+  others. Setting <factor> to 0 (the default) disables the feature. Otherwise,
+  <factor> is a percentage greater than 100. For example, if <factor> is 150,
+  then no server will be allowed to have a load more than 1.5 times the average.
+  If server weights are used, they will be respected.
+
+  If the first-choice server is disqualified, the algorithm will choose another
+  server based on the request hash, until a server with additional capacity is
+  found. A higher <factor> allows more imbalance between the servers, while a
+  lower <factor> means that more servers will be checked on average, affecting
+  performance. Reasonable values are from 125 to 200.
+
+  See also : "balance" and "hash-type".
+
+
 bind [<address>]:<port_range> [, ...] [param*]
 bind /<path> [, ...] [param*]
   Define one or several listening addresses and/or ports in a frontend.
@@ -3358,7 +3384,7 @@ hash-type <method> <function> <modifier>
   default function is "sdbm", the selection of a function should be based on
   the range of the values being hashed.
 
-  See also : "balance", "server"
+  See also : "balance", "balance-factor", "server"
 
 
 http-check disable-on-404
index 5991ce961b7a519bea707b7ff46b0883d01656dd..b711636e245e36a35179a1fa687bba3fe42519c7 100644 (file)
@@ -30,6 +30,7 @@ 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 cc2f507e7d779d58b30ed528f8a7dbbb1072360a..229b3ceb891a1786c787d92b992749e91a6c3802 100644 (file)
@@ -1983,6 +1983,7 @@ void init_default_instance()
        defproxy.maxconn = cfg_maxpconn;
        defproxy.conn_retries = CONN_RETRIES;
        defproxy.redispatch_after = 0;
+       defproxy.lbprm.chash.balance_factor = 0;
 
        defproxy.defsrv.check.inter = DEF_CHKINTR;
        defproxy.defsrv.check.fastinter = 0;
@@ -2825,6 +2826,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->fullconn = defproxy.fullconn;
                        curproxy->conn_retries = defproxy.conn_retries;
                        curproxy->redispatch_after = defproxy.redispatch_after;
@@ -5958,6 +5960,19 @@ stats_error_parsing:
                        }
                }
        }
+       else if (strcmp(args[0], "hash-balance-factor") == 0) {
+               if (*(args[1]) == 0) {
+                       Alert("parsing [%s:%d] : '%s' expects an integer argument.\n", file, linenum, args[0]);
+                       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) {
+                       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;
+               }
+       }
        else if (strcmp(args[0], "unique-id-format") == 0) {
                if (!*(args[1])) {
                        Alert("parsing [%s:%d] : %s expects an argument.\n", file, linenum, args[0]);