Skip to content

Commit 5c299e8

Browse files
authored
Increase multipart upload default part size to 8MB (#4032)
1 parent 3975b0b commit 5c299e8

File tree

4 files changed

+38
-12
lines changed

4 files changed

+38
-12
lines changed
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
{
2+
"services": [
3+
{
4+
"serviceName": "S3",
5+
"type": "minor",
6+
"changeLogMessages": [
7+
"Increasing the default part size for S3 multipart upload from 5MB to 8MB when no part size is specified. This will reduce the number of API calls for multipart uploads."
8+
]
9+
}
10+
]
11+
}

sdk/src/Services/S3/Custom/Transfer/Internal/MultipartUploadCommand.cs

Lines changed: 7 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -81,11 +81,12 @@ internal MultipartUploadCommand(IAmazonS3 s3Client, TransferUtilityConfig config
8181
this._s3Client = s3Client;
8282
this._fileTransporterRequest = fileTransporterRequest;
8383
this._contentLength = this._fileTransporterRequest.ContentLength;
84+
85+
long targetPartSize = fileTransporterRequest.IsSetPartSize()
86+
? fileTransporterRequest.PartSize
87+
: S3Constants.DefaultPartSize;
8488

85-
if (fileTransporterRequest.IsSetPartSize())
86-
this._partSize = fileTransporterRequest.PartSize;
87-
else
88-
this._partSize = calculatePartSize(this._contentLength);
89+
this._partSize = calculatePartSize(this._contentLength, targetPartSize);
8990

9091
if (fileTransporterRequest.InputStream != null)
9192
{
@@ -98,15 +99,9 @@ internal MultipartUploadCommand(IAmazonS3 s3Client, TransferUtilityConfig config
9899
Logger.DebugFormat("Upload part size {0}.", this._partSize);
99100
}
100101

101-
private static long calculatePartSize(long fileSize)
102+
private static long calculatePartSize(long contentLength, long targetPartSize)
102103
{
103-
double partSize = Math.Ceiling((double)fileSize / S3Constants.MaxNumberOfParts);
104-
if (partSize < S3Constants.MinPartSize)
105-
{
106-
partSize = S3Constants.MinPartSize;
107-
}
108-
109-
return (long)partSize;
104+
return Math.Max(targetPartSize, contentLength / S3Constants.MaxNumberOfParts);
110105
}
111106

112107
private string determineContentType()

sdk/src/Services/S3/Custom/Util/S3Constants.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ internal static class S3Constants
3333
internal const int PutObjectDefaultTimeout = 20 * 60 * 1000;
3434

3535
internal static readonly long MinPartSize = 5 * (long)Math.Pow(2, 20);
36+
internal static readonly long DefaultPartSize = 8 * (long)Math.Pow(2, 20);
3637
internal const int MaxNumberOfParts = 10000;
3738

3839
internal const int DefaultBufferSize = 8192;

sdk/test/Services/S3/IntegrationTests/TransferUtilityTests.cs

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -663,6 +663,25 @@ public void MultipartGetNumberTest()
663663
}
664664
}
665665

666+
[TestMethod]
667+
[TestCategory("S3")]
668+
public void MultipartValidatePartSize8MbTest()
669+
{
670+
string key = "MultipartValidatePartSizeTest";
671+
672+
Upload(key, 20 * MEG_SIZE, null, Client);
673+
674+
var objectMetadataResponse = Client.GetObjectMetadata(new GetObjectMetadataRequest
675+
{
676+
BucketName = bucketName,
677+
Key = key,
678+
PartNumber = 1,
679+
});
680+
681+
Assert.AreEqual(3, objectMetadataResponse.PartsCount);
682+
Assert.AreEqual(8 * MEG_SIZE, objectMetadataResponse.ContentLength);
683+
}
684+
666685
void Upload(string fileName, long size,
667686
TransferProgressValidator<UploadProgressArgs> progressValidator, AmazonS3Client client = null)
668687
{

0 commit comments

Comments
 (0)