ks2bmallik
ks2bmallik

Reputation: 184

TCP load balancing in HAProxy with persistent TCP connections

Currently, I have a single client (component) having a single persistent TCP connection with the server(another component), and messages are exchanged asynchronously. I wanted to have a load balancer (HAProxy preferably) where the connection b/w client and load balancer as well as b/w load balancer and multiple servers as persistent TCP connection.

I know HAProxy can easily be set up for the TCP load balancing, but I wanted to know does it support persistent connections out of the box. Would be great help if someone points me in the right direction. Thanks.

Upvotes: 6

Views: 10482

Answers (2)

Sridhar Sarnobat
Sridhar Sarnobat

Reputation: 25216

This is impossible. TCP is a stateful protocol. Even we do it by some tricks, such as an iptables mirror, the target backend host will drop packets which it has no handshake or pre packets.

You would have to consider UDP instead.

Upvotes: 2

Praveen Pavithran
Praveen Pavithran

Reputation: 98

Yes it supports persistent TCP connections right out of the box. A simple implementation in the haproxy looks like this

listen tcpProxy 0.0.0.0:7000 
    mode tcp 
    balance source
    server tcp1 ip1:port check maxconn 10000
    server tcp2 ip2:port check maxconn 10000

Hope this helps

Upvotes: 6

Related Questions