@@ -84,33 +84,32 @@ is on the other side of the planet and has a latency of 10000
84
84
milliseconds, setting the ``connectTimeoutMS`` to anything lower will
85
85
prevent the driver from ever connecting to that member.
86
86
87
- Should I Use "socketTimeoutMS" as a Way of Preventing Long- Running Operations From Slowing Down the Server ?
88
- -------------------------------------------------------------------------------------------------------------
87
+ What Happens to Running Operations If the Client Disconnects ?
88
+ -------------------------------------------------------------
89
89
90
- No, you should **not** use ``socketTimeoutMS`` to end operations that
91
- may run for too long and slow down the application. Attempting to do so
92
- may not achieve the intended result.
90
+ Starting in {+mdb-server+} version 4.2, the server terminates
91
+ running operations such as aggregations and find operations if the
92
+ client disconnects. To see a full list of operations affected by this
93
+ behavior, see the :manual:`Server version 4.2 release notes
94
+ </release-notes/4.2/#client-disconnection>` in the Server manual.
93
95
94
- Closing the socket causes a reconnect of the driver's connection pool,
95
- introducing latency to any other queued up operations. Chronically slow
96
- operations will, therefore, cause a large number of reconnect requests,
97
- negatively impacting throughput and performance .
96
+ Other operations, such as write operations, continue to run on the
97
+ {+mdb-server+} even if the client disconnects. This behavior can cause data
98
+ inconsistencies if your application retries the operation after the
99
+ client disconnects .
98
100
99
- Also, closing the socket does not terminate the operation; it will
100
- continue to run on the MongoDB server, which could cause data
101
- inconsistencies if the application retries the operation on failure.
101
+ How Can I Confirm That the Driver Closed Unusable Sockets?
102
+ ----------------------------------------------------------
102
103
103
- However, there are important use cases for ``socketTimeoutMS`` -
104
- consider the following cases:
104
+ If you experience unexpected network behavior or if a MongoDB process
105
+ fails with an error, you may not receive confirmation that the
106
+ driver correctly closed the corresponding socket.
105
107
106
- - A MongoDB process erroring out
107
- - A misconfigured firewall causing a socket connection without sending a ``FIN`` packet
108
-
109
- In those cases, there is no way to detect that the connection has died.
110
- Setting the ``socketTimeoutMS`` is essential to ensure that the sockets
111
- are closed correctly. A good rule of thumb is to set ``socketTimeoutMS``
112
- to two to three times the length of the slowest operation that runs
113
- through the driver.
108
+ To make sure that the driver correctly closes the socket in these cases,
109
+ set the ``socketTimeoutMS`` option. When a MongoDB process times out, the driver
110
+ will close the socket. We recommend that you select a value
111
+ for ``socketTimeoutMS`` that is two to three times as long as the
112
+ expected duration of the slowest operation that your application executes.
114
113
115
114
How Can I Prevent Sockets From Timing out Before They Become Active?
116
115
--------------------------------------------------------------------
@@ -127,18 +126,19 @@ avoid closing.
127
126
128
127
One message every 3000 milliseconds is not enough to keep the sockets
129
128
active, so several of the sockets will time out after 5000 milliseconds.
130
- Reduce the ``poolSize`` in the connection settings to fix the problem.
129
+ To avoid excessive socket timeouts, reduce the number of connections
130
+ that the driver can maintain in the connection pool by specifying the
131
+ ``maxPoolSize`` option.
131
132
132
- To specify the optional ``poolSize `` setting for your ``MongoClient``, declare
133
+ To specify the optional ``maxPoolSize `` setting for your ``MongoClient``, declare
133
134
it in the ``options`` object of the constructor as follows:
134
135
135
136
.. code-block:: javascript
136
137
137
138
const client = new MongoClient(uri, {
138
- poolSize : <integer value>,
139
+ maxPoolSize : <integer value>,
139
140
});
140
141
141
-
142
142
What Does a Value of "0" mean for "connectTimeoutMS" and "socketTimeoutMS"?
143
143
---------------------------------------------------------------------------
144
144
@@ -216,7 +216,7 @@ How Can I Prevent a Slow Operation From Delaying Other Operations?
216
216
------------------------------------------------------------------
217
217
218
218
A slow operation may delay your other operations that occur after it, if
219
- the ``poolSize `` has not been set in the
219
+ the ``maxPoolSize `` has not been set in the
220
220
:ref:`connection options <node-connection-options>`.
221
221
MongoDB is synchronous and uses a single execution thread per socket,
222
222
meaning that MongoDB will execute one single operation per socket at any
@@ -227,9 +227,9 @@ a separate connection pool for the slow operation, isolating it from
227
227
other, faster operations.
228
228
229
229
.. note::
230
- If the number of operations is greater than the set ``poolSize`` and
231
- a slow operation occurs, subsequent operations will be delayed.
232
-
230
+ If the number of operations is greater than the value of the
231
+ ``maxPoolSize`` option and a slow operation occurs, subsequent
232
+ operations will be delayed.
233
233
234
234
To create a separate connection pool, instantiate another ``MongoClient``
235
235
call the ``connect()`` method on it. See the following example for the
0 commit comments