I’m trying to figure out how to balance websocket connections across several servers using haproxy.
It looks like the leastconn balancing algorithm seems a good idea for this.
I understand that this means that when a new websocket connection is being established (i.e. connected), haproxy will assign this to the server with the least connections.
However, what happens while the connection is open (and after haproxy initially assigned it to the server with the least connections)?
Would haproxy reassign the server anytime a packet flows over the open websocket connection, or only when a new websocket connection is being established?
It’s for new connections only, you can’t reassign a websocket connection, because by websocket definition we need to be layer 4 payload agnostic, so we cannot know when we could possibly interrupt a session and if another server would know what to do with it.
The only way to move existing connection around is to fully close and destroy them, so that the client reconnects.
So, if I understand correctly, I don’t need a stick-table for this scenario, as once-established websocket connections stick to the originally assigned server automatically?
You’d only need stick-tables if all the connections from one single source IP would need to hit a specific server, e.g. when the customer closes the browser and reopens it 10 minutes later, reestablishes the connection to your application, and you still need to make sure that the customer this the same server than it did in the previous session, then you need stick tables.
If I take one of my servers down, will the loadbalancer reset the connection count for that server automatically to zero?
Does using wss (instead of ws) introduce any problems in terms of leastconn balancing? Would it matter -from a balancing and connection counting perspective- where I terminate SSL in this case (on the load balancer vs on the server)?