@@ -190,7 +190,7 @@ will close the socket. We recommend that you select a value
190
190
for ``socketTimeoutMS`` that is two to three times as long as the
191
191
expected duration of the slowest operation that your application executes.
192
192
193
- How Can I Prevent Sockets From Timing out Before They Become Active?
193
+ How Can I Prevent Sockets From Timing Out Before They Become Active?
194
194
--------------------------------------------------------------------
195
195
196
196
Having a large connection pool does not always reduce reconnection
@@ -261,31 +261,58 @@ socket connections.
261
261
If you experience unexpected network behavior, here
262
262
are some things to check:
263
263
264
- #. The firewall should send a ``FIN packet`` when closing a socket,allowing the driver to detect that the socket is closed.
264
+ #. The firewall should send a ``FIN packet`` when closing a socket,
265
+ allowing the driver to detect that the socket is closed.
265
266
#. The firewall should allow ``keepAlive`` probes.
266
267
267
268
How Can I Prevent a Slow Operation From Delaying Other Operations?
268
269
------------------------------------------------------------------
269
270
270
- To control the maximum size of a connection pool, you can set the
271
- ``maxPoolSize`` option in the :ref:`connection options
272
- <node-connection-options>`. The default value of ``maxPoolSize`` is
273
- ``100``. If the number of in-use connections to a server reaches
274
- ``maxPoolSize``, the next request to that server will wait
275
- until a connection becomes available. To prevent long-running operations
276
- from slowing down your application, you can increase ``maxPoolSize``.
277
-
278
- The driver does not limit the number of requests that can wait for
279
- sockets to become available. Requests wait for the amount of time
280
- specified in the ``waitQueueTimeoutMS`` option, which
281
- defaults to ``0`` (no limit). You should set this option if it is
282
- more important to stop long-running operations than it is to complete
283
- every operation.
271
+ When you use the same ``MongoClient`` instance to run multiple MongoDB
272
+ operations concurrently, a slow operation can cause delays to other
273
+ operations. Slow operations keep a connection to MongoDB occupied,
274
+ which can cause other operations to wait until an additional connection
275
+ becomes available.
276
+
277
+ If you suspect that slow MongoDB operations are causing delays, you
278
+ can check the performance of all in-progress operations by using the
279
+ following methods:
280
+
281
+ - Enable the database profiler on your deployment. To learn more, see
282
+ :manual:`Database Profiler </tutorial/manage-the-database-profiler/>`
283
+ in the Server manual.
284
+ - Run the ``db.currentOp()`` MongoDB Shell command. To learn more, see the
285
+ :manual:`db.currentOp() </reference/method/db.currentOp/>`
286
+ documentation in the Server manual.
287
+ - Enable connection pool monitoring. To learn more, see
288
+ :ref:`node-connection-pool-monitoring`.
289
+
290
+ After you determine which operations are causing delays, try to improve
291
+ the performance of these operations. Read the :website:`Best Practices
292
+ Guide for MongoDB Performance </basics/best-practices>` for possible solutions.
293
+
294
+ If you implement performance best practices but still
295
+ experience delays, you can modify your connection settings to increase
296
+ the size of the connection pool. A connection pool is the group of
297
+ connections to the server that the driver maintains at any time.
298
+
299
+ To specify the maximum size of a
300
+ connection pool, you can set the ``maxPoolSize`` option in the
301
+ :ref:`connection options <node-connection-options>` for your
302
+ ``MongoClient`` instance. The default value
303
+ of ``maxPoolSize`` is ``100``. If the number of in-use connections to a
304
+ server reaches ``maxPoolSize``, the next operation sent to the server
305
+ pauses until a connection to the driver becomes available. The following
306
+ code sets ``maxPoolSize`` to ``150`` when creating a new ``MongoClient``:
307
+
308
+ .. code-block:: js
309
+
310
+ const client = new MongoClient(uri, { maxPoolSize: 150 });
284
311
285
312
.. tip::
286
313
287
- To learn more about connection pooling, see :ref:`How Does Connection
288
- Pooling Work in the Node Driver? <node-faq-connection-pool>`.
314
+ To learn more about connection pooling, see the :ref:`How Does Connection
315
+ Pooling Work in the Node Driver? <node-faq-connection-pool>` FAQ entry .
289
316
290
317
How Can I Ensure My Connection String Is Valid for a Replica Set?
291
318
-----------------------------------------------------------------
0 commit comments