Load balancing with least_conn strategy does round-robin
mdounin at mdounin.ru
Wed Feb 20 16:18:05 UTC 2019
On Wed, Feb 20, 2019 at 11:01:45AM -0500, emil.vikstrom wrote:
> I want to use nginx as a load balancer for tcp streams and because I want to
> share the load evenly over all machines I thought that least_conn would be
> the right strategy to use in this case. But I have stumbled upon an problem
> I don't really understand.
> In my lab environment I have three machines running server software.
> I start my testing establishing 12 connections to nginx and can see that
> they are getting evenly across all hosts. 4 connections per host.
> I then stop one of the machines and the client reestablishes the lost
> connections and they are getting spread evenly to the remaining hosts. Now
> we have 6 connections on 2 hosts.
> I then start up the closed machine and proceed to close 2 connections each
> on the servers that have been up all this time. The client tries to set up
> new connections and this is where I notice that the load not being equally
> shared anymore.
> The results I get is host1: 6 connections, host2: 5 connections, host3: 1
> As far as I can see it seems like nginx uses round-robin to balance the
> connections and not setting up connections to the host with least
> connections. Am I misinterpreting what least connections mean?
The problem is that host3 is considered to be failed as per
max_fails, so it only gets one "test" connection once
fail_timeout expires. The host won't be considered fully
operational till this connection is closed without an error.
More information about the nginx