From c92eb9a37ad0fcadb4c0772580919bc03755e7a1 Mon Sep 17 00:00:00 2001 From: norareidy Date: Mon, 8 Jan 2024 11:30:22 -0500 Subject: [PATCH 1/5] DOCSP-35254: Connection pooling subsections --- source/fundamentals/performance.txt | 32 +++++++++++++++++++---------- 1 file changed, 21 insertions(+), 11 deletions(-) diff --git a/source/fundamentals/performance.txt b/source/fundamentals/performance.txt index a38db105..a391c160 100644 --- a/source/fundamentals/performance.txt +++ b/source/fundamentals/performance.txt @@ -71,9 +71,18 @@ Connection Pool Every ``Client`` instance has a built-in connection pool for each server in your MongoDB topology. Connection pools open sockets on demand to -support concurrent requests to MongoDB in your application. You can -tune the connection pool to best fit the needs of your application -and optimize performance. +support concurrent requests to MongoDB in your application. + +The default configuration for a ``Client`` works for most applications. +The following code shows how to create a client with default connection +settings: + +.. code-block:: rust + + let client = Client::with_uri_str("").await?; + +Alternatively, you can tune the connection pool to best fit the needs of your +application and optimize performance. .. tip:: @@ -81,6 +90,9 @@ and optimize performance. :manual:`Tuning Your Connection Pool Settings ` in the Server manual. +Configure Maximum Pool Size +~~~~~~~~~~~~~~~~~~~~~~~~~~~ + The maximum size of each connection pool is set by the ``max_pool_size`` option, which defaults to ``10``. If the number of in-use connections to a server reaches the value of ``max_pool_size``, the next request to @@ -108,6 +120,9 @@ option. The following code demonstrates how to specify a value for let client = Client::with_options(client_options)?; +Configure Concurrent Connection Options +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + Connection pools are rate-limited. The ``max_connecting`` option determines the number of connections that the pool can create in parallel at any time. For example, if the value of ``max_connecting`` is @@ -127,6 +142,9 @@ sockets are closed and the total number of sockets, both in use and idle, drops below the minimum, the connection pool opens more sockets until the minimum is reached. +Configure Maximum Idle Time +~~~~~~~~~~~~~~~~~~~~~~~~~~~ + You can set the maximum amount of time that a connection can remain idle in the pool by setting the ``max_idle_time`` option. Once a connection has been idle for the duration specified in @@ -140,14 +158,6 @@ closes only inactive sockets, so you cannot interrupt or terminate any ongoing operations by using this method. The driver closes these sockets only when the process completes. -The default configuration for a ``Client`` works for most applications. -The following code shows how to create a client with default connection -settings: - -.. code-block:: rust - - let client = Client::with_uri_str("").await?; - .. _rust-performance-parallelism: Parallelism From 190dcbc86e16db01ca9b256e32369f790eaed9ae Mon Sep 17 00:00:00 2001 From: norareidy Date: Mon, 8 Jan 2024 11:40:20 -0500 Subject: [PATCH 2/5] add code + edits --- source/fundamentals/performance.txt | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/source/fundamentals/performance.txt b/source/fundamentals/performance.txt index a391c160..4c4a086c 100644 --- a/source/fundamentals/performance.txt +++ b/source/fundamentals/performance.txt @@ -142,6 +142,17 @@ sockets are closed and the total number of sockets, both in use and idle, drops below the minimum, the connection pool opens more sockets until the minimum is reached. +The following code sets the ``max_connecting`` and ``min_pool_size`` options when +instantiating a ``Client``: + +.. code-block:: rust + + let mut client_options = ClientOptions::parse("").await?; + client_options.max_connecting = Some(3); + client_options.min_pool_size = Some(1); + + let client = Client::with_options(client_options)?; + Configure Maximum Idle Time ~~~~~~~~~~~~~~~~~~~~~~~~~~~ @@ -158,6 +169,16 @@ closes only inactive sockets, so you cannot interrupt or terminate any ongoing operations by using this method. The driver closes these sockets only when the process completes. +The following code sets the value of the ``max_idle_time`` option to +``90`` seconds when instantiating a ``Client``: + +.. code-block:: rust + + let mut client_options = ClientOptions::parse("").await?; + client_options.max_idle_time = Some(Duration::new(90, 0)); + + let client = Client::with_options(client_options)?; + .. _rust-performance-parallelism: Parallelism From c327851299c1bea84f078155d5b9d3bd23975917 Mon Sep 17 00:00:00 2001 From: norareidy Date: Mon, 8 Jan 2024 11:48:41 -0500 Subject: [PATCH 3/5] derive statement fix --- source/fundamentals/serialization.txt | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/source/fundamentals/serialization.txt b/source/fundamentals/serialization.txt index 2129057c..b0719f0c 100644 --- a/source/fundamentals/serialization.txt +++ b/source/fundamentals/serialization.txt @@ -66,8 +66,8 @@ Custom Data Model You can use any Rust data type that implements the ``Serialize`` and ``Deserialize`` traits from the ``serde`` crate as the generic type parameter for a ``Collection`` instance. To implement the ``Serialize`` -and ``Deserialize`` traits, you must use the following ``derive`` -statement before defining a Rust type: +and ``Deserialize`` traits, you must include the following ``derive`` +attribute before defining a Rust type: .. code-block:: rust From effaad41e0c178f8936815bbfc3c47062ada39a0 Mon Sep 17 00:00:00 2001 From: norareidy Date: Mon, 8 Jan 2024 13:23:14 -0500 Subject: [PATCH 4/5] MW feedback --- source/fundamentals/performance.txt | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/source/fundamentals/performance.txt b/source/fundamentals/performance.txt index 4c4a086c..00d43aed 100644 --- a/source/fundamentals/performance.txt +++ b/source/fundamentals/performance.txt @@ -82,7 +82,12 @@ settings: let client = Client::with_uri_str("").await?; Alternatively, you can tune the connection pool to best fit the needs of your -application and optimize performance. +application and optimize performance. For more information on how to customize +your connection settings, see the following subsections of this guide: + +- :ref:`rust-max-pool` +- :ref:`rust-concurrent-connections` +- :ref:`rust-max-idle` .. tip:: @@ -90,6 +95,8 @@ application and optimize performance. :manual:`Tuning Your Connection Pool Settings ` in the Server manual. +.. _rust-max-pool: + Configure Maximum Pool Size ~~~~~~~~~~~~~~~~~~~~~~~~~~~ @@ -120,6 +127,8 @@ option. The following code demonstrates how to specify a value for let client = Client::with_options(client_options)?; +.. _rust-concurrent-connections: + Configure Concurrent Connection Options ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ @@ -153,6 +162,8 @@ instantiating a ``Client``: let client = Client::with_options(client_options)?; +.. _rust-max-idle: + Configure Maximum Idle Time ~~~~~~~~~~~~~~~~~~~~~~~~~~~ From 694d4758e51784852ca8819005f678da0e0d1669 Mon Sep 17 00:00:00 2001 From: norareidy Date: Mon, 8 Jan 2024 13:42:54 -0500 Subject: [PATCH 5/5] fixing parse method --- source/fundamentals/performance.txt | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/source/fundamentals/performance.txt b/source/fundamentals/performance.txt index 00d43aed..7b528edd 100644 --- a/source/fundamentals/performance.txt +++ b/source/fundamentals/performance.txt @@ -122,7 +122,7 @@ option. The following code demonstrates how to specify a value for .. code-block:: rust - let mut client_options = ClientOptions::parse("").await?; + let mut client_options = ClientOptions::parse_async("").await?; client_options.max_pool_size = Some(20); let client = Client::with_options(client_options)?; @@ -156,7 +156,7 @@ instantiating a ``Client``: .. code-block:: rust - let mut client_options = ClientOptions::parse("").await?; + let mut client_options = ClientOptions::parse_async("").await?; client_options.max_connecting = Some(3); client_options.min_pool_size = Some(1); @@ -185,7 +185,7 @@ The following code sets the value of the ``max_idle_time`` option to .. code-block:: rust - let mut client_options = ClientOptions::parse("").await?; + let mut client_options = ClientOptions::parse_async("").await?; client_options.max_idle_time = Some(Duration::new(90, 0)); let client = Client::with_options(client_options)?;