i’ve tried to build a socket server in php, but found out that because of the lack of multithreading capability in php, if the server is loaded with connection (lets say even a small amount of 300 connection), the server will be very slow.
i’ve switched to java, and built a multithreading socket server, and tried to overloaded it with 100 connection in 10 seconds, and i must say it took it bravely.. my own pc (which made the overload) became real slow during the process but server looked like he was ok.
since i’m building a server which should run lots of connections simultaneously, i’m trying to make efficient, and not to leave any ghost connection open.
there for i’m implementing a “Keep Alive” method and my question is as follow:
if i have 600 open connections opened in my server, and obviously it takes the server time to run between all threads to check keep alive and even to get the keep alive message from the client – what should be the appropriate time to check if a keep alive message was sent.
i’ve thought somewhere around 2 minutes – so the server want be to busy, and from the other hand i don’t want my clients to send data too often..
any suggestions ?
600 open connections. Assuming that a keep-alive is sent every 2 minutes, 120 seconds, that means about 5 threads becoming ready per second to send a keep-alive. Assuming that all the connections are up, the five threads wil beome ready again shortly after to process the echo from the peer. So, that’s about ten threads/sec need to run to support the keep-alives.
That’s an insignificant loading.
If the clients are busy, then those clients will not be sent keep-alives, so the loading for keep-alives drops as clients become usefully busy.
You sound like you should be OK.