From 81b74fc31560c56bcf40447ba6ed3a3fd190af0b Mon Sep 17 00:00:00 2001 From: Lindsey Moore Date: Thu, 20 Feb 2025 13:59:25 -0500 Subject: [PATCH 01/17] DOCSP-47031 Connection Pools --- source/connection/connection-pools.txt | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) create mode 100644 source/connection/connection-pools.txt diff --git a/source/connection/connection-pools.txt b/source/connection/connection-pools.txt new file mode 100644 index 000000000..e67c6ea28 --- /dev/null +++ b/source/connection/connection-pools.txt @@ -0,0 +1,16 @@ +.. _java-connection-pools: + +================ +Connection Pools +================ + +.. contents:: On this page + :local: + :backlinks: none + :depth: 1 + :class: singlecol + +.. facet:: + :name: genre + :values: reference + From 36fd4f2454da03cacdfa994799d0a706f4b92b3c Mon Sep 17 00:00:00 2001 From: Lindsey Moore Date: Fri, 21 Feb 2025 15:56:37 -0500 Subject: [PATCH 02/17] code and table --- source/connection/connection-pools.txt | 138 ++++++++++++++++++ .../code-snippets/ConnectionPool.java | 35 +++++ .../{mcs.java => MCSettings.java} | 4 +- 3 files changed, 175 insertions(+), 2 deletions(-) create mode 100644 source/includes/fundamentals/code-snippets/ConnectionPool.java rename source/includes/fundamentals/code-snippets/{mcs.java => MCSettings.java} (98%) diff --git a/source/connection/connection-pools.txt b/source/connection/connection-pools.txt index e67c6ea28..a6bc45849 100644 --- a/source/connection/connection-pools.txt +++ b/source/connection/connection-pools.txt @@ -14,3 +14,141 @@ Connection Pools :name: genre :values: reference +Overview +-------- + +This guide shows you how to create and configure a connection pool associated +with a ``MongoClient``. + +Create and Use a Connection Pool +-------------------------------- + +Every ``MongoClient`` instance has a built-in connection pool for each server +in your MongoDB topology. Connection pools open sockets on demand to support +concurrent MongoDB operations in your multi-threaded application. + +The maximum size of each connection pool is set by the ``maxPoolSize`` option, which +defaults to 100. If the number of in-use connections to a server reaches the +value of maxPoolSize, the next request to that server will wait until a +connection becomes available. + +Each ``MongoClient`` instance opens two additional sockets per server in your MongoDB +topology for monitoring the server's state. + +Configure a Connection Pool +--------------------------- + +You can specify settings for your connection pool using either a connection +string or by passing a ``MongoClientSettings`` object to the +``MongoClients.create()`` method. + +The following code creates a client with a maximum connection pool size of ``50`` +by using either a connection string or ``MongoClientSettings`` object: + +. tabs:: + + .. tab:: Connection String + :tabid: uri + + .. code-block:: java + + MongoClient mongoClient = MongoClients.create("mongodb://:/?maxPoolSize=50") + + .. tab:: ``MongoClientSettings`` + :tabid: MongoClient + + .. literalinclude:: /includes/fundamentals/code-snippets/mcs.java + :start-after: begin MongoSettings + :end-before: end MongoSettings + :language: java + :dedent: + +For more information on these connection string options, see the +:ref:`Connection Options ` +guide. + +For more information on configuring you connection pool by using a +``MongoClientSettings`` object see the Connection Pool Settings section +of the :ref:`` guide. + +Connection Pool Settings +~~~~~~~~~~~~~~~~~~~~~~~~ + +The following are connection string settings you can use to configure your +connection pool: + +.. list-table:: + :widths: 25,75 + :header-rows: 1 + + * - Setting + - Description + + * - :urioption:`connectTimeoutMS` + + - Specifies the maximum amount of time, in milliseconds, the Java driver + waits for a connection to open before timing out. A value of 0 instructs + the driver to never time out while waiting for a connection to open. + + *Default:* ``10000`` (10 seconds) + + * - :urioption:`maxConnecting` + + - Maximum number of connections a pool may be establishing + concurrently. + + .. include:: /includes/connection-pool/max-connecting-use-case.rst + + *Default:* ``2`` + + * - :urioption:`maxIdleTimeMS` + + - The maximum number of milliseconds that a connection can + remain idle in the pool before being removed and closed. + + *Default:* ``0`` + + * - :urioption:`maxPoolSize` + + - Maximum number of connections opened in the pool. When the + connection pool reaches the maximum number of connections, new + connections wait up until to the value of + :urioption:`waitQueueTimeoutMS`. + + *Default:* ``100`` + + * - :urioption:`minPoolSize` + + - Minimum number of connections opened in the pool. + The value of :urioption:`minPoolSize` must be less than + the value of :urioption:`maxPoolSize`. + + *Default*: ``0`` + + * - :urioption:`socketTimeoutMS` + + - Number of milliseconds to wait before timeout on a TCP + connection. + + Do *not* use :urioption:`socketTimeoutMS` as a mechanism for + preventing long-running server operations. + + Setting low socket timeouts may result in operations that error + before the server responds. + + *Default*: ``0``, which means no timeout. + + * - :urioption:`waitQueueTimeoutMS` + + - Maximum wait time in milliseconds that a can thread wait for + a connection to become available. A value of ``0`` means there + is no limit. + + *Default*: ``120000`` (120 seconds) + +Additional Information +---------------------- + +For more information on using a connection pool, see the +:manual:`Connection Pool ` +documentation in the Server manual. diff --git a/source/includes/fundamentals/code-snippets/ConnectionPool.java b/source/includes/fundamentals/code-snippets/ConnectionPool.java new file mode 100644 index 000000000..097981b61 --- /dev/null +++ b/source/includes/fundamentals/code-snippets/ConnectionPool.java @@ -0,0 +1,35 @@ +import static java.util.concurrent.TimeUnit.*; + +import com.mongodb.client.MongoClient; +import com.mongodb.client.MongoClients; +import com.mongodb.connection.ClusterConnectionMode; +import com.mongodb.ConnectionString; +import com.mongodb.MongoClientSettings; + +public class ConnectionPool { + + public static void main(String[] args) { + + System.out.println("MongoSettings:"); + createMongoSettings(); + System.out.println(); + + } + + private static void createMongoSettings() { + try { + //begin MongoSettings + MongoClient mongoClient = MongoClients.create( + MongoClientSettings.builder().applyConnectionString(new ConnectionString("")) + .applyToConnectionPoolSettings(builder -> + builder.maxSize(50)) + .build()); + //end MongoSettings + mongoClient.listDatabaseNames().forEach(n -> System.out.println(n)); + mongoClient.close(); + } finally { + System.out.print("---------------------------------------"); + } + } + +} \ No newline at end of file diff --git a/source/includes/fundamentals/code-snippets/mcs.java b/source/includes/fundamentals/code-snippets/MCSettings.java similarity index 98% rename from source/includes/fundamentals/code-snippets/mcs.java rename to source/includes/fundamentals/code-snippets/MCSettings.java index 23a424cfb..c38717be8 100644 --- a/source/includes/fundamentals/code-snippets/mcs.java +++ b/source/includes/fundamentals/code-snippets/MCSettings.java @@ -58,7 +58,7 @@ private static void createClusterSettings() { MongoClient mongoClient = MongoClients.create( MongoClientSettings.builder() .applyToClusterSettings(builder -> - builder.mode(ClusterConnectionMode.SINGLE) + builder.mode(ClusterConnectionMode.SINGLE)) .build()); //end ClusterSettings mongoClient.listDatabaseNames().forEach(n -> System.out.println(n)); @@ -109,7 +109,7 @@ private static void createConnectionPoolSettings() { MongoClientSettings.builder().applyConnectionString(new ConnectionString("")) .applyToConnectionPoolSettings(builder -> builder.maxWaitTime(10, SECONDS) - .maxSize(200) + .maxSize(200)) .build()); //end ConnectionPoolSettings mongoClient.listDatabaseNames().forEach(n -> System.out.println(n)); From c5c6abcfd364fb0e49203394bb92d017a5e52c8c Mon Sep 17 00:00:00 2001 From: Lindsey Moore Date: Fri, 21 Feb 2025 15:57:49 -0500 Subject: [PATCH 03/17] new line --- source/includes/fundamentals/code-snippets/ConnectionPool.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/source/includes/fundamentals/code-snippets/ConnectionPool.java b/source/includes/fundamentals/code-snippets/ConnectionPool.java index 097981b61..48cbf4d4e 100644 --- a/source/includes/fundamentals/code-snippets/ConnectionPool.java +++ b/source/includes/fundamentals/code-snippets/ConnectionPool.java @@ -32,4 +32,4 @@ private static void createMongoSettings() { } } -} \ No newline at end of file +} From 2571150f66b07c9f8e42dc459e294f6852c08396 Mon Sep 17 00:00:00 2001 From: Lindsey Moore Date: Fri, 21 Feb 2025 16:00:53 -0500 Subject: [PATCH 04/17] add code file --- source/connection/connection-pools.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/source/connection/connection-pools.txt b/source/connection/connection-pools.txt index a6bc45849..6b97c2a1a 100644 --- a/source/connection/connection-pools.txt +++ b/source/connection/connection-pools.txt @@ -57,7 +57,7 @@ by using either a connection string or ``MongoClientSettings`` object: .. tab:: ``MongoClientSettings`` :tabid: MongoClient - .. literalinclude:: /includes/fundamentals/code-snippets/mcs.java + .. literalinclude:: /includes/fundamentals/code-snippets/ConnectionPool.java :start-after: begin MongoSettings :end-before: end MongoSettings :language: java From 89b304f7f0014da7db23000c143dd08746cffa0a Mon Sep 17 00:00:00 2001 From: Lindsey Moore Date: Fri, 21 Feb 2025 16:01:27 -0500 Subject: [PATCH 05/17] fix tabs --- source/connection/connection-pools.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/source/connection/connection-pools.txt b/source/connection/connection-pools.txt index 6b97c2a1a..c111c923f 100644 --- a/source/connection/connection-pools.txt +++ b/source/connection/connection-pools.txt @@ -45,7 +45,7 @@ string or by passing a ``MongoClientSettings`` object to the The following code creates a client with a maximum connection pool size of ``50`` by using either a connection string or ``MongoClientSettings`` object: -. tabs:: +.. tabs:: .. tab:: Connection String :tabid: uri From 5ebc72bf7557e0451b683ff2b25bf83caec28b79 Mon Sep 17 00:00:00 2001 From: Lindsey Moore Date: Fri, 21 Feb 2025 16:10:43 -0500 Subject: [PATCH 06/17] edit --- source/connection/connection-pools.txt | 33 ++++++++++++++++---------- 1 file changed, 21 insertions(+), 12 deletions(-) diff --git a/source/connection/connection-pools.txt b/source/connection/connection-pools.txt index c111c923f..6863c3173 100644 --- a/source/connection/connection-pools.txt +++ b/source/connection/connection-pools.txt @@ -7,7 +7,7 @@ Connection Pools .. contents:: On this page :local: :backlinks: none - :depth: 1 + :depth: 2 :class: singlecol .. facet:: @@ -17,8 +17,17 @@ Connection Pools Overview -------- -This guide shows you how to create and configure a connection pool associated -with a ``MongoClient``. +In this guide, you can learn about how {+driver-short+} uses connection pools to manage +connections to a MongoDB deployment and how you can configure connection pool settings +in your application. + +A connection pool is a cache of open database connections maintained by {+driver-short+}. +When your application requests a connection to MongoDB, {+driver-short+} seamlessly +gets a connection from the pool, performs operations, and returns the connection +to the pool for reuse. + +Connection pools help reduce application latency and the number of times new connections +are created by {+driver-short+}. Create and Use a Connection Pool -------------------------------- @@ -54,7 +63,7 @@ by using either a connection string or ``MongoClientSettings`` object: MongoClient mongoClient = MongoClients.create("mongodb://:/?maxPoolSize=50") - .. tab:: ``MongoClientSettings`` + .. tab:: MongoClientSettings :tabid: MongoClient .. literalinclude:: /includes/fundamentals/code-snippets/ConnectionPool.java @@ -63,14 +72,6 @@ by using either a connection string or ``MongoClientSettings`` object: :language: java :dedent: -For more information on these connection string options, see the -:ref:`Connection Options ` -guide. - -For more information on configuring you connection pool by using a -``MongoClientSettings`` object see the Connection Pool Settings section -of the :ref:`` guide. - Connection Pool Settings ~~~~~~~~~~~~~~~~~~~~~~~~ @@ -146,6 +147,14 @@ connection pool: *Default*: ``120000`` (120 seconds) +For more information on these connection string options, see the +:ref:`Connection Options ` +guide. + +For more information on configuring you connection pool by using a +``MongoClientSettings`` object see the Connection Pool Settings section +of the :ref:`` guide. + Additional Information ---------------------- From af5da6bd75d61eab431f531a1ec09d3f360fe6fa Mon Sep 17 00:00:00 2001 From: Lindsey Moore Date: Fri, 21 Feb 2025 16:13:32 -0500 Subject: [PATCH 07/17] edits --- source/connection/connection-pools.txt | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/source/connection/connection-pools.txt b/source/connection/connection-pools.txt index 6863c3173..9bb955d1f 100644 --- a/source/connection/connection-pools.txt +++ b/source/connection/connection-pools.txt @@ -95,7 +95,7 @@ connection pool: * - :urioption:`maxConnecting` - - Maximum number of connections a pool may be establishing + - Maximum number of connections a pool may establish concurrently. .. include:: /includes/connection-pool/max-connecting-use-case.rst @@ -141,7 +141,7 @@ connection pool: * - :urioption:`waitQueueTimeoutMS` - - Maximum wait time in milliseconds that a can thread wait for + - Maximum wait time in milliseconds that a thread can wait for a connection to become available. A value of ``0`` means there is no limit. From ff6deeb20c24d6059210d2b79a759af67dea1b04 Mon Sep 17 00:00:00 2001 From: Lindsey Moore Date: Fri, 21 Feb 2025 16:35:47 -0500 Subject: [PATCH 08/17] add to toc --- source/connection.txt | 1 + source/connection/connection-pools.txt | 6 ++++-- .../includes/fundamentals/code-snippets/ConnectionPool.java | 3 ++- 3 files changed, 7 insertions(+), 3 deletions(-) diff --git a/source/connection.txt b/source/connection.txt index d34dc63f2..92a7feda6 100644 --- a/source/connection.txt +++ b/source/connection.txt @@ -10,6 +10,7 @@ Connection Guide Connection Options MongoClient Settings Stable API + Connection Pools Network Compression JNDI Datasource Connection Troubleshooting diff --git a/source/connection/connection-pools.txt b/source/connection/connection-pools.txt index 9bb955d1f..57c0656e5 100644 --- a/source/connection/connection-pools.txt +++ b/source/connection/connection-pools.txt @@ -52,7 +52,8 @@ string or by passing a ``MongoClientSettings`` object to the ``MongoClients.create()`` method. The following code creates a client with a maximum connection pool size of ``50`` -by using either a connection string or ``MongoClientSettings`` object: +by using either a :guilabel:`Connection String` or :guilabel:`MongoClientSettings` +object: .. tabs:: @@ -61,7 +62,8 @@ by using either a connection string or ``MongoClientSettings`` object: .. code-block:: java - MongoClient mongoClient = MongoClients.create("mongodb://:/?maxPoolSize=50") + ConnectionString connectionString = "mongodb://:/?maxPoolSize=50" + MongoClient mongoClient = MongoClients.create(connectionString) .. tab:: MongoClientSettings :tabid: MongoClient diff --git a/source/includes/fundamentals/code-snippets/ConnectionPool.java b/source/includes/fundamentals/code-snippets/ConnectionPool.java index 48cbf4d4e..f3b7b817e 100644 --- a/source/includes/fundamentals/code-snippets/ConnectionPool.java +++ b/source/includes/fundamentals/code-snippets/ConnectionPool.java @@ -20,7 +20,8 @@ private static void createMongoSettings() { try { //begin MongoSettings MongoClient mongoClient = MongoClients.create( - MongoClientSettings.builder().applyConnectionString(new ConnectionString("")) + MongoClientSettings.builder().applyConnectionString( + new ConnectionString("")) .applyToConnectionPoolSettings(builder -> builder.maxSize(50)) .build()); From b24c1b968baefae0a5250707be1063f725839564 Mon Sep 17 00:00:00 2001 From: Lindsey Moore Date: Fri, 21 Feb 2025 16:37:34 -0500 Subject: [PATCH 09/17] edit title --- source/connection/connection-pools.txt | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/source/connection/connection-pools.txt b/source/connection/connection-pools.txt index 57c0656e5..125bfa8d9 100644 --- a/source/connection/connection-pools.txt +++ b/source/connection/connection-pools.txt @@ -29,8 +29,8 @@ to the pool for reuse. Connection pools help reduce application latency and the number of times new connections are created by {+driver-short+}. -Create and Use a Connection Pool --------------------------------- +Create a Connection Pool +------------------------ Every ``MongoClient`` instance has a built-in connection pool for each server in your MongoDB topology. Connection pools open sockets on demand to support From 8266c195739e39ed88b0df8f2657d7c96aba719a Mon Sep 17 00:00:00 2001 From: Lindsey Moore Date: Fri, 21 Feb 2025 16:41:53 -0500 Subject: [PATCH 10/17] another small edit --- source/connection/connection-pools.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/source/connection/connection-pools.txt b/source/connection/connection-pools.txt index 125bfa8d9..89b1dddfd 100644 --- a/source/connection/connection-pools.txt +++ b/source/connection/connection-pools.txt @@ -36,7 +36,7 @@ Every ``MongoClient`` instance has a built-in connection pool for each server in your MongoDB topology. Connection pools open sockets on demand to support concurrent MongoDB operations in your multi-threaded application. -The maximum size of each connection pool is set by the ``maxPoolSize`` option, which +The ``maxPoolSize`` option sets the maximum size of each connection pool, which defaults to 100. If the number of in-use connections to a server reaches the value of maxPoolSize, the next request to that server will wait until a connection becomes available. From 3740ec89fe03fd186ec14b5ca55b2e9e0e08b731 Mon Sep 17 00:00:00 2001 From: Lindsey Moore Date: Mon, 24 Feb 2025 13:08:39 -0500 Subject: [PATCH 11/17] rachel feedback --- source/connection/connection-pools.txt | 151 ++++++++++++------------- 1 file changed, 73 insertions(+), 78 deletions(-) diff --git a/source/connection/connection-pools.txt b/source/connection/connection-pools.txt index 89b1dddfd..29a0d81a4 100644 --- a/source/connection/connection-pools.txt +++ b/source/connection/connection-pools.txt @@ -52,110 +52,105 @@ string or by passing a ``MongoClientSettings`` object to the ``MongoClients.create()`` method. The following code creates a client with a maximum connection pool size of ``50`` -by using either a :guilabel:`Connection String` or :guilabel:`MongoClientSettings` +by using either a connection String or MongoClientSettings object: .. tabs:: - .. tab:: Connection String - :tabid: uri + .. tab:: Connection String + :tabid: uri + + .. code-block:: java - .. code-block:: java + ConnectionString connectionString = "mongodb://:/?maxPoolSize=50" + MongoClient mongoClient = MongoClients.create(connectionString) - ConnectionString connectionString = "mongodb://:/?maxPoolSize=50" - MongoClient mongoClient = MongoClients.create(connectionString) + The following are connection string settings you can use to configure your + connection pool: - .. tab:: MongoClientSettings - :tabid: MongoClient - - .. literalinclude:: /includes/fundamentals/code-snippets/ConnectionPool.java - :start-after: begin MongoSettings - :end-before: end MongoSettings - :language: java - :dedent: - -Connection Pool Settings -~~~~~~~~~~~~~~~~~~~~~~~~ + .. list-table:: + :widths: 25,75 + :header-rows: 1 -The following are connection string settings you can use to configure your -connection pool: + * - Setting + - Description + + * - :urioption:`connectTimeoutMS` -.. list-table:: - :widths: 25,75 - :header-rows: 1 + - Specifies the maximum amount of time, in milliseconds, the Java driver + waits for a connection to open before timing out. A value of 0 instructs + the driver to never time out while waiting for a connection to open. + + *Default:* ``10000`` (10 seconds) + + * - :urioption:`maxConnecting` + + - Maximum number of connections a pool may establish + concurrently. - * - Setting - - Description - - * - :urioption:`connectTimeoutMS` + *Default:* ``2`` + + * - :urioption:`maxIdleTimeMS` + + - The maximum number of milliseconds that a connection can + remain idle in the pool before being removed and closed. - - Specifies the maximum amount of time, in milliseconds, the Java driver - waits for a connection to open before timing out. A value of 0 instructs - the driver to never time out while waiting for a connection to open. - - *Default:* ``10000`` (10 seconds) - - * - :urioption:`maxConnecting` - - - Maximum number of connections a pool may establish - concurrently. + *Default:* ``0`` + + * - :urioption:`maxPoolSize` - .. include:: /includes/connection-pool/max-connecting-use-case.rst + - Maximum number of connections opened in the pool. When the + connection pool reaches the maximum number of connections, new + connections wait up until to the value of + :urioption:`waitQueueTimeoutMS`. - *Default:* ``2`` - - * - :urioption:`maxIdleTimeMS` - - - The maximum number of milliseconds that a connection can - remain idle in the pool before being removed and closed. + *Default:* ``100`` - *Default:* ``0`` - - * - :urioption:`maxPoolSize` + * - :urioption:`minPoolSize` - - Maximum number of connections opened in the pool. When the - connection pool reaches the maximum number of connections, new - connections wait up until to the value of - :urioption:`waitQueueTimeoutMS`. + - Minimum number of connections opened in the pool. + The value of :urioption:`minPoolSize` must be less than + the value of :urioption:`maxPoolSize`. - *Default:* ``100`` + *Default*: ``0`` - * - :urioption:`minPoolSize` + * - :urioption:`socketTimeoutMS` - - Minimum number of connections opened in the pool. - The value of :urioption:`minPoolSize` must be less than - the value of :urioption:`maxPoolSize`. + - Number of milliseconds to wait before timeout on a TCP + connection. + + Do *not* use :urioption:`socketTimeoutMS` as a mechanism for + preventing long-running server operations. - *Default*: ``0`` + Setting low socket timeouts may result in operations that error + before the server responds. + + *Default*: ``0``, which means no timeout. - * - :urioption:`socketTimeoutMS` + * - :urioption:`waitQueueTimeoutMS` - - Number of milliseconds to wait before timeout on a TCP - connection. - - Do *not* use :urioption:`socketTimeoutMS` as a mechanism for - preventing long-running server operations. + - Maximum wait time in milliseconds that a thread can wait for + a connection to become available. A value of ``0`` means there + is no limit. - Setting low socket timeouts may result in operations that error - before the server responds. - - *Default*: ``0``, which means no timeout. + *Default*: ``120000`` (120 seconds) - * - :urioption:`waitQueueTimeoutMS` + For more information on these connection string options, see the + :ref:`Connection Options ` + guide. - - Maximum wait time in milliseconds that a thread can wait for - a connection to become available. A value of ``0`` means there - is no limit. - - *Default*: ``120000`` (120 seconds) + .. tab:: MongoClientSettings + :tabid: MongoClient -For more information on these connection string options, see the -:ref:`Connection Options ` -guide. + .. literalinclude:: /includes/fundamentals/code-snippets/ConnectionPool.java + :start-after: begin MongoSettings + :end-before: end MongoSettings + :language: java + :dedent: -For more information on configuring you connection pool by using a -``MongoClientSettings`` object see the Connection Pool Settings section -of the :ref:`` guide. + For more information on configuring you connection pool by using a + ``MongoClientSettings`` object see the Connection Pool Settings section + of the :ref:`` guide. Additional Information ---------------------- From 0a0a0365e58daacae4d2a535ebc6a54f16e1d74e Mon Sep 17 00:00:00 2001 From: Lindsey Moore Date: Mon, 24 Feb 2025 13:15:02 -0500 Subject: [PATCH 12/17] edit tab copy --- source/connection/connection-pools.txt | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/source/connection/connection-pools.txt b/source/connection/connection-pools.txt index 29a0d81a4..f69ed4138 100644 --- a/source/connection/connection-pools.txt +++ b/source/connection/connection-pools.txt @@ -51,9 +51,9 @@ You can specify settings for your connection pool using either a connection string or by passing a ``MongoClientSettings`` object to the ``MongoClients.create()`` method. -The following code creates a client with a maximum connection pool size of ``50`` -by using either a connection String or MongoClientSettings -object: +The following code creates a client with a maximum connection pool size of ``50``. +Select the :guilabel:`Connection String` or :guilabel:`MongoClientSettings` tab to +see the corresponding syntax: .. tabs:: From 2e62d52bae8737db13d84f6eec6039a52e23bec1 Mon Sep 17 00:00:00 2001 From: Lindsey Moore Date: Mon, 24 Feb 2025 13:19:18 -0500 Subject: [PATCH 13/17] format --- source/connection/connection-pools.txt | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/source/connection/connection-pools.txt b/source/connection/connection-pools.txt index f69ed4138..0ea394649 100644 --- a/source/connection/connection-pools.txt +++ b/source/connection/connection-pools.txt @@ -65,8 +65,8 @@ see the corresponding syntax: ConnectionString connectionString = "mongodb://:/?maxPoolSize=50" MongoClient mongoClient = MongoClients.create(connectionString) - The following are connection string settings you can use to configure your - connection pool: + The following are connection string settings you can use to configure your + connection pool: .. list-table:: :widths: 25,75 From b2840114c5da87ee551127e5b8c940c69910df27 Mon Sep 17 00:00:00 2001 From: Lindsey Moore Date: Mon, 24 Feb 2025 17:45:53 -0500 Subject: [PATCH 14/17] remove unnecessary links to server options --- source/connection/connection-pools.txt | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/source/connection/connection-pools.txt b/source/connection/connection-pools.txt index 0ea394649..cf0534725 100644 --- a/source/connection/connection-pools.txt +++ b/source/connection/connection-pools.txt @@ -75,7 +75,7 @@ see the corresponding syntax: * - Setting - Description - * - :urioption:`connectTimeoutMS` + * - ``connectTimeoutMS`` - Specifies the maximum amount of time, in milliseconds, the Java driver waits for a connection to open before timing out. A value of 0 instructs @@ -83,43 +83,43 @@ see the corresponding syntax: *Default:* ``10000`` (10 seconds) - * - :urioption:`maxConnecting` + * - ``maxConnecting`` - Maximum number of connections a pool may establish concurrently. *Default:* ``2`` - * - :urioption:`maxIdleTimeMS` + * - ``maxIdleTimeMS`` - The maximum number of milliseconds that a connection can remain idle in the pool before being removed and closed. *Default:* ``0`` - * - :urioption:`maxPoolSize` + * - ``maxPoolSize`` - Maximum number of connections opened in the pool. When the connection pool reaches the maximum number of connections, new connections wait up until to the value of - :urioption:`waitQueueTimeoutMS`. + ``waitQueueTimeoutMS``. *Default:* ``100`` - * - :urioption:`minPoolSize` + * - ``minPoolSize`` - Minimum number of connections opened in the pool. - The value of :urioption:`minPoolSize` must be less than - the value of :urioption:`maxPoolSize`. + The value of ``minPoolSize`` must be less than + the value of ``maxPoolSize``. *Default*: ``0`` - * - :urioption:`socketTimeoutMS` + * - ``socketTimeoutMS`` - Number of milliseconds to wait before timeout on a TCP connection. - Do *not* use :urioption:`socketTimeoutMS` as a mechanism for + Do *not* use ``socketTimeoutMS`` as a mechanism for preventing long-running server operations. Setting low socket timeouts may result in operations that error @@ -127,7 +127,7 @@ see the corresponding syntax: *Default*: ``0``, which means no timeout. - * - :urioption:`waitQueueTimeoutMS` + * - ``waitQueueTimeoutMS`` - Maximum wait time in milliseconds that a thread can wait for a connection to become available. A value of ``0`` means there From c6a081527b88cb06f0128da3ff151c76345f1ae5 Mon Sep 17 00:00:00 2001 From: Lindsey Moore Date: Mon, 24 Feb 2025 17:50:00 -0500 Subject: [PATCH 15/17] vale --- source/connection/connection-pools.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/source/connection/connection-pools.txt b/source/connection/connection-pools.txt index cf0534725..1aef27a8c 100644 --- a/source/connection/connection-pools.txt +++ b/source/connection/connection-pools.txt @@ -41,7 +41,7 @@ defaults to 100. If the number of in-use connections to a server reaches the value of maxPoolSize, the next request to that server will wait until a connection becomes available. -Each ``MongoClient`` instance opens two additional sockets per server in your MongoDB +Each ``MongoClient`` instance opens two more sockets per server in your MongoDB topology for monitoring the server's state. Configure a Connection Pool From 7bd7662e15cbf8f625453c727afa4f52aeb46916 Mon Sep 17 00:00:00 2001 From: Lindsey Moore Date: Fri, 28 Feb 2025 11:12:25 -0500 Subject: [PATCH 16/17] tech review --- source/connection/connection-pools.txt | 25 ++----------------------- 1 file changed, 2 insertions(+), 23 deletions(-) diff --git a/source/connection/connection-pools.txt b/source/connection/connection-pools.txt index 1aef27a8c..f56ee94e4 100644 --- a/source/connection/connection-pools.txt +++ b/source/connection/connection-pools.txt @@ -74,14 +74,6 @@ see the corresponding syntax: * - Setting - Description - - * - ``connectTimeoutMS`` - - - Specifies the maximum amount of time, in milliseconds, the Java driver - waits for a connection to open before timing out. A value of 0 instructs - the driver to never time out while waiting for a connection to open. - - *Default:* ``10000`` (10 seconds) * - ``maxConnecting`` @@ -114,28 +106,15 @@ see the corresponding syntax: *Default*: ``0`` - * - ``socketTimeoutMS`` - - - Number of milliseconds to wait before timeout on a TCP - connection. - - Do *not* use ``socketTimeoutMS`` as a mechanism for - preventing long-running server operations. - - Setting low socket timeouts may result in operations that error - before the server responds. - - *Default*: ``0``, which means no timeout. - * - ``waitQueueTimeoutMS`` - - Maximum wait time in milliseconds that a thread can wait for + - Maximum wait time in milliseconds that an operation can wait for a connection to become available. A value of ``0`` means there is no limit. *Default*: ``120000`` (120 seconds) - For more information on these connection string options, see the + To learn more about connection string options, see the :ref:`Connection Options ` guide. From 50e502bbd8a59a897fa79e899b3b1465e4a48489 Mon Sep 17 00:00:00 2001 From: Lindsey Moore Date: Wed, 5 Mar 2025 16:54:51 -0500 Subject: [PATCH 17/17] small edits --- source/connection/connection-pools.txt | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/source/connection/connection-pools.txt b/source/connection/connection-pools.txt index f56ee94e4..26e18b75c 100644 --- a/source/connection/connection-pools.txt +++ b/source/connection/connection-pools.txt @@ -17,12 +17,12 @@ Connection Pools Overview -------- -In this guide, you can learn about how {+driver-short+} uses connection pools to manage +In this guide, you can learn about how the {+driver-short+} uses connection pools to manage connections to a MongoDB deployment and how you can configure connection pool settings in your application. -A connection pool is a cache of open database connections maintained by {+driver-short+}. -When your application requests a connection to MongoDB, {+driver-short+} seamlessly +A connection pool is a cache of open database connections maintained by the {+driver-short+}. +When your application requests a connection to MongoDB, the {+driver-short+} seamlessly gets a connection from the pool, performs operations, and returns the connection to the pool for reuse. @@ -38,7 +38,7 @@ concurrent MongoDB operations in your multi-threaded application. The ``maxPoolSize`` option sets the maximum size of each connection pool, which defaults to 100. If the number of in-use connections to a server reaches the -value of maxPoolSize, the next request to that server will wait until a +value of ``maxPoolSize``, the next request to that server will wait until a connection becomes available. Each ``MongoClient`` instance opens two more sockets per server in your MongoDB