Skip to content

Commit cc06b46

Browse files
authored
Bump CRT version and expose setting memory limits for S3 calls (#4885)
* Bump aws-crt version to 0.29.9 * Exposes a setting to set the memory limit when making asynchronous calls with the CRT-based S3 client
1 parent 2336fed commit cc06b46

File tree

8 files changed

+66
-5
lines changed

8 files changed

+66
-5
lines changed
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{
2+
"type": "feature",
3+
"category": "AWS SDK for Java v2",
4+
"contributor": "",
5+
"description": "Bump `aws-crt` version to `0.29.9`"
6+
}
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{
2+
"type": "feature",
3+
"category": "AWS CRT-based S3 Client",
4+
"contributor": "",
5+
"description": "Exposes a setting to set the memory limit when making asynchronous calls with the CRT-based S3 client"
6+
}

pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@
119119
<rxjava.version>2.2.21</rxjava.version>
120120
<commons-codec.verion>1.15</commons-codec.verion>
121121
<jmh.version>1.29</jmh.version>
122-
<awscrt.version>0.29.7</awscrt.version>
122+
<awscrt.version>0.29.9</awscrt.version>
123123

124124
<!--Test dependencies -->
125125
<junit5.version>5.10.0</junit5.version>

services/s3/src/main/java/software/amazon/awssdk/services/s3/S3CrtAsyncClientBuilder.java

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,12 +117,32 @@ default S3CrtAsyncClientBuilder credentialsProvider(IdentityProvider<? extends A
117117
*/
118118
S3CrtAsyncClientBuilder minimumPartSizeInBytes(Long uploadPartSize);
119119

120+
/**
121+
* The amount of native memory that CRT is allowed to use when making requests to S3.
122+
* <p>
123+
* If not provided, the CRT attempts to limit native memory usage in an optimal way, based on a number of parameters
124+
* such as target throughput. Therefore, only configure the memory limit explicitly when needed.
125+
* <p>
126+
* Supported range:
127+
* <ul>
128+
* <li><b>Min: </b>1 GB</li>
129+
* <li><b>Max: </b>The lowest value of the supplied value and the SIZE_MAX of the system</li>
130+
* </ul>
131+
*
132+
* @param maxNativeMemoryLimitInBytes
133+
the native memory limit in bytes
134+
* @return this builder for method chaining.
135+
* @see #targetThroughputInGbps(Double)
136+
*/
137+
S3CrtAsyncClientBuilder maxNativeMemoryLimitInBytes(Long maxNativeMemoryLimitInBytes
138+
);
139+
120140
/**
121141
* The target throughput for transfer requests. Higher value means more connections will be established with S3.
122142
*
123143
* <p>
124144
* Whether the transfer manager can achieve the configured target throughput depends on various factors such as the network
125-
* bandwidth of the environment and whether {@link #maxConcurrency} is configured.
145+
* bandwidth of the environment, whether {@link #maxConcurrency} is configured and amount of available memory.
126146
*
127147
* <p>
128148
* By default, it is 10 gigabits per second. If users want to transfer as fast as possible, it's recommended to set it to the
@@ -131,10 +151,15 @@ default S3CrtAsyncClientBuilder credentialsProvider(IdentityProvider<? extends A
131151
* instance type in <a href="https://aws.amazon.com/ec2/instance-types/">Amazon EC2 instance type page</a>.
132152
* If you are running into out of file descriptors error, consider using {@link #maxConcurrency(Integer)} to limit the
133153
* number of connections.
154+
* <p>
155+
* <b>Note: </b> This setting affects the native memory usage used by CRT; a higher throughput value will result in a larger
156+
* memory usage. Typically, a range of throughput values maps to a discrete memory limit value in CRT, with a maximum upper
157+
* limit.
134158
*
135159
* @param targetThroughputInGbps the target throughput in Gbps
136160
* @return this builder for method chaining.
137161
* @see #maxConcurrency(Integer)
162+
* @see #maxNativeMemoryLimitInBytes(Long)
138163
*/
139164
S3CrtAsyncClientBuilder targetThroughputInGbps(Double targetThroughputInGbps);
140165

services/s3/src/main/java/software/amazon/awssdk/services/s3/internal/crt/DefaultS3CrtAsyncClient.java

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -168,7 +168,8 @@ private static S3CrtAsyncHttpClient.Builder initializeS3CrtAsyncHttpClient(Defau
168168
.credentialsProvider(builder.credentialsProvider)
169169
.readBufferSizeInBytes(builder.readBufferSizeInBytes)
170170
.httpConfiguration(builder.httpConfiguration)
171-
.thresholdInBytes(builder.thresholdInBytes);
171+
.thresholdInBytes(builder.thresholdInBytes)
172+
.maxNativeMemoryLimitInBytes(builder.maxNativeMemoryLimitInBytes);
172173

173174
if (builder.retryConfiguration != null) {
174175
nativeClientBuilder.standardRetryOptions(
@@ -186,6 +187,8 @@ public static final class DefaultS3CrtClientBuilder implements S3CrtAsyncClientB
186187
private Region region;
187188
private Long minimalPartSizeInBytes;
188189
private Double targetThroughputInGbps;
190+
private Long maxNativeMemoryLimitInBytes
191+
;
189192
private Integer maxConcurrency;
190193
private URI endpointOverride;
191194
private Boolean checksumValidationEnabled;
@@ -224,6 +227,12 @@ public S3CrtAsyncClientBuilder targetThroughputInGbps(Double targetThroughputInG
224227
return this;
225228
}
226229

230+
@Override
231+
public S3CrtAsyncClientBuilder maxNativeMemoryLimitInBytes(Long maxNativeMemoryLimitInBytes) {
232+
this.maxNativeMemoryLimitInBytes = maxNativeMemoryLimitInBytes;
233+
return this;
234+
}
235+
227236
@Override
228237
public S3CrtAsyncClientBuilder maxConcurrency(Integer maxConcurrency) {
229238
this.maxConcurrency = maxConcurrency;

services/s3/src/main/java/software/amazon/awssdk/services/s3/internal/crt/S3CrtAsyncHttpClient.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,7 @@ private S3ClientOptions createS3ClientOption() {
106106
.withComputeContentMd5(false)
107107
.withEnableS3Express(true)
108108
.withMaxConnections(s3NativeClientConfiguration.maxConcurrency())
109+
.withMemoryLimitInBytes(s3NativeClientConfiguration.maxNativeMemoryLimitInBytes())
109110
.withThroughputTargetGbps(s3NativeClientConfiguration.targetThroughputInGbps())
110111
.withInitialReadWindowSize(initialWindowSize)
111112
.withReadBackpressureEnabled(true);

services/s3/src/main/java/software/amazon/awssdk/services/s3/internal/crt/S3NativeClientConfiguration.java

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,13 +59,12 @@ public class S3NativeClientConfiguration implements SdkAutoCloseable {
5959
private final boolean checksumValidationEnabled;
6060
private final Long readBufferSizeInBytes;
6161
private final TlsContext tlsContext;
62-
6362
private final TlsContextOptions clientTlsContextOptions;
6463
private final HttpProxyOptions proxyOptions;
6564
private final Duration connectionTimeout;
6665
private final HttpMonitoringOptions httpMonitoringOptions;
67-
6866
private final Boolean useEnvironmentVariableProxyOptionsValues;
67+
private final long maxNativeMemoryLimitInBytes;
6968

7069
public S3NativeClientConfiguration(Builder builder) {
7170
this.signingRegion = builder.signingRegion == null ? DefaultAwsRegionProviderChain.builder().build().getRegion().id() :
@@ -98,6 +97,7 @@ public S3NativeClientConfiguration(Builder builder) {
9897

9998
// Using 0 so that CRT will calculate it based on targetThroughputGbps
10099
this.maxConcurrency = builder.maxConcurrency == null ? 0 : builder.maxConcurrency;
100+
this.maxNativeMemoryLimitInBytes = builder.maxNativeMemoryLimitInBytes == null ? 0 : builder.maxNativeMemoryLimitInBytes;
101101

102102
this.endpointOverride = builder.endpointOverride;
103103

@@ -177,6 +177,10 @@ public double targetThroughputInGbps() {
177177
return targetThroughputInGbps;
178178
}
179179

180+
public long maxNativeMemoryLimitInBytes() {
181+
return maxNativeMemoryLimitInBytes;
182+
}
183+
180184
public int maxConcurrency() {
181185
return maxConcurrency;
182186
}
@@ -218,6 +222,7 @@ public static final class Builder {
218222
private S3CrtHttpConfiguration httpConfiguration;
219223
private StandardRetryOptions standardRetryOptions;
220224
private Long thresholdInBytes;
225+
private Long maxNativeMemoryLimitInBytes;
221226

222227
private Builder() {
223228
}
@@ -247,6 +252,11 @@ public Builder maxConcurrency(Integer maxConcurrency) {
247252
return this;
248253
}
249254

255+
public Builder maxNativeMemoryLimitInBytes(Long maxNativeMemoryLimitInBytes) {
256+
this.maxNativeMemoryLimitInBytes = maxNativeMemoryLimitInBytes;
257+
return this;
258+
}
259+
250260
public Builder endpointOverride(URI endpointOverride) {
251261
this.endpointOverride = endpointOverride;
252262
return this;

services/s3/src/test/java/software/amazon/awssdk/services/s3/internal/crt/S3CrtAsyncHttpClientTest.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -379,6 +379,8 @@ void build_shouldPassThroughParameters() {
379379
.maxConcurrency(100)
380380
.signingRegion(signingRegion)
381381
.thresholdInBytes(1024L)
382+
.targetThroughputInGbps(3.5)
383+
.maxNativeMemoryLimitInBytes(5L * 1024 * 1024 * 1024)
382384
.standardRetryOptions(
383385
new StandardRetryOptions()
384386
.withBackoffRetryOptions(new ExponentialBackoffRetryOptions().withMaxRetries(7)))
@@ -409,6 +411,8 @@ void build_shouldPassThroughParameters() {
409411
assertThat(options.getMinThroughputBytesPerSecond()).isEqualTo(1024);
410412
});
411413
assertThat(clientOptions.getMaxConnections()).isEqualTo(100);
414+
assertThat(clientOptions.getThroughputTargetGbps()).isEqualTo(3.5);
415+
assertThat(clientOptions.getMemoryLimitInBytes()).isEqualTo(5L * 1024 * 1024 * 1024);
412416
}
413417
}
414418

0 commit comments

Comments
 (0)