upstream hash consistent seems to depend on order of DNS entries

Maxim Dounin mdounin at
Mon Feb 3 13:05:38 UTC 2020


On Sat, Feb 01, 2020 at 11:48:00AM -0800, Ian Morris Nieves wrote:

> Here is the setup:
> - I am running nginx in a single docker container and it has an 
> upstream to a docker service which is composed of 3 docker 
> containers (which happens to be php-fpm)
> - the service is configured to _not_ expose a single virtual ip 
> address (vip), instead the service exposes the ip addresses of 
> all 3 containers through docker’s built-in DNS.  When this DNS 
> is asked for the IP address of the service it will respond with 
> a list of 3 IP address but the list will rotate in round-robin 
> fashion each time a lookup is performed.  Thus the first IP in 
> the list will not be the same for any 2 consecutive lookups.
> My first question is:
> Is it the correct behavior that consistent hashing depends on 
> the order of IP addresses in the DNS query response?  I can 
> imagine arguments either way, and it is possible that this 
> critical detail is outside the scope of consistent hashing.  I 
> will also forward this question to the author of Ketama.

Consistent hashing uses the _name_ as written in the 
configuration, not the IP addresses the name resolves to.

If a name resolves to multiple IP addresses, these addresses are 
considered equal and requests are distributed between them using 
round-robin balancing.

That is, to balance multiple servers (containers) using consistent 
hashing, you have to configure an upstream block with multiple 
"server" directives in it.

Maxim Dounin

More information about the nginx mailing list