Reputation: 305
If i set the pingTimeout: 3000
and pingInterval: 2000
; and if there are simultaneously 800 socket connections; will this have any issue on server performance or provide latency? And what do we mean by when the socket.io docs says that the server will wait for pingTimeout(ms)
to disconnect the socket if it doesn't get the pong
packet (which means the socket is idle).
What cases are covered when we say that the socket is idle? Does that mean that if the user is active on the page but is not clicking anything then does it mean the socket is idle?
Upvotes: 5
Views: 7844
Reputation: 707298
socket.io uses an active scheme (as opposed to a passive scheme) for detecting when a socket.io connection has become disconnected or non-functional for any reason.
This active scheme involves the client sending a ping
packet to the server on a regular interval and waiting for a pong
interval to come back from the server.
From the client-side of things, the pingInterval
is how often is sends a ping packet and the pingTimeout
is how long is waits for a pong packet to come back from the server before concluding that there is a problem with the connection and it should drop the connection and then make an attempt to reconnect.
Similarly, the server is expecting a ping
packet to arrive every pingInterval
and if one does not arrive, then the server will conclude that the connection has died in some way.
So, the shorter you set the pingInterval
, the more often client is sending a ping
and receiving a pong
back from the server and similarly, the more often the server is receiving a ping
from the client and sending back a pong
.
An "idle" socket.io connection is still sending ping
and pong
messages.
If there are simultaneously 800 socket connections; will this have any issue on server performance or provide latency
There are a lot of variables involved in how many simultaneous connections a server can handle and you don't really provide any of the relevant info to know about your particular case. Here are some of the things that go into determining it:
In general, 800 simultaneous connections is a relatively small number and many installations can handle that just fine if overall data usage is low and configurations are otherwise optimized. There are some server installations that can handle many thousands of simultaneous connections.
What cases are covered when we say that the socket is idle?
I'm not sure what you mean by "what cases". An idle socket.io connection means that no messages have been flowing in either direction. When the connection goes idle, socket.io uses ping and pong packets to "test" the connection to make sure it is still working.
Does that mean that if the user is active on the page but is not clicking anything then does it mean the socket is idle?
A socket is idle when YOUR code isn't sending or receiving anything on the socket. That may or may not be connected to what the user clicks on. That depends entirely upon your app. For example a stock ticker app may be receiving stock price updates over socket.io every few seconds and that connection would pretty much never be idle even though the end-user never clicked on anything in the web page.
Upvotes: 11