Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 282
ks2bmallik Avatar asked May 25 '18 05:05

ks2bmallik


2 Answers

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

like image 115
Praveen Pavithran Avatar answered Oct 01 '22 09:10

Praveen Pavithran


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.

like image 35
Sridhar Sarnobat Avatar answered Oct 01 '22 07:10

Sridhar Sarnobat