Skip to content

Commit fd080c7

Browse files
authored
Set PoolManager blocksize if urllib3 is v2 (boto#3612)
1 parent 26f423c commit fd080c7

3 files changed

Lines changed: 20 additions & 0 deletions

File tree

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"type": "enhancement",
3+
"category": "HTTP session",
4+
"description": "Set blocksize from default 16KB to 128KB if urllib3 v2 is installed"
5+
}

botocore/httpsession.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
)
2020
from urllib3.exceptions import ReadTimeoutError as URLLib3ReadTimeoutError
2121
from urllib3.exceptions import SSLError as URLLib3SSLError
22+
from urllib3.poolmanager import PoolKey
2223
from urllib3.util.retry import Retry
2324
from urllib3.util.ssl_ import (
2425
OP_NO_COMPRESSION,
@@ -81,6 +82,15 @@
8182
DEFAULT_TIMEOUT = 60
8283
MAX_POOL_CONNECTIONS = 10
8384
DEFAULT_CA_BUNDLE = os.path.join(os.path.dirname(__file__), 'cacert.pem')
85+
BUFFER_SIZE = None
86+
if hasattr(PoolKey, 'key_blocksize'):
87+
# urllib3 2.0 implemented its own chunking logic and set
88+
# a default blocksize of 16KB. This creates a noticeable
89+
# performance bottleneck when transferring objects
90+
# larger than 100MB. Based on experiments, a blocksize
91+
# of 128KB significantly improves throughput before
92+
# getting diminishing returns.
93+
BUFFER_SIZE = 1024 * 128
8494

8595
try:
8696
from certifi import where
@@ -343,6 +353,8 @@ def _get_pool_manager_kwargs(self, **extra_kwargs):
343353
'cert_file': self._cert_file,
344354
'key_file': self._key_file,
345355
}
356+
if BUFFER_SIZE:
357+
pool_manager_kwargs['blocksize'] = BUFFER_SIZE
346358
pool_manager_kwargs.update(**extra_kwargs)
347359
return pool_manager_kwargs
348360

tests/unit/test_http_session.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
ProxyConnectionError,
1616
)
1717
from botocore.httpsession import (
18+
BUFFER_SIZE,
1819
ProxyConfiguration,
1920
URLLib3Session,
2021
get_cert_path,
@@ -156,6 +157,8 @@ def _assert_manager_call(self, manager, *assert_args, **assert_kwargs):
156157
'cert_file': None,
157158
'key_file': None,
158159
}
160+
if BUFFER_SIZE:
161+
call_kwargs['blocksize'] = BUFFER_SIZE
159162
call_kwargs.update(assert_kwargs)
160163
manager.assert_called_with(*assert_args, **call_kwargs)
161164

0 commit comments

Comments
 (0)