The server can handle 65,536 sockets per IP address. So the number can be easily increased by adding additional network interfaces to the server. Meanwhile, it is extremely important to keep track of how many connections are present on the server. Once the limit is exceeded, you can have many problems with other TCP connections (for example, no, you can connect to the server via ssh). So itβs a good idea to restrict WS to node inside your application code.
For HAProxy to handle more than 65 thousand connections, we must go through the following steps:
- Create a bunch of private IP addresses. To do this, select your Amazon Instance β Actions β Network β Manage Private IP Addresses. We have added 3 IP addresses: 192.168.1.1, 192.168.1.2, 192.168.1.3. Just remember that the IP must be on the same subnet as your real application server.
Connect to your HAProxy instance via SSH and run the 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 the section from the haproxy.cfg file for 3 hosts that accept 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 connection limit can be easily increased by adding virtual network interfaces. In addition, it can establish new connections pretty quickly.
Also see this blog post
source share