Skip to content

DOCSP-31596: improve slow operation faq #728

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 6 commits into from
Aug 4, 2023
Merged
Changes from 3 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
58 changes: 40 additions & 18 deletions source/faq.txt
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,7 @@ will close the socket. We recommend that you select a value
for ``socketTimeoutMS`` that is two to three times as long as the
expected duration of the slowest operation that your application executes.

How Can I Prevent Sockets From Timing out Before They Become Active?
How Can I Prevent Sockets From Timing Out Before They Become Active?
--------------------------------------------------------------------

Having a large connection pool does not always reduce reconnection
Expand Down Expand Up @@ -261,31 +261,53 @@ socket connections.
If you experience unexpected network behavior, here
are some things to check:

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

How Can I Prevent a Slow Operation From Delaying Other Operations?
------------------------------------------------------------------

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.
Before you make changes to your connection configuration or application,
you should determine which operations could be causing delays. You can
investigate the performance of in-progress operations by using the
following strategies:

- Enable the database profiler on your deployment. To learn more, see
:manual:`Database Profiler </tutorial/manage-the-database-profiler/>`
in the Server manual.
- Run the ``db.currentOp()`` :manual:`shell command </reference/method/>`. To learn more, see the
:manual:`db.currentOp() </reference/method/db.currentOp/>`
documentation in the Server manual.
- Enable connection pool monitoring. To learn more, see
:ref:`node-connection-pool-monitoring`.

Once you determine how and why your operations are delayed, if possible,
try to improve the performance of your application. Read the :website:`Best
Practices Guide for MongoDB Performance </basics/best-practices>` for
possible solutions.

If you cannot avoid time-consuming or slow operations, you can
modify your connection settings to increase the size of the connection
pool, a group of connections to the server that the driver maintains at
any time.

To specify 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 operation sent to the server
will wait until a connection becomes available. The following code sets
``maxPoolSize`` to ``150`` when creating a new ``MongoClient``:

.. code-block:: js

const client = new MongoClient(uri, { maxPoolSize: 150 });

.. tip::

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

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