From d4a7d89f564234e44012a763cc28c5a3991bd98e Mon Sep 17 00:00:00 2001 From: Alban Lecocq Date: Mon, 5 Dec 2022 19:28:12 +0100 Subject: reverseproxy: Improve hostByHashing distribution (#5229) * If upstreams are all using same host but with different ports ie: foobar:4001 foobar:4002 foobar:4003 ... Because fnv-1a has not a good enough avalanche effect Then the hostByHashing result is not well balanced over all upstreams As last byte FNV input tend to affect few bits, the idea is to change the concatenation order between the key and the upstream strings So the upstream last byte have more impact on hash diffusion --- modules/caddyhttp/reverseproxy/selectionpolicies.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'modules/caddyhttp/reverseproxy/selectionpolicies.go') diff --git a/modules/caddyhttp/reverseproxy/selectionpolicies.go b/modules/caddyhttp/reverseproxy/selectionpolicies.go index 2de830c..0b7f50c 100644 --- a/modules/caddyhttp/reverseproxy/selectionpolicies.go +++ b/modules/caddyhttp/reverseproxy/selectionpolicies.go @@ -528,7 +528,7 @@ func hostByHashing(pool []*Upstream, s string) *Upstream { if !up.Available() { continue } - h := hash(s + up.String()) // important to hash key and server together + h := hash(up.String() + s) // important to hash key and server together if h > highestHash { highestHash = h upstream = up -- cgit v1.2.3