I understand the Ping is to help prevent proxies from closing idle connections. Is there any guidelines w.r.t. how often to ping? Once every second? 10 seconds? Minute? Does it even matter? A preliminary google search gives me nothing, and the websocket spec only says what a ping is, not how often you should do it
Maintaining the connection Mews recommends that the integration sends a WebSocket Ping request to Mews at regular intervals (e.g., every 5 minutes) to monitor the connection. If the Ping request fails, the integration interface should be restarted or try to re-establish a connection.
Using TCP keepalive may work, but only for the TCP session from your client to the next hop -- which may or may not actually be the end server. Given the above, I would recommend that yes, you should ping your connected WebSocket sessions periodically.
The Websocket protocol implements so called PING/PONG messages to keep Websockets alive, even behind proxies, firewalls and load-balancers. The server sends a PING message to the client through the Websocket, which then replies with PONG. If the client does not reply, the server closes the connection.
The theoretical limit is 65k connections per IP address but the actual limit is often more like 20k, so we use multiple addresses to connect 20k to each (50 * 20k = 1 mil).
I know this is an old question, but i've also been in search for an answer. The previous answer does not make mention of the interval, so I searched through some code of some popular websocket frameworks. Not that this is official, but at least it gives a starting point: this repo makes use of 20 second intervals. I'm not sure if that 100% correct, but its better than "often", or "somewhat frequently".
The accepted answer to the following SO thread seems to answer your question pretty well:
Sending websocket ping/pong frame from browser
It sounds like you can ping fairly often (using your own custom ping/pong strings), and unless there are a ton of clients connected to your WebSocket server, then the load on the system will be fairly minimal.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With