Reputation: 203
I'm having hard time understanding keepAlive
option passed to nodeJS mongo driver.
this docs says keepAlive
takes boolean value and keepAliveInitialDelay
is used to wait before initiating keepAlive on the TCP socket
this docs says keepAlive
takes an integer value and reads The number of milliseconds to wait before initiating keepAlive on the TCP socket.
I tried using both and failed to find any difference also I tried with both true
and false
values for keepAlive
and tried 0,1 and 30000(default) for keepAliveInitialDelay
.
keepAlive
?keepAlive
do? or what is the use of keepAlive
option?keepAlive
to false
or settings it to 0
or 1
?keepAlive
affects artefacts -> Server, ReplicaSet, Mongos
. so to which option does it map to at server side docs?I'm using mongo driver V3.3 and mongo atlas V4.2
Thanks in advance.
Upvotes: 3
Views: 7984
Reputation: 14520
The TCP keep-alive mechanism is described here. It is used for:
Checking for dead peers
Preventing disconnection due to network inactivity
When keep-alive is enabled, the driver instructs the network stack to periodically send ping packets to the server on the established connection. If the server's network stack does not respond, the connection is flagged as failed.
Without keep-alive, the driver wouldn't find out about some of the network issues until after the application issued a query (and was waiting for it to be executed).
The driver sets the network stack options here using setKeepAlive.
To see whether keep-alives are being sent, you need to use a tool like tcpdump
to inspect traffic on the connections established by the driver.
The server uses the system-wide keep-alive value if it is under 300 seconds, otherwise sets keep-alive interval to 300 seconds.
Upvotes: 2