The server can handle 65,536 sockets per single IP address. So the
quantity can be easily extended by adding additional network
interfaces to a server. Meanwhile, it’s extremely important to track
how many connections present on a server. Once the limit is exceeded,
you can have a lot of issues with other TCP connections (e.g. it’s not
possible to connect to a server via ssh). So it’s a good idea to limit
WS connections per node inside your application’s code.
To make HAProxy handle more than 65k connections we should pass through the next steps::
- Create a bunch of private IP addresses. To do it choose your Amazon
Instance -> Actions -> Networking -> Manage Private IP Addresses. We
added 3 IP addresses: 192.168.1.1, 192.168.1.2, 192.168.1.3. Just
remember that the IP should be in the same sub-network as your real
application server.
Connect to your HAProxy instance via SSH and run following commands:
$> ifconfig eth0:1 192.168.1.1
$> ifconfig eth0:2 192.168.1.2
$> ifconfig eth0:3 192.168.1.3
This will add 3 virtual network interfaces to the instance.
Configure HAProxy. Here is a section from haproxy.cfg file for 3
nodes accepting WS connections:
listen erlang_front :8888
mode http
balance roundrobin
timeout connect 1s
timeout queue 5s
timeout server 3600s
option httpclose
option forwardfor
server xxxxx-1 192.168.0.1:8888 source 192.168.1.1
server xxxxx-2 192.168.0.2:8888 source 192.168.1.2
server xxxxx-3 192.168.0.3:8888 source 192.168.1.3
Now HAProxy can handle more than 65,536 WebSocket connections, and the limit of connections can be easily increased by adding virtual network interfaces. Also, it can establish new connections rather fast.
Also Refer this Blog Post