Skip to content

Commit 9aa0195

Browse files
committed
PYTHON-785 Update connection-pooling FAQ.
1 parent 7adf3e6 commit 9aa0195

File tree

1 file changed

+17
-23
lines changed

1 file changed

+17
-23
lines changed

doc/faq.rst

Lines changed: 17 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ Frequently Asked Questions
66
Is PyMongo thread-safe?
77
-----------------------
88

9-
PyMongo is thread-safe and even provides built-in connection pooling
9+
PyMongo is thread-safe and provides built-in connection pooling
1010
for threaded applications.
1111

1212
.. _connection-pooling:
@@ -15,21 +15,18 @@ How does connection pooling work in PyMongo?
1515
--------------------------------------------
1616

1717
Every :class:`~pymongo.mongo_client.MongoClient` instance has a built-in
18-
connection pool. The pool begins with one open connection. If necessary to
19-
support concurrent access to MongoDB from multiple threads in your application,
20-
the client opens new connections on demand.
18+
connection pool. The client opens sockets on demand to support the number
19+
of concurrent MongoDB operations your application requires. There is no
20+
thread-affinity for sockets.
2121

22-
By default, there is no thread-affinity for connections.
22+
The client instance opens one additional socket per server in your MongoDB
23+
topology for monitoring the server's state.
2324

24-
In versions before 2.6, the default ``max_pool_size`` was 10, and it did not
25-
actually bound the number of open connections; it only determined the number
26-
of connections that would be kept open when no longer in use.
27-
28-
Starting with PyMongo 2.6, the size of the connection pool is capped at
29-
``max_pool_size``, which now defaults to 100. When a thread in your application
30-
begins an operation on MongoDB, if all other connections are in use and the
31-
pool has reached its maximum, the thread pauses, waiting for a connection to
32-
be returned to the pool by another thread.
25+
The size of each connection pool is capped at ``max_pool_size``, which defaults
26+
to 100. When a thread in your application begins an operation on MongoDB, if
27+
all other sockets are in use and the pool has reached its maximum, the
28+
thread pauses, waiting for a socket to be returned to the pool by another
29+
thread.
3330

3431
The default configuration for a :class:`~pymongo.mongo_client.MongoClient`
3532
works for most applications::
@@ -49,34 +46,31 @@ process, increase ``max_pool_size``::
4946

5047
client = MongoClient(host, port, max_pool_size=None)
5148

52-
By default, any number of threads are allowed to wait for connections to become
49+
By default, any number of threads are allowed to wait for sockets to become
5350
available, and they can wait any length of time. Override ``waitQueueMultiple``
5451
to cap the number of waiting threads. E.g., to keep the number of waiters less
5552
than or equal to 500::
5653

5754
client = MongoClient(host, port, max_pool_size=50, waitQueueMultiple=10)
5855

59-
When 500 threads are waiting for a socket, the 501st that needs a connection
56+
When 500 threads are waiting for a socket, the 501st that needs a socket
6057
raises :exc:`~pymongo.errors.ExceededMaxWaiters`. Use this option to
6158
bound the amount of queueing in your application during a load spike, at the
6259
cost of additional exceptions.
6360

6461
Once the pool reaches its max size, additional threads are allowed to wait
65-
indefinitely for connections to become available, unless you set
62+
indefinitely for sockets to become available, unless you set
6663
``waitQueueTimeoutMS``::
6764

6865
client = MongoClient(host, port, waitQueueTimeoutMS=100)
6966

70-
A thread that waits more than 100ms (in this example) for a connection raises
67+
A thread that waits more than 100ms (in this example) for a sockets raises
7168
:exc:`~pymongo.errors.ConnectionFailure`. Use this option if it is more
7269
important to bound the duration of operations during a load spike than it is to
7370
complete every operation.
7471

75-
When :meth:`~pymongo.mongo_client.MongoClient.disconnect` is called by any thread,
76-
all sockets are closed.
77-
78-
:class:`~pymongo.mongo_replica_set_client.MongoReplicaSetClient` maintains one
79-
connection pool per server in your replica set.
72+
When :meth:`~pymongo.mongo_client.MongoClient.disconnect` is called by any
73+
thread, all sockets are closed.
8074

8175
Does PyMongo support Python 3?
8276
------------------------------

0 commit comments

Comments
 (0)