Skip to content

Commit 4800512

Browse files
committed
PYTHON-1839 Deprecate waitQueueMultiple option
1 parent 62400e5 commit 4800512

File tree

5 files changed

+58
-34
lines changed

5 files changed

+58
-34
lines changed

doc/changelog.rst

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,9 @@ Version 3.9 adds support for MongoDB 4.2. Highlights include:
3232
- ``ssl_ca_certs`` has been deprecated in favor of ``tlsCAFile``.
3333
- ``ssl_certfile`` has been deprecated in favor of ``tlsCertificateKeyFile``.
3434
- ``ssl_pem_passphrase`` has been deprecated in favor of ``tlsCertificateKeyFilePassword``.
35+
- ``waitQueueMultiple`` has been deprecated without replacement. This option
36+
was a poor solution for putting an upper bound on queuing since it didn't
37+
affect queuing in other parts of the driver.
3538
- The ``retryWrites`` URI option now defaults to ``True``. Supported write
3639
operations that fail with a retryable error will automatically be retried one
3740
time, with at-most-once semantics.

doc/faq.rst

Lines changed: 6 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -98,21 +98,12 @@ process, increase ``maxPoolSize``::
9898

9999
client = MongoClient(host, port, maxPoolSize=None)
100100

101-
By default, any number of threads are allowed to wait for sockets to become
102-
available, and they can wait any length of time. Override ``waitQueueMultiple``
103-
to cap the number of waiting threads. E.g., to keep the number of waiters less
104-
than or equal to 500::
105-
106-
client = MongoClient(host, port, maxPoolSize=50, waitQueueMultiple=10)
107-
108-
When 500 threads are waiting for a socket, the 501st that needs a socket
109-
raises :exc:`~pymongo.errors.ExceededMaxWaiters`. Use this option to
110-
bound the amount of queueing in your application during a load spike, at the
111-
cost of additional exceptions.
112-
113-
Once the pool reaches its max size, additional threads are allowed to wait
114-
indefinitely for sockets to become available, unless you set
115-
``waitQueueTimeoutMS``::
101+
Once the pool reaches its maximum size, additional threads have to wait for
102+
sockets to become available. PyMongo does not limit the number of threads
103+
that can wait for sockets to become available and it is the application's
104+
responsibility to limit the size of its thread pool to bound queuing during a
105+
load spike. Threads are allowed to wait for any length of time unless
106+
``waitQueueTimeoutMS`` is defined::
116107

117108
client = MongoClient(host, port, waitQueueTimeoutMS=100)
118109

pymongo/common.py

Lines changed: 19 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -658,16 +658,26 @@ def validate_tzinfo(dummy, value):
658658
'tlscertificatekeyfilepassword': 'ssl_pem_passphrase',
659659
}
660660

661-
# Map from deprecated URI option names to the updated option names.
662-
# Case is preserved for updated option names as they are part of user warnings.
661+
# Map from deprecated URI option names to a tuple indicating the method of
662+
# their deprecation and any additional information that may be needed to
663+
# construct the warning message.
663664
URI_OPTIONS_DEPRECATION_MAP = {
664-
'j': 'journal',
665-
'wtimeout': 'wTimeoutMS',
666-
'ssl_cert_reqs': 'tlsAllowInvalidCertificates',
667-
'ssl_match_hostname': 'tlsAllowInvalidHostnames',
668-
'ssl_crlfile': 'tlsCRLFile',
669-
'ssl_ca_certs': 'tlsCAFile',
670-
'ssl_pem_passphrase': 'tlsCertificateKeyFilePassword',
665+
# format: <deprecated option name>: (<mode>, <message>),
666+
# Supported <mode> values:
667+
# - 'renamed': <message> should be the new option name. Note that case is
668+
# preserved for renamed options as they are part of user warnings.
669+
# - 'removed': <message> may suggest the rationale for deprecating the
670+
# option and/or recommend remedial action.
671+
'j': ('renamed', 'journal'),
672+
'wtimeout': ('renamed', 'wTimeoutMS'),
673+
'ssl_cert_reqs': ('renamed', 'tlsAllowInvalidCertificates'),
674+
'ssl_match_hostname': ('renamed', 'tlsAllowInvalidHostnames'),
675+
'ssl_crlfile': ('renamed', 'tlsCRLFile'),
676+
'ssl_ca_certs': ('renamed', 'tlsCAFile'),
677+
'ssl_pem_passphrase': ('renamed', 'tlsCertificateKeyFilePassword'),
678+
'waitqueuemultiple': ('removed', (
679+
'Instead of using waitQueueMultiple to bound queuing, limit the size '
680+
'of the thread pool in your application server'))
671681
}
672682

673683
# Augment the option validator map with pymongo-specific option information.

pymongo/uri_parser.py

Lines changed: 21 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -195,16 +195,27 @@ def _handle_option_deprecations(options):
195195
"""
196196
for optname in list(options):
197197
if optname in URI_OPTIONS_DEPRECATION_MAP:
198-
newoptname = URI_OPTIONS_DEPRECATION_MAP[optname]
199-
if newoptname in options:
200-
warn_msg = "Deprecated option '%s' ignored in favor of '%s'."
201-
warnings.warn(warn_msg % (options.cased_key(optname),
202-
options.cased_key(newoptname)))
203-
options.pop(optname)
204-
continue
205-
warn_msg = "Option '%s' is deprecated, use '%s' instead."
206-
warnings.warn(warn_msg % (options.cased_key(optname),
207-
newoptname))
198+
mode, message = URI_OPTIONS_DEPRECATION_MAP[optname]
199+
if mode == 'renamed':
200+
newoptname = message
201+
if newoptname in options:
202+
warn_msg = ("Deprecated option '%s' ignored in favor of "
203+
"'%s'.")
204+
warnings.warn(
205+
warn_msg % (options.cased_key(optname),
206+
options.cased_key(newoptname)),
207+
DeprecationWarning, stacklevel=2)
208+
options.pop(optname)
209+
continue
210+
warn_msg = "Option '%s' is deprecated, use '%s' instead."
211+
warnings.warn(
212+
warn_msg % (options.cased_key(optname), newoptname),
213+
DeprecationWarning, stacklevel=2)
214+
elif mode == 'removed':
215+
warn_msg = "Option '%s' is deprecated. %s."
216+
warnings.warn(
217+
warn_msg % (options.cased_key(optname), message),
218+
DeprecationWarning, stacklevel=2)
208219

209220
return options
210221

test/test_uri_parser.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -485,6 +485,15 @@ def test_normalize_options(self):
485485
"fsync": True, "wtimeoutms": 10}
486486
self.assertEqual(res, parse_uri(uri)["options"])
487487

488+
def test_waitQueueMultiple_deprecated(self):
489+
uri = "mongodb://example.com/?waitQueueMultiple=5"
490+
with warnings.catch_warnings(record=True) as ctx:
491+
warnings.simplefilter('always')
492+
parse_uri(uri)
493+
494+
self.assertEqual(len(ctx), 1)
495+
self.assertTrue(issubclass(ctx[0].category, DeprecationWarning))
496+
488497

489498
if __name__ == "__main__":
490499
unittest.main()

0 commit comments

Comments
 (0)