Skip to content

Commit a4e7efc

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

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

304-
A slow operation may delay your other operations that occur after it, if
305-
the ``maxPoolSize`` has not been set in the
306-
:ref:`connection options <node-connection-options>`.
307-
MongoDB is synchronous and uses a single execution thread per socket,
308-
meaning that MongoDB will execute one single operation per socket at any
309-
point in time. Any other operation sent to that socket will have to wait
310-
until the current operation is finished. If you have a slow-running
311-
operation that holds up other operations, the best solution is to create
312-
a separate connection pool for the slow operation, isolating it from
313-
other, faster operations.
314-
315-
.. note::
316-
If the number of operations is greater than the value of the
317-
``maxPoolSize`` option and a slow operation occurs, subsequent
318-
operations will be delayed.
319-
320-
To create a separate connection pool, instantiate another ``MongoClient``
321-
call the ``connect()`` method on it. See the following example for the
322-
syntax you can use to create two clients, each with its own connection
323-
pool:
324-
325-
.. code-block:: javascript
326-
327-
const clientA = new MongoClient(uri, options);
328-
clientA.connect(); // any method calls on clientA use clientA's connection pool
329-
330-
const clientB = new MongoClient(uri, options);
331-
clientB.connect(); // any method calls on clientB use clientB's connection pool
304+
To control the maximum size of a connection pool, you can set the
305+
``maxPoolSize`` option in the :ref:`connection options
306+
<node-connection-options>`. The default value of ``maxPoolSize`` is
307+
``100``. If the number of in-use connections to a server reaches
308+
``maxPoolSize``, the next request to that server will wait
309+
until a connection becomes available. To prevent long-running operations
310+
from slowing down your application, you can increase ``maxPoolSize``.
311+
312+
The driver does not limit the number of requests that can wait for
313+
sockets to become available. Requests wait for the amount of time
314+
specified in the ``waitQueueTimeoutMS`` option, which
315+
defaults to ``0`` (no limit). You should set this option if it is
316+
more important to stop long-running operations than it is to complete
317+
every operation.
332318

319+
.. tip::
320+
321+
To learn more about connection pooling, see :ref:`How Does Connection
322+
Pooling Work in the Node Driver? <node-faq-connection-pool>`.
333323

334324
How Can I Ensure My Connection String Is Valid for a Replica Set?
335325
-----------------------------------------------------------------

0 commit comments

Comments
 (0)