Score:1

Nginx Round Robin is balancing every second request

kh flag

I have configured nginx to do basic Round Robin load balancing between upstream servers. The traffic is being distributed evenly between upstream server, I am expecting load to be balanced after every request but instead it is balanced every second request (the load balancer is serving the first 2 HTTP requests to the first server, the following 2 HTTP requests got to the second server etc. ). I have also tried to use weighted load balancing with even weights on upstream servers and behavior stays the same.

load balancer config:

######################  Upstream directive   ######################
upstream backend {
   server ecslb.bknd-srv-one.com:10000;
   server ecslb.bknd-srv-two.com:10000;
   server ecslb.bknd-srv-three.com:10000;
}

######################  Server directive   ######################
server {
   listen 10000;   
   server_name research-complex.com;
   location / {
   proxy_pass http://backend;
   }
}

The load-balancer config is loaded by nginx.conf which was left default, only a resolver was added. Any thoughts what could be the reason for this?

Score:0
jp flag

This might help. Looks like your are not the only one with this problem.

https://stackoverflow.com/questions/55257595/nginx-round-robin-load-balancing-is-not-as-expected

Score:0
kz flag

Not sure if this is your exact case, but it may help others who come here.

The documentation for the server directive says that

A domain name that resolves to several IP addresses defines multiple servers at once. http://nginx.org/en/docs/http/ngx_http_upstream_module.html#server

So if the address specified in server is resolved into multiple IP addresses, Nginx will also create multiple upstream servers and balance between them. It may then look as if Nginx is passing two requests in a row to the same upstream server, but it's actually two "different" upstream servers (with different IP addresses).

In my case, I was using localhost as the server address, which, according to my /etc/hosts file, resolves to both 127.0.0.1 and ::1 IP addresses. For example:

# /etc/hosts
127.0.0.1   localhost
...

::1     localhost ip6-localhost ip6-loopback
...

Then, in a configuration like:

upstream backend {
   server localhost:8001;
   server localhost:8002;
}

Nginx would balance between 4 servers - 127.0.0.1:8001, [::1]:8001, 127.0.0.1:8002 and [::1]:8002.

mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.