Skip to content

DOCSP-29272: fix pool sizing question in faq #689

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 17, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 18 additions & 28 deletions source/faq.txt
Original file line number Diff line number Diff line change
Expand Up @@ -332,35 +332,25 @@ This sets the maximum number of ``file descriptors`` for the process to
How Can I Prevent a Slow Operation From Delaying Other Operations?
------------------------------------------------------------------

A slow operation may delay your other operations that occur after it, if
the ``maxPoolSize`` has not been set in the
:ref:`connection options <node-connection-options>`.
MongoDB is synchronous and uses a single execution thread per socket,
meaning that MongoDB will execute one single operation per socket at any
point in time. Any other operation sent to that socket will have to wait
until the current operation is finished. If you have a slow-running
operation that holds up other operations, the best solution is to create
a separate connection pool for the slow operation, isolating it from
other, faster operations.

.. note::
If the number of operations is greater than the value of the
``maxPoolSize`` option and a slow operation occurs, subsequent
operations will be delayed.

To create a separate connection pool, instantiate another ``MongoClient``
call the ``connect()`` method on it. See the following example for the
syntax you can use to create two clients, each with its own connection
pool:

.. code-block:: javascript

const clientA = new MongoClient(uri, options);
clientA.connect(); // any method calls on clientA use clientA's connection pool

const clientB = new MongoClient(uri, options);
clientB.connect(); // any method calls on clientB use clientB's connection pool
To control the maximum size of a connection pool, you can set the
``maxPoolSize`` option in the :ref:`connection options
<node-connection-options>`. The default value of ``maxPoolSize`` is
``100``. If the number of in-use connections to a server reaches
``maxPoolSize``, the next request to that server will wait
until a connection becomes available. To prevent long-running operations
from slowing down your application, you can increase ``maxPoolSize``.

The driver does not limit the number of requests that can wait for
sockets to become available. Requests wait for the amount of time
specified in the ``waitQueueTimeoutMS`` option, which
defaults to ``0`` (no limit). You should set this option if it is
more important to stop long-running operations than it is to complete
every operation.

.. tip::

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

How Can I Ensure My Connection String Is Valid for a Replica Set?
-----------------------------------------------------------------
Expand Down