Scaling socket.io
Jade Meskill edited this page Oct 17, 2017
·
1 revision
socket.io requires sticky sessions in order to support multiple backends. For Meshblu in large scale settings, we have used haproxy to provide stickiness.
For use with Docker Swarm see: octoblu/swarm-haproxy-socket-io
global
stats socket /tmp/haproxy.sock
maxconn 80000
resolvers dns
nameserver dns1 8.8.8.8:53
hold valid 2m
defaults
log global
mode http
timeout client 60s # Client and server timeout must match the longest
timeout server 300s # time we may wait for a response from the server.
timeout queue 120s # Don't queue requests too long if saturated.
timeout connect 10s # There's no reason to change this one.
timeout http-request 300s # A complete request may never take that long.
timeout tunnel 2h
retries 3
option redispatch
option httplog
option dontlognull
option http-server-close # enable HTTP connection closing on the server side
option abortonclose # enable early dropping of aborted requests from pending queue
option httpchk # enable HTTP protocol to check on servers health
stats auth opsworks:opsworks
stats uri /haproxy?stats
backend meshblu-socket-io
balance roundrobin
timeout queue 5000
timeout server 86400000
timeout connect 86400000
timeout check 1s
option forwardfor
no option httpclose
option http-server-close
option forceclose
# this must be the partial url
option httpchk GET /healthcheck
stick-table type string len 40 size 20M expire 2m
stick store-response set-cookie(io)
stick on cookie(io)
stick on url_param(sid)
server server1 server1.local:80 resolvers dns resolve-prefer ipv4 check inter 1m
server server2 server2.local:80 resolvers dns resolve-prefer ipv4 check inter 1m
frontend http-in
bind :80
default_backend meshblu-socket-io