I had a similar experience that may help someone.
My server was stoping responding after one hour when the number of concurrent socket connections reached about 700. After trying all of the possible solutions, I realized that I had a ProxyPass
in apache which redirects port 443 (SSL) to 8080 (my socket port) In other words from ws to wss like discussed here.
Finally, I increased the ServerLimit
in my Apache prefork
configuration from 500 to 1700 and the problem was solved temporarily. (You should increase MaxRequestWorkers
as well)
This shows that if you use ReverseProxy in Apache (or another webserver) the Apache will become busy as it gets stuck between the client and WebSocket server.
I do not recommend increasing the Apache config for the final solution, but I want to mention considering this as a potential bottleneck. Maybe the best solution is to run a direct wss. (I anyone knows a good tutorial please comment that)
The second thing I should mention is that there is a hard limit of 1024 connections which in my case was exactly 1019 concurrent connections that will be solved by installing ev or event.
I installed ev but due to a problem during the installation, it did not work well. I had to reinstall it and the problem was solved (uninstall using pecl uninstall ev). I used the following lines for installing it on php8.0:
apt install php8.0-dev
pecl install ev
sudo echo 'extension=ev.so' > /etc/php/8.0/mods-available/ev.ini
sudo phpenmod -v 8.0 ev
# Check module (it will echo ev if installation is successful):
php8.0 -i | grep -i ev