Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What are issues with using WebSockets with proxies and load balancers?

I'm reading up on SockJS node server. Documentation says:

Often WebSockets don't play nicely with proxies and load balancers. Deploying a SockJS server behind Nginx or Apache could be painful. Fortunately recent versions of an excellent load balancer HAProxy are able to proxy WebSocket connections. We propose to put HAProxy as a front line load balancer and use it to split SockJS traffic from normal HTTP data.

I'm curious if anyone can expand on the problem that is being solved by HAProxy in this case? Specifically:

  1. Why websockets don't play nice with proxies and load balancers?
  2. Why deploying Sockjs sever behind Apache is painful?
like image 327
dev.e.loper Avatar asked Apr 04 '13 17:04

dev.e.loper


People also ask

Do WebSockets work with load balancers?

The load balancer knows how to upgrade an HTTP connection to a WebSocket connection and once that happens, messages will travel back and forth through a WebSocket tunnel. However, you must design your system for scale if you plan to load balance multiple WebSocket servers.

Do proxies support WebSockets?

Transparent proxies will usually by default forward SSL traffic. This will allow us to establish a WebSocket connection. To do this we must configure apache to allow the HTTP CONNECT header to be sent to the secure nirvana interface.

Why WebSockets are not reliable?

It has built-in means of detecting transmission errors or packet corruption and attempting retransmissions in those cases, but delivery can still fail. It guarantees that if the packet is not delivered, the caller will get an error so the caller can know. Since websocket is built on top of TCP, it has the same issue.

How are WebSockets load balanced?

WebSocket load balancing is mutual problem of client and server. Without a hint from client, it is hardly possible to get 6D-tuple knowledge on the server side. A reasonable solution is to lift load balancing to the application level. It means that client application logic will be aware of server-side scaling.


1 Answers

1. Why websockets don't play nice with proxies and load balancers?

I'd recommend you read this article on How HTML5 Web Sockets Interact With Proxy Servers by Peter Lubbers. It should cover everything you need to know about WebSocket and proxies - and thus, load balancers.

2. Why deploying Sockjs sever behind Apache is painful?

There is a module for handling WebSocket connections but at present Apache doesn't natively support WebSocket, nor does it look like it will any time soon based on this bug filed on apache - HTML5 Websocket implementation. The suggestion is that it actually fits the module pattern better.

So, it's "painful" simply because it's not easy - there's no official support and therefore it doesn't have the community use that it otherwise may have.

There may also be other pains in the SockJS has HTTP-based fallback transports. So you need to proxy both the WebSocket connections (using the apache-websocket module) and also HTTP requests when fallback is used.

Related to this: Nginx v1.3 was released in February with WebSocket support.

like image 182
leggetter Avatar answered Nov 16 '22 02:11

leggetter