Skip to content

Commit

Permalink
PYTHON-5059 Update default maxMessageSizeBytes and maxWriteBatchSize (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
ShaneHarvey authored Jan 24, 2025
1 parent dc18231 commit a3208df
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 8 deletions.
4 changes: 2 additions & 2 deletions pymongo/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,10 +60,10 @@

# Defaults until we connect to a server and get updated limits.
MAX_BSON_SIZE = 16 * (1024**2)
MAX_MESSAGE_SIZE: int = 2 * MAX_BSON_SIZE
MAX_MESSAGE_SIZE = 48 * 1000 * 1000
MIN_WIRE_VERSION = 0
MAX_WIRE_VERSION = 0
MAX_WRITE_BATCH_SIZE = 1000
MAX_WRITE_BATCH_SIZE = 100000

# What this version of PyMongo supports.
MIN_SUPPORTED_SERVER_VERSION = "4.0"
Expand Down
2 changes: 1 addition & 1 deletion pymongo/hello.py
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ def max_bson_size(self) -> int:

@property
def max_message_size(self) -> int:
return self._doc.get("maxMessageSizeBytes", 2 * self.max_bson_size)
return self._doc.get("maxMessageSizeBytes", common.MAX_MESSAGE_SIZE)

@property
def max_write_batch_size(self) -> int:
Expand Down
13 changes: 8 additions & 5 deletions test/test_server_description.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@

from bson.int64 import Int64
from bson.objectid import ObjectId
from pymongo import common
from pymongo.hello import Hello, HelloCompat
from pymongo.server_description import ServerDescription
from pymongo.server_type import SERVER_TYPE
Expand Down Expand Up @@ -132,11 +133,13 @@ def test_fields(self):
self.assertEqual(4, s.min_wire_version)
self.assertEqual(25, s.max_wire_version)

def test_default_max_message_size(self):
s = parse_hello_response({"ok": 1, HelloCompat.LEGACY_CMD: True, "maxBsonObjectSize": 2})

# Twice max_bson_size.
self.assertEqual(4, s.max_message_size)
def test_defaults(self):
s = parse_hello_response({"ok": 1, HelloCompat.LEGACY_CMD: True})
self.assertEqual(common.MAX_BSON_SIZE, s.max_bson_size)
self.assertEqual(common.MAX_MESSAGE_SIZE, s.max_message_size)
self.assertEqual(common.MIN_WIRE_VERSION, s.min_wire_version)
self.assertEqual(common.MAX_WIRE_VERSION, s.max_wire_version)
self.assertEqual(common.MAX_WRITE_BATCH_SIZE, s.max_write_batch_size)

def test_standalone(self):
s = parse_hello_response({"ok": 1, HelloCompat.LEGACY_CMD: True})
Expand Down

0 comments on commit a3208df

Please sign in to comment.