Welcome! Log In Create A New Profile


Re: Load balancing with least_conn strategy does round-robin

Maxim Dounin
February 20, 2019 11:20AM

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
> connection.
> 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[1], 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.

[1] http://nginx.org/en/docs/stream/ngx_stream_upstream_module.html#max_fails

Maxim Dounin
nginx mailing list
Subject Author Posted

Load balancing with least_conn strategy does round-robin

emil.vikstrom February 20, 2019 11:01AM

Re: Load balancing with least_conn strategy does round-robin

Maxim Dounin February 20, 2019 11:20AM

Sorry, only registered users may post in this forum.

Click here to login

Online Users

Guests: 187
Record Number of Users: 8 on April 13, 2023
Record Number of Guests: 500 on July 15, 2024
Powered by nginx      Powered by FreeBSD      PHP Powered      Powered by MariaDB      ipv6 ready