Skip to content

Commit b93aa0d

Browse files
committed
DOCSP-46691: Connection Pools
1 parent 12cb738 commit b93aa0d

File tree

2 files changed

+99
-0
lines changed

2 files changed

+99
-0
lines changed

source/connect.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ Connect to MongoDB
3030
Customize Server Selection </connect/server-selection>
3131
Stable API </connect/stable-api>
3232
Limit Server Execution Time </connect/csot>
33+
Connection Pools </connect/connection-pools>
3334

3435
Overview
3536
--------

source/connect/connection-pools.txt

Lines changed: 98 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,98 @@
1+
.. _pymongo-connection-pools:
2+
3+
================
4+
Connection Pools
5+
================
6+
7+
.. facet::
8+
:name: genre
9+
:values: reference
10+
11+
.. contents:: On this page
12+
:local:
13+
:backlinks: none
14+
:depth: 2
15+
:class: singlecol
16+
17+
Overview
18+
--------
19+
20+
In this guide, you can learn about how {+driver-short+} uses connection pools to manage
21+
connections to a MongoDB deployment and how you can configure connection pool settings
22+
in your application.
23+
24+
A connection pool is a cache of open database connections maintained by {+driver-short+}.
25+
When your application requests a connection to MongoDB, {+driver-short+} seamlessly
26+
gets a connection from the pool, performs operations, and returns the connection
27+
to the pool for reuse.
28+
29+
Connection pools help reduce application latency and the number of times new connections
30+
are created by {+driver-short+}.
31+
32+
Configuring Connection Pools
33+
----------------------------
34+
35+
You can specify the following connection pool settings in your ``MongoClient`` object or in
36+
your connection URI:
37+
38+
.. list-table::
39+
:widths: 30 70
40+
:header-rows: 1
41+
42+
* - Setting
43+
- Description
44+
45+
* - ``connectTimeoutMS``
46+
- | Sets the time that {+driver-short+} waits when connecting a new
47+
socket before timing out.
48+
| Defaults to ``20000``
49+
50+
* - ``maxConnecting``
51+
- | Sets the maximum number of connections that each pool can have at once.
52+
| Defaults to ``2``
53+
54+
* - ``maxIdleTimeMS``
55+
- | Sets the maximum time that a connection can remain idle in the pool.
56+
| Defaults to ``None`` (no limit)
57+
58+
* - ``maxPoolSize``
59+
- | Sets the maximum number of concurrent connections that the pool will maintain.
60+
If the maximum pool size is reached, further requests will wait until a connection
61+
becomes available.
62+
| Defaults to ``100``
63+
64+
* - ``minPoolSize``
65+
- | Sets the minimum number of concurrent connections that the pool will maintain. If
66+
the number of open connections falls below this value due to network errors,
67+
{+driver-short+} will attempt to create new connections to maintain this minimum.
68+
| Defaults to ``0``
69+
70+
* - ``socketTimeoutMS``
71+
- | Sets the length of time that {+driver-short+} waits for a response from the server
72+
before timing out.
73+
| Defaults to ``None`` (no timeout)
74+
75+
* - ``waitQueueTimeoutMS``
76+
- | Sets how long a thread will wait for a connection to become available in the pool
77+
before timing out.
78+
| Defaults to ``None`` (no timeout)
79+
80+
The following code creates a client with a connection pool size of 50:
81+
82+
.. code-block:: python
83+
84+
client = MongoClient(host, port, maxPoolSize=50)
85+
86+
Additional Information
87+
----------------------
88+
89+
To learn more about connection pools, see :manual:`Connection Pool Overview </manual/administration/connection-pool-overview/>`
90+
in the {+mdb-server+} manual.
91+
92+
API Documentation
93+
~~~~~~~~~~~~~~~~~
94+
95+
To learn more about any of the methods or types discussed in this
96+
guide, see the following API documentation:
97+
98+
- `MongoClient <{+api-root+}pymongo/mongo_client.html#pymongo.mongo_client.MongoClient>`__

0 commit comments

Comments
 (0)