Skip to content

Commit 54db77e

Browse files
committed
DOCSP-31596: improve slow operation faq (#728)
* DOCSP-31596: imrpove slow op faq * quick fix * CC PR fixes 1 * CC PR fixes 2 * small fixes (cherry picked from commit 29e65be)
1 parent 94ff272 commit 54db77e

File tree

1 file changed

+45
-18
lines changed

1 file changed

+45
-18
lines changed

source/faq.txt

+45-18
Original file line numberDiff line numberDiff line change
@@ -226,7 +226,7 @@ will close the socket. We recommend that you select a value
226226
for ``socketTimeoutMS`` that is two to three times as long as the
227227
expected duration of the slowest operation that your application executes.
228228

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?
230230
--------------------------------------------------------------------
231231

232232
Having a large connection pool does not always reduce reconnection
@@ -297,7 +297,8 @@ socket connections.
297297
If you experience unexpected network behavior, here
298298
are some things to check:
299299

300-
#. The firewall should send a ``FIN packet`` when closing a socket,allowing the driver to detect that the socket is closed.
300+
#. The firewall should send a ``FIN packet`` when closing a socket,
301+
allowing the driver to detect that the socket is closed.
301302
#. The firewall should allow ``keepAlive`` probes.
302303

303304
What Can I Do If I'm Getting "ECONNRESET" When Calling "client.connect()"?
@@ -332,25 +333,51 @@ This sets the maximum number of ``file descriptors`` for the process to
332333
How Can I Prevent a Slow Operation From Delaying Other Operations?
333334
------------------------------------------------------------------
334335

335-
To control the maximum size of a connection pool, you can set the
336-
``maxPoolSize`` option in the :ref:`connection options
337-
<node-connection-options>`. The default value of ``maxPoolSize`` is
338-
``100``. If the number of in-use connections to a server reaches
339-
``maxPoolSize``, the next request to that server will wait
340-
until a connection becomes available. To prevent long-running operations
341-
from slowing down your application, you can increase ``maxPoolSize``.
342-
343-
The driver does not limit the number of requests that can wait for
344-
sockets to become available. Requests wait for the amount of time
345-
specified in the ``waitQueueTimeoutMS`` option, which
346-
defaults to ``0`` (no limit). You should set this option if it is
347-
more important to stop long-running operations than it is to complete
348-
every operation.
336+
When you use the same ``MongoClient`` instance to run multiple MongoDB
337+
operations concurrently, a slow operation can cause delays to other
338+
operations. Slow operations keep a connection to MongoDB occupied,
339+
which can cause other operations to wait until an additional connection
340+
becomes available.
341+
342+
If you suspect that slow MongoDB operations are causing delays, you
343+
can check the performance of all in-progress operations by using the
344+
following methods:
345+
346+
- Enable the database profiler on your deployment. To learn more, see
347+
:manual:`Database Profiler </tutorial/manage-the-database-profiler/>`
348+
in the Server manual.
349+
- Run the ``db.currentOp()`` MongoDB Shell command. To learn more, see the
350+
:manual:`db.currentOp() </reference/method/db.currentOp/>`
351+
documentation in the Server manual.
352+
- Enable connection pool monitoring. To learn more, see
353+
:ref:`node-connection-pool-monitoring`.
354+
355+
After you determine which operations are causing delays, try to improve
356+
the performance of these operations. Read the :website:`Best Practices
357+
Guide for MongoDB Performance </basics/best-practices>` for possible solutions.
358+
359+
If you implement performance best practices but still
360+
experience delays, you can modify your connection settings to increase
361+
the size of the connection pool. A connection pool is the group of
362+
connections to the server that the driver maintains at any time.
363+
364+
To specify the maximum size of a
365+
connection pool, you can set the ``maxPoolSize`` option in the
366+
:ref:`connection options <node-connection-options>` for your
367+
``MongoClient`` instance. The default value
368+
of ``maxPoolSize`` is ``100``. If the number of in-use connections to a
369+
server reaches ``maxPoolSize``, the next operation sent to the server
370+
pauses until a connection to the driver becomes available. The following
371+
code sets ``maxPoolSize`` to ``150`` when creating a new ``MongoClient``:
372+
373+
.. code-block:: js
374+
375+
const client = new MongoClient(uri, { maxPoolSize: 150 });
349376

350377
.. tip::
351378

352-
To learn more about connection pooling, see :ref:`How Does Connection
353-
Pooling Work in the Node Driver? <node-faq-connection-pool>`.
379+
To learn more about connection pooling, see the :ref:`How Does Connection
380+
Pooling Work in the Node Driver? <node-faq-connection-pool>` FAQ entry.
354381

355382
How Can I Ensure My Connection String Is Valid for a Replica Set?
356383
-----------------------------------------------------------------

0 commit comments

Comments
 (0)