Skip to content

Commit b67a3d2

Browse files
authored
DOCSP-29272: fix pool sizing q in faq (#689)
1 parent 693e7ab commit b67a3d2

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
@@ -332,35 +332,25 @@ This sets the maximum number of ``file descriptors`` for the process to
332332
How Can I Prevent a Slow Operation From Delaying Other Operations?
333333
------------------------------------------------------------------
334334

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

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

365355
How Can I Ensure My Connection String Is Valid for a Replica Set?
366356
-----------------------------------------------------------------

0 commit comments

Comments
 (0)