Skip to content

Commit bfdcacc

Browse files
committed
DOCSP-29272: fix pool sizing q in faq (#689)
(cherry picked from commit b67a3d2)
1 parent bf82ed5 commit bfdcacc

File tree

1 file changed

+18
-28
lines changed

1 file changed

+18
-28
lines changed

source/faq.txt

Lines changed: 18 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -330,35 +330,25 @@ This sets the maximum number of ``file descriptors`` for the process to
330330
How Can I Prevent a Slow Operation From Delaying Other Operations?
331331
------------------------------------------------------------------
332332

333-
A slow operation may delay your other operations that occur after it, if
334-
the ``maxPoolSize`` has not been set in the
335-
:ref:`connection options <node-connection-options>`.
336-
MongoDB is synchronous and uses a single execution thread per socket,
337-
meaning that MongoDB will execute one single operation per socket at any
338-
point in time. Any other operation sent to that socket will have to wait
339-
until the current operation is finished. If you have a slow-running
340-
operation that holds up other operations, the best solution is to create
341-
a separate connection pool for the slow operation, isolating it from
342-
other, faster operations.
343-
344-
.. note::
345-
If the number of operations is greater than the value of the
346-
``maxPoolSize`` option and a slow operation occurs, subsequent
347-
operations will be delayed.
348-
349-
To create a separate connection pool, instantiate another ``MongoClient``
350-
call the ``connect()`` method on it. See the following example for the
351-
syntax you can use to create two clients, each with its own connection
352-
pool:
353-
354-
.. code-block:: javascript
355-
356-
const clientA = new MongoClient(uri, options);
357-
clientA.connect(); // any method calls on clientA use clientA's connection pool
358-
359-
const clientB = new MongoClient(uri, options);
360-
clientB.connect(); // any method calls on clientB use clientB's connection pool
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.
361347

348+
.. tip::
349+
350+
To learn more about connection pooling, see :ref:`How Does Connection
351+
Pooling Work in the Node Driver? <node-faq-connection-pool>`.
362352

363353
How Can I Ensure My Connection String Is Valid for a Replica Set?
364354
-----------------------------------------------------------------

0 commit comments

Comments
 (0)