Skip to content

Commit c5487b5

Browse files
authored
Add max_bandwidth to TransferConfig (#3059)
1 parent ce77775 commit c5487b5

File tree

3 files changed

+42
-8
lines changed

3 files changed

+42
-8
lines changed
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"type": "enchancement",
3+
"category": "``s3``",
4+
"description": "TransferConfig now supports the `max_bandwidth` argument."
5+
}

boto3/s3/transfer.py

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -166,14 +166,17 @@ class TransferConfig(S3TransferConfig):
166166
'max_io_queue': 'max_io_queue_size'
167167
}
168168

169-
def __init__(self,
170-
multipart_threshold=8 * MB,
171-
max_concurrency=10,
172-
multipart_chunksize=8 * MB,
173-
num_download_attempts=5,
174-
max_io_queue=100,
175-
io_chunksize=256 * KB,
176-
use_threads=True):
169+
def __init__(
170+
self,
171+
multipart_threshold=8 * MB,
172+
max_concurrency=10,
173+
multipart_chunksize=8 * MB,
174+
num_download_attempts=5,
175+
max_io_queue=100,
176+
io_chunksize=256 * KB,
177+
use_threads=True,
178+
max_bandwidth=None,
179+
):
177180
"""Configuration object for managed S3 transfers
178181
179182
:param multipart_threshold: The transfer size threshold for which
@@ -209,6 +212,10 @@ def __init__(self,
209212
:param use_threads: If True, threads will be used when performing
210213
S3 transfers. If False, no threads will be used in
211214
performing transfers: all logic will be ran in the main thread.
215+
216+
:param max_bandwidth: The maximum bandwidth that will be consumed
217+
in uploading and downloading file content. The value is an integer
218+
in terms of bytes per second.
212219
"""
213220
super(TransferConfig, self).__init__(
214221
multipart_threshold=multipart_threshold,
@@ -217,6 +224,7 @@ def __init__(self,
217224
num_download_attempts=num_download_attempts,
218225
max_io_queue_size=max_io_queue,
219226
io_chunksize=io_chunksize,
227+
max_bandwidth=max_bandwidth,
220228
)
221229
# Some of the argument names are not the same as the inherited
222230
# S3TransferConfig so we add aliases so you can still access the

tests/unit/s3/test_transfer.py

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
from boto3.s3.transfer import S3Transfer
2424
from boto3.s3.transfer import OSUtils, TransferConfig, ProgressCallbackInvoker
2525
from boto3.s3.transfer import ClientError, S3TransferRetriesExceededError
26+
from boto3.s3.transfer import KB, MB
2627

2728

2829
class TestCreateTransferManager(unittest.TestCase):
@@ -83,6 +84,26 @@ def test_alias_max_io_queue(self):
8384
self.assert_value_of_actual_and_alias(
8485
config, 'max_io_queue_size', 'max_io_queue', new_value)
8586

87+
def test_transferconfig_parameters(self):
88+
config = TransferConfig(
89+
multipart_threshold=8 * MB,
90+
max_concurrency=10,
91+
multipart_chunksize=8 * MB,
92+
num_download_attempts=5,
93+
max_io_queue=100,
94+
io_chunksize=256 * KB,
95+
use_threads=True,
96+
max_bandwidth=1024 * KB,
97+
)
98+
assert config.multipart_threshold == 8 * MB
99+
assert config.multipart_chunksize == 8 * MB
100+
assert config.max_request_concurrency == 10
101+
assert config.num_download_attempts == 5
102+
assert config.max_io_queue_size == 100
103+
assert config.io_chunksize == 256 * KB
104+
assert config.use_threads is True
105+
assert config.max_bandwidth == 1024 * KB
106+
86107

87108
class TestProgressCallbackInvoker(unittest.TestCase):
88109
def test_on_progress(self):

0 commit comments

Comments
 (0)