@@ -226,7 +226,7 @@ will close the socket. We recommend that you select a value
226
226
for ``socketTimeoutMS`` that is two to three times as long as the
227
227
expected duration of the slowest operation that your application executes.
228
228
229
- How Can I Prevent Sockets From Timing out Before They Become Active?
229
+ How Can I Prevent Sockets From Timing Out Before They Become Active?
230
230
--------------------------------------------------------------------
231
231
232
232
Having a large connection pool does not always reduce reconnection
@@ -295,7 +295,8 @@ socket connections.
295
295
If you experience unexpected network behavior, here
296
296
are some things to check:
297
297
298
- #. The firewall should send a ``FIN packet`` when closing a socket,allowing the driver to detect that the socket is closed.
298
+ #. The firewall should send a ``FIN packet`` when closing a socket,
299
+ allowing the driver to detect that the socket is closed.
299
300
#. The firewall should allow ``keepAlive`` probes.
300
301
301
302
What Can I Do If I'm Getting "ECONNRESET" When Calling "client.connect()"?
@@ -330,25 +331,51 @@ This sets the maximum number of ``file descriptors`` for the process to
330
331
How Can I Prevent a Slow Operation From Delaying Other Operations?
331
332
------------------------------------------------------------------
332
333
333
- To control the maximum size of a connection pool, you can set the
334
- ``maxPoolSize`` option in the :ref:`connection options
335
- <node-connection-options>`. The default value of ``maxPoolSize`` is
336
- ``100``. If the number of in-use connections to a server reaches
337
- ``maxPoolSize``, the next request to that server will wait
338
- until a connection becomes available. To prevent long-running operations
339
- from slowing down your application, you can increase ``maxPoolSize``.
340
-
341
- The driver does not limit the number of requests that can wait for
342
- sockets to become available. Requests wait for the amount of time
343
- specified in the ``waitQueueTimeoutMS`` option, which
344
- defaults to ``0`` (no limit). You should set this option if it is
345
- more important to stop long-running operations than it is to complete
346
- every operation.
334
+ When you use the same ``MongoClient`` instance to run multiple MongoDB
335
+ operations concurrently, a slow operation can cause delays to other
336
+ operations. Slow operations keep a connection to MongoDB occupied,
337
+ which can cause other operations to wait until an additional connection
338
+ becomes available.
339
+
340
+ If you suspect that slow MongoDB operations are causing delays, you
341
+ can check the performance of all in-progress operations by using the
342
+ following methods:
343
+
344
+ - Enable the database profiler on your deployment. To learn more, see
345
+ :manual:`Database Profiler </tutorial/manage-the-database-profiler/>`
346
+ in the Server manual.
347
+ - Run the ``db.currentOp()`` MongoDB Shell command. To learn more, see the
348
+ :manual:`db.currentOp() </reference/method/db.currentOp/>`
349
+ documentation in the Server manual.
350
+ - Enable connection pool monitoring. To learn more, see
351
+ :ref:`node-connection-pool-monitoring`.
352
+
353
+ After you determine which operations are causing delays, try to improve
354
+ the performance of these operations. Read the :website:`Best Practices
355
+ Guide for MongoDB Performance </basics/best-practices>` for possible solutions.
356
+
357
+ If you implement performance best practices but still
358
+ experience delays, you can modify your connection settings to increase
359
+ the size of the connection pool. A connection pool is the group of
360
+ connections to the server that the driver maintains at any time.
361
+
362
+ To specify the maximum size of a
363
+ connection pool, you can set the ``maxPoolSize`` option in the
364
+ :ref:`connection options <node-connection-options>` for your
365
+ ``MongoClient`` instance. The default value
366
+ of ``maxPoolSize`` is ``100``. If the number of in-use connections to a
367
+ server reaches ``maxPoolSize``, the next operation sent to the server
368
+ pauses until a connection to the driver becomes available. The following
369
+ code sets ``maxPoolSize`` to ``150`` when creating a new ``MongoClient``:
370
+
371
+ .. code-block:: js
372
+
373
+ const client = new MongoClient(uri, { maxPoolSize: 150 });
347
374
348
375
.. tip::
349
376
350
- To learn more about connection pooling, see :ref:`How Does Connection
351
- Pooling Work in the Node Driver? <node-faq-connection-pool>`.
377
+ To learn more about connection pooling, see the :ref:`How Does Connection
378
+ Pooling Work in the Node Driver? <node-faq-connection-pool>` FAQ entry .
352
379
353
380
How Can I Ensure My Connection String Is Valid for a Replica Set?
354
381
-----------------------------------------------------------------
0 commit comments