2

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?

1

2 Answers 2

1

You could try to force nginx to consider all servers having the same weight:

upstream file_server_com {
    server machine-01 weight=1;
    server machine-02 weight=1;
}

that might help instill the right algorithm.

Or use the least_conn attribute if round-robin cannot get obtained. At least, the least busy server should be selected.

But according to this SO answer nginx seems to deal differently with round-robin when multiple threads are running. The "solution" was to set

worker_processes 1;

but that is likely to reduce performance.

0

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.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .