I have a very basic round-robin reverse proxy setup for learning purposes.

upstream file_server_com {
    server machine-01;
    server machine-02;
}

server {
        listen 80 default_server reuseport;
        listen [::]:80 default_server ipv6only=on reuseport;

        root /usr/share/nginx/html;
        index index.html index.htm;

        server_name localhost;

        location / {
            proxy_pass http://file_server_com;
        }
}

I have a 1kb file on the each of the upstream servers. I run wget to download the file. I'm not seeing the requests ping-pong between machine 01 and 02. Overall, I do see about a 50/50 split between the two, but I would have thought I should see the requests alternate between the two machines.

Sometimes I'll see machine 01 get the request consecutively, sometimes I'll see machine 02 get consecutive requests, sometimes they alternate.

Is there something I'm not understanding about nginx's round-robin load balancer?

We're seeing similar behavior from the roud roubin module with nginx/1.13.7. Borrowing from your example, we noticed a higher proportion of requests being sent to machine-01 than machine-02.

Initially, we thought the nginx-sticky-module-ng could be causing the skew in distribution. But we noticed the sticky session only exacerbates an underlying problem.

We can test requests using curl without persisting the route cookies, and this triggers nginx's default round robin on every request. By counting the number of route cookies for each upatream, we can measure which ares are being favoured -- from top to bottom, the first servers in the upstream list seem to get more traffic.

We are still trying to understand how or why this is happening. At the moment, we are trying to get around the issue by adjusting the weight parameter in each upstream server.

Your Answer

 

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Not the answer you're looking for? Browse other questions tagged or ask your own question.