Only first server on backend getting used

Here’s my setup. Both http and https connections are working, but on both backends, only the first server entry (server aab) is being forwarded to. The second one (server aaa) never gets hit. If I reverse the order the servers are listed, still only the first one gets hit:

defaults
log global
mode tcp
option dontlognull
timeout connect 5000
timeout client 50000
timeout server 50000

frontend http
bind :80
default_backend servers_http

frontend https
bind :443
default_backend servers_https

backend servers_http
mode tcp
balance roundrobin
server aab 44.195.20.48:80
server aaa 3.88.254.26:80

backend servers_https
mode tcp
balance roundrobin
server aab 44.195.20.48:443
server aaa 3.88.254.26:443

Just to add a bit more, I have determined that it does indeed hit both backend servers occasionally, it definitely does not do a “round robin” in the traditional sense. After more research, I added a weight setting to the servers, so now it looks like this:

backend servers_http
mode tcp
balance roundrobin
server aab 44.195.20.48:80 weight 50
server aaa 3.88.254.26:80 weight 50

backend servers_https
mode tcp
balance roundrobin
server aab 44.195.20.48:443 weight 50
server aaa 3.88.254.26:443 weight 50

My understanding is that this should force each server to be used equally and alternately, but I am not seeing this behavior.

This was a fun experiment! I have three identical webservers. On each one, I added the header called “selserv” and I ordered them 1-3. Here’s what I found:

$ curl -s -I https://test.example.com/?[1-10] | grep selserv
selserv: 2
selserv: 3
selserv: 1
selserv: 2
selserv: 3
selserv: 1
selserv: 2
selserv: 3
selserv: 1
selserv: 2

HAProxy indeed follows roundrobin, but it’s hard to measure outside of very controlled circumstances. In this case, every request was exactly the same, and it was the only traffic hitting these web servers. Notice that it starts on 2? That’s beause I opened this in a browser when I started.

Yours should work the exact same way, however I’ve noticed differences in milliseconds can throw off an observation. For instance, if HAProxy delivers request 1 to server 1, but it’s for a 1MB file, the request 2 goes to server 2 which is answered with a redirect. Request 3 comes in, server 1 has not yet responded to request 1, so request 3 goes to server 2.

If you have this kind of flexibility with your web servers, try the same experiment.

Thanks for the reply. I started working on a more realistic test and I did see significant improvement. HAProxy was working very well and distributing the load equally. It also seems to be rock-solid under load and very efficient. I guess that shouldn’t be surprising considering its reputation and the size of its user base :slight_smile:

1 Like