Keepalive connection reuse with url balancing


#1

Hi All,
is it possible to have connection reuse and http keepalive at server-side with url balancing?

For example, I have two clients with keepalive executing requests
Client 1 connection:
GET /server1-url1
GET /server2-url1

Client 2 connection:
GET /server2-url2
GET /server1-url2

and it goes through two connections from HAProxy to servers:

connection 1 to server 1:
GET /server1-url1
GET /server1-url2

connection 2 to server 2:
GET /server2-url1
GET /server2-url2

(ordering doesn’t matter, the main idea is connection reuse)

I tried the following config (HAProxy version is 1.5.4-2.el6_7.1), my clients do not reconnect to HAProxy, but it keeps reconnecting to backend, utilises 100% cpu and works slower than a single server without HAProxy:

global
log 127.0.0.1 local2

chroot      /var/lib/haproxy
pidfile     /var/run/haproxy.pid
maxconn     400000
user        haproxy
group       haproxy
daemon
stats socket /var/lib/haproxy/stats

defaults
mode http
option dontlognull
option forwardfor except 127.0.0.0/8
option redispatch
option http-keep-alive
retries 1
timeout http-request 10s
timeout queue 1m
timeout connect 10s
timeout client 1m
timeout server 1m
timeout http-keep-alive 10s
timeout check 10s
maxconn 300000

listen stats :1936
mode http
stats enable
stats hide-version
stats realm Haproxy\ Statistics
stats uri /
stats auth private:hastats777

frontend main *:80
acl url_static path_beg -i /stats

use_backend static          if url_static
default_backend             mybackend

backend static
balance roundrobin
server static host1:8080 check

backend mybackend
balance uri depth 2
hash-type consistent
mode http
server back1 host1:8080 check
server back2 host2:8080 check


#2

You may give a try to HAProxy 1.6 and http-reuse function:
http://cbonte.github.io/haproxy-dconv/snapshot/configuration-1.6.html#http-reuse

That said, it will be very efficient if you have many users browsing the website, since the server side connection is being reused for an other client as long as the client who has initiated the connection is still connected.


#3

Thanks a lot, it should help


#4

Looks like this option alone, doesn’t help for HAProxy 1.6.3, maybe there are other conditions for keepalive reuse? I tried simply adding it to the config above (updating “bind” syntax for 1.6) and tried combining with other http options, but didn’t succeed, it keeps reconnecting to backend, how could I debug this situation? I mean, maybe I miss some HTTP headers required for this option in my packets or something


#5

You can enable capture of Connection headers, on both the client and the server.
Also, what http-reuse option have you setup, some of them are more or less conservative.
Last but not least, it’s not a pool of connections, so HAProxy may re-use an established connections until the client which has created it kills his connection.