proxy - Load balance WebSocket connections to Tornado app using HAProxy? -


i working on tornado app uses websocket handlers. i'm running multiple instances of app using supervisord, have trouble load balancing websocket connections.

i know nginx not support dealing websockets out of box, followed instructions here http://www.letseehere.com/reverse-proxy-web-sockets use nginx tcp_proxy module reverse proxy websocket connections. however, did not work since module can't route websocket urls (ex: ws://localhost:80/something). not work url routes have defined in tornado app.

from research around web, seems haproxy way go load balance websocket connections. however, i'm having trouble finding decent guidance setup haproxy load balance websocket connections , able handle websocket url routes.

i appreciate detailed directions on how going. open other solutions well.

it's not difficult implement websocket in haproxy, though admit it's not yet easy find doc on (hopefully response make 1 example). if you're using haproxy 1.4 (which suppose are) works other http request without having anything, http upgrade recognized haproxy.

if want direct websocket traffic different farm rest of http, should use content switching rules, in short :

  frontend pub-srv     bind :80     use_backend websocket if { hdr(upgrade) -i websocket }     default_backend http   backend websocket     timeout server 600s     server node1 1.1.1.1:8080 check     server node2 2.2.2.2:8080 check   backend http     timeout server 30s     server www1 1.1.1.1:80 check     server www2 2.2.2.2:80 check 

if you're using 1.5-dev, can specify "timeout tunnel" have larger timeout ws connections normal http connections, saves using overly long timeouts on client side.

you can combine upgrade: websocket + specific url :

  frontend pub-srv     bind :80     acl is_websocket hdr(upgrade) -i websocket     acl is_ws_url path /something1 /something2 /something3     use_backend websocket if is_websocket is_ws_url     default_backend http 

last, please don't use stupid 24h idle timeouts see, makes absolutely no sense wait client 24h established session right now. web more mobile in 80s , connection ephemeral. you'd end many fin_wait sockets nothing. 10 minutes quite long current internet.

hoping helps!


Comments

Popular posts from this blog

java - Play! framework 2.0: How to display multiple image? -

gmail - Is there any documentation for read-only access to the Google Contacts API? -

php - Controller/JToolBar not working in Joomla 2.5 -