fabiolb / fabio

Consul Load-Balancing made simple
https://fabiolb.net
MIT License
7.27k stars 616 forks source link

Question: Load balancing WebSocket connections #718

Closed djromberg closed 4 years ago

djromberg commented 4 years ago

This is a question regarding the load balancing capabilities of Fabio. In our cluster we have a WebSocket service that can only handle up to N (let's say N=3, without loss of generality) clients. Whenever a connection is established we notify an API endpoint so that the cluster orchestrator (in our case Nomad) is told to fire up another container if we run "out of seats". The question now is: Does Fabio somehow consider the open connection "load" for a given service instance during its round-robin distribution? If not, (how) can we tell Fabio (or Consul) to reflect that? If one container has no more "seats" a new user should not get routed to it (if there is a container that still has "seats").

Thanks for any insights or hints! Daniel

pschultz commented 4 years ago

fabio does not have a connection limiter, and backends are picked irrespective of the number of existing connections; there is a round-robin balancer and a random balancer, but nothing like least connections.

Have you considered marking backends with N connections unhealthy causing fabio to ignore it? You can either incorporate that into existing health checks, or, if that's too slow, add and remove checks that always fail as appropriate.

djromberg commented 4 years ago

Thanks for the info and the health check idea. This is what we are going to try out now: Our WebSocket server offers an HTTP endpoint to query the current number of connections. I can create a script health check that uses curl and compares the resulting value with a corresponding environment variable that we set (e.g., ${MAX_CONNECTIONS}). If these values are equal, the health check will fail and should revoke service validity for consul.

Update: It works :) Thanks for the suggestion, I'll close this issue.

tino commented 4 years ago

But doesn't that mean that all connections to the clients from that server are severed? Because consul unhealthy => unroutable, right?

pschultz commented 4 years ago

@tino, already established connections are not interrupted when a backend becomes unhealthy.