Upstream Consistent Hash Inconsistency

Ari Croock acroock at isazi.ai
Thu Feb 11 08:54:34 UTC 2021


Thanks for the explanation.

I don't think changing the current implementation would be a good idea, but
what do you think of adding another option in addition to "consistent"?
It could use the consistent hashing algorithm with peer IP addresses
instead of hostnames, as you suggested.
Not sure what the nginx policy is for that sort of change.

If that's not possible, do you think we could at least add a line to the
documentation about this edge case?

Thanks

On Thu, 11 Feb 2021 at 04:22, Maxim Dounin <mdounin at mdounin.ru> wrote:

> Hello!
>
> On Wed, Feb 10, 2021 at 07:03:30PM +0200, Ari Croock wrote:
>
> > That makes sense to me, except for the fact that "hash" (without
> > "consistent") doesn't seem to be doing round-robin load balancing.
> >
> > Is there a reason that regular "hash" keeps returning a consistent IP? I
> > could understand if both directives resulted in the behaviour you
> > described, but it seems strange that only one would.
>
> That's because the algorithms used are quite different.
>
> Simple hashing algorithm doesn't care about being consistent, and
> uses the Nth peer, where N is calculated as a hash modulo
> total number of peers.  This works good as long as the list of
> servers is not changed.  If the list is changed, however, new hashing
> will result in completely different peer being used for requests
> with the same hash key.  Note that "the list is changed" also
> implies changes in number or order of IP addresses if you use
> names in the configuration.
>
> Consistent hashing works differently: instead, it tries to
> preserve mapping from hash to a particular upstream server.  To do
> so, it relies on names used in the configuration, so changes in
> the configuration, such as order of servers, or even changes of IP
> addresses used by particular servers, do not affect distribution
> of the requests between servers.  As a result, if a name in the
> configuration maps to more than one IP address, these addresses
> are equal to the algorithm, since they use the same name.
>
> It should be possible to implement consistent hashing differently,
> for example, using IP addresses of the particular peers instead of
> names from the configuration.  This approach will probably match
> what you are trying to do somewhat better.  This is not how it is
> currently implemented in nginx though.
>
> --
> Maxim Dounin
> http://mdounin.ru/
> _______________________________________________
> nginx mailing list
> nginx at nginx.org
> http://mailman.nginx.org/mailman/listinfo/nginx
>


-- 
Ari Croock | Isazi | Software Engineer | BSc (Eng) - Electrical

38 Homestead Road, Rivonia, Johannesburg, South Africa, 2128 |(: +27 11 027
6996

*:  acroock at isazi.ai | www.isazi.ai
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mailman.nginx.org/pipermail/nginx/attachments/20210211/eb7376a2/attachment.htm>


More information about the nginx mailing list