From: Willy Tarreau Date: Thu, 1 Oct 2009 05:52:15 +0000 (+0200) Subject: [MEDIUM] backend: implement consistent hashing variation X-Git-Tag: v1.4-dev4~17 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=6b2e11be1;p=thirdparty%2Fhaproxy.git [MEDIUM] backend: implement consistent hashing variation Consistent hashing provides some interesting advantages over common hashing. It avoids full redistribution in case of a server failure, or when expanding the farm. This has a cost however, the hashing is far from being perfect, as we associate a server to a request by searching the server with the closest key in a tree. Since servers appear multiple times based on their weights, it is recommended to use weights larger than approximately 10-20 in order to smoothen the distribution a bit. In some cases, playing with weights will be the only solution to make a server appear more often and increase chances of being picked, so stats are very important with consistent hashing. In order to indicate the type of hashing, use : hash-type map-based (default, old one) hash-type consistent (new one) Consistent hashing can make sense in a cache farm, in order not to redistribute everyone when a cache changes state. It could also probably be used for long sessions such as terminal sessions, though that has not be attempted yet. More details on this method of hashing here : http://www.spiteful.com/2008/03/17/programmers-toolbox-part-3-consistent-hashing/ --- diff --git a/Makefile b/Makefile index ed8cb27c9a..14586dcdb1 100644 --- a/Makefile +++ b/Makefile @@ -459,7 +459,7 @@ OBJS = src/haproxy.o src/sessionhash.o src/base64.o src/protocols.o \ src/time.o src/fd.o src/pipe.o src/regex.o src/cfgparse.o src/server.o \ src/checks.o src/queue.o src/client.o src/proxy.o src/proto_uxst.o \ src/proto_http.o src/stream_sock.o src/appsession.o src/backend.o \ - src/lb_fwlc.o src/lb_fwrr.o src/lb_map.o \ + src/lb_chash.o src/lb_fwlc.o src/lb_fwrr.o src/lb_map.o \ src/stream_interface.o src/dumpstats.o src/proto_tcp.o \ src/session.o src/hdr_idx.o src/ev_select.o src/signal.o \ src/acl.o src/memory.o src/freq_ctr.o \ diff --git a/Makefile.bsd b/Makefile.bsd index eb2b6b085e..7957f9427b 100644 --- a/Makefile.bsd +++ b/Makefile.bsd @@ -105,7 +105,7 @@ OBJS = src/haproxy.o src/sessionhash.o src/base64.o src/protocols.o \ src/proto_http.o src/stream_sock.o src/appsession.o src/backend.o \ src/stream_interface.o src/dumpstats.o src/proto_tcp.o \ src/session.o src/hdr_idx.o src/ev_select.o src/signal.o \ - src/lb_fwlc.o src/lb_fwrr.o src/lb_map.o \ + src/lb_chash.o src/lb_fwlc.o src/lb_fwrr.o src/lb_map.o \ src/ev_poll.o src/ev_kqueue.o \ src/acl.o src/memory.o src/freq_ctr.o \ src/ebtree.o src/eb32tree.o diff --git a/Makefile.osx b/Makefile.osx index 9ba146b27f..19fb720608 100644 --- a/Makefile.osx +++ b/Makefile.osx @@ -102,7 +102,7 @@ OBJS = src/haproxy.o src/sessionhash.o src/base64.o src/protocols.o \ src/proto_http.o src/stream_sock.o src/appsession.o src/backend.o \ src/stream_interface.o src/dumpstats.o src/proto_tcp.o \ src/session.o src/hdr_idx.o src/ev_select.o src/signal.o \ - src/lb_fwlc.o src/lb_fwrr.o src/lb_map.o \ + src/lb_chash.o src/lb_fwlc.o src/lb_fwrr.o src/lb_map.o \ src/ev_poll.o \ src/acl.o src/memory.o src/freq_ctr.o \ src/ebtree.o src/eb32tree.o diff --git a/doc/configuration.txt b/doc/configuration.txt index 6fe6e958ba..fecab814fc 100644 --- a/doc/configuration.txt +++ b/doc/configuration.txt @@ -723,6 +723,7 @@ errorloc302 X X X X errorloc303 X X X X fullconn X - X X grace - X X X +hash-type X - X X http-check disable-on-404 X - X X id - X X X log X X X X @@ -956,8 +957,9 @@ balance url_param [check_post []] used in TCP mode where no cookie may be inserted. It may also be used on the Internet to provide a best-effort stickyness to clients which refuse session cookies. This algorithm is - static, which means that changing a server's weight on the - fly will have no effect. + static by default, which means that changing a server's + weight on the fly will have no effect, but this can be + changed using "hash-type". uri The left part of the URI (before the question mark) is hashed and divided by the total weight of the running servers. The @@ -966,9 +968,9 @@ balance url_param [check_post []] server as long as no server goes up or down. This is used with proxy caches and anti-virus proxies in order to maximize the cache hit rate. Note that this algorithm may only be used - in an HTTP backend. This algorithm is static, which means - that changing a server's weight on the fly will have no - effect. + in an HTTP backend. This algorithm is static by default, + which means that changing a server's weight on the fly will + have no effect, but this can be changed using "hash-type". This algorithm support two optional parameters "len" and "depth", both followed by a positive integer number. These @@ -1018,8 +1020,9 @@ balance url_param [check_post []] long as no server goes up or down. If no value is found or if the parameter is not found, then a round robin algorithm is applied. Note that this algorithm may only be used in an HTTP - backend. This algorithm is static, which means that changing a - server's weight on the fly will have no effect. + backend. This algorithm is static by default, which means + that changing a server's weight on the fly will have no + effect, but this can be changed using "hash-type". hdr(name) The HTTP header will be looked up in each HTTP request. Just as with the equivalent ACL 'hdr()' function, the header @@ -1032,6 +1035,10 @@ balance url_param [check_post []] specific headers such as 'Host'. For instance, in the Host value "haproxy.1wt.eu", only "1wt" will be considered. + This algorithm is static by default, which means that + changing a server's weight on the fly will have no effect, + but this can be changed using "hash-type". + rdp-cookie rdp-cookie(name) The RDP cookie (or "mstshash" if omitted) will be @@ -1048,6 +1055,10 @@ balance url_param [check_post []] you must use 'tcp-request content accept' rule combined with a 'req_rdp_cookie_cnt' ACL. + This algorithm is static by default, which means that + changing a server's weight on the fly will have no effect, + but this can be changed using "hash-type". + is an optional list of arguments which may be needed by some algorithms. Right now, only "url_param" and "uri" support an optional argument. @@ -1099,7 +1110,8 @@ balance url_param [check_post []] might be a URL parameter list. This is probably not a concern with SGML type message bodies. - See also : "dispatch", "cookie", "appsession", "transparent" and "http_proxy". + See also : "dispatch", "cookie", "appsession", "transparent", "hash-type" and + "http_proxy". bind [
]: [, ...] @@ -1729,6 +1741,40 @@ grace