Skip to content

Commit d66db22

Browse files
authored
CRT HTTP/1 GA - Surface Area Updates - readBufferSizeInBytes takes long (#3714)
* readBufferSizeInBytes takes long * Fixed review comments
1 parent 658b97a commit d66db22

File tree

3 files changed

+14
-15
lines changed

3 files changed

+14
-15
lines changed

http-clients/aws-crt-client/src/main/java/software/amazon/awssdk/http/crt/AwsCrtAsyncHttpClient.java

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ public final class AwsCrtAsyncHttpClient implements SdkAsyncHttpClient {
7676
private static final Logger log = Logger.loggerFor(AwsCrtAsyncHttpClient.class);
7777

7878
private static final String AWS_COMMON_RUNTIME = "AwsCommonRuntime";
79-
private static final int DEFAULT_STREAM_WINDOW_SIZE = 16 * 1024 * 1024; // 16 MB
79+
private static final long DEFAULT_STREAM_WINDOW_SIZE = 16L * 1024L * 1024L; // 16 MB
8080

8181
private final Map<URI, HttpClientConnectionManager> connectionPools = new ConcurrentHashMap<>();
8282
private final LinkedList<CrtResource> ownedSubResources = new LinkedList<>();
@@ -86,7 +86,7 @@ public final class AwsCrtAsyncHttpClient implements SdkAsyncHttpClient {
8686
private final HttpProxyOptions proxyOptions;
8787
private final HttpMonitoringOptions monitoringOptions;
8888
private final long maxConnectionIdleInMilliseconds;
89-
private final int readBufferSize;
89+
private final long readBufferSize;
9090
private final int maxConnectionsPerEndpoint;
9191
private boolean isClosed = false;
9292

@@ -107,7 +107,7 @@ private AwsCrtAsyncHttpClient(DefaultBuilder builder, AttributeMap config) {
107107
this.bootstrap = registerOwnedResource(clientBootstrap);
108108
this.socketOptions = registerOwnedResource(clientSocketOptions);
109109
this.tlsContext = registerOwnedResource(clientTlsContext);
110-
this.readBufferSize = builder.readBufferSize == null ? DEFAULT_STREAM_WINDOW_SIZE : builder.readBufferSize;
110+
this.readBufferSize = builder.readBufferSize == null ? DEFAULT_STREAM_WINDOW_SIZE : builder.readBufferSize;
111111
this.maxConnectionsPerEndpoint = config.get(SdkHttpConfigurationOption.MAX_CONNECTIONS);
112112
this.monitoringOptions = revolveHttpMonitoringOptions(builder.connectionHealthConfiguration);
113113
this.maxConnectionIdleInMilliseconds = config.get(SdkHttpConfigurationOption.CONNECTION_MAX_IDLE_TIMEOUT).toMillis();
@@ -213,7 +213,7 @@ private HttpClientConnectionManager createConnectionPool(URI uri) {
213213
.withSocketOptions(socketOptions)
214214
.withTlsContext(tlsContext)
215215
.withUri(uri)
216-
.withWindowSize(readBufferSize)
216+
.withWindowSize(NumericUtils.saturatedCast(readBufferSize))
217217
.withMaxConnections(maxConnectionsPerEndpoint)
218218
.withManualWindowManagement(true)
219219
.withProxyOptions(proxyOptions)
@@ -326,12 +326,11 @@ public interface Builder extends SdkAsyncHttpClient.Builder<AwsCrtAsyncHttpClien
326326
* client before we stop reading from the underlying TCP socket and wait for the Subscriber
327327
* to read more data.
328328
*
329-
* @param readBufferSize The number of bytes that can be buffered
329+
* @param readBufferSize The number of bytes that can be buffered. The maximum buffering size value is
330+
* capped at {@code Integer.MAX}.
330331
* @return The builder of the method chaining.
331-
*
332-
* TODO: This is also used for the write buffer size. Should we rename it?
333332
*/
334-
Builder readBufferSizeInBytes(Integer readBufferSize);
333+
Builder readBufferSizeInBytes(Long readBufferSize);
335334

336335
/**
337336
* Sets the http proxy configuration to use for this client.
@@ -427,7 +426,7 @@ Builder tcpKeepAliveConfiguration(Consumer<TcpKeepAliveConfiguration.Builder>
427426
*/
428427
private static final class DefaultBuilder implements Builder {
429428
private final AttributeMap.Builder standardOptions = AttributeMap.builder();
430-
private Integer readBufferSize;
429+
private Long readBufferSize;
431430
private ProxyConfiguration proxyConfiguration;
432431
private ConnectionHealthConfiguration connectionHealthConfiguration;
433432
private TcpKeepAliveConfiguration tcpKeepAliveConfiguration;
@@ -456,7 +455,7 @@ public Builder maxConcurrency(Integer maxConcurrency) {
456455
}
457456

458457
@Override
459-
public Builder readBufferSizeInBytes(Integer readBufferSize) {
458+
public Builder readBufferSizeInBytes(Long readBufferSize) {
460459
Validate.isPositiveOrNull(readBufferSize, "readBufferSize");
461460
this.readBufferSize = readBufferSize;
462461
return this;

http-clients/aws-crt-client/src/main/java/software/amazon/awssdk/http/crt/internal/CrtRequestContext.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
@SdkInternalApi
2424
public final class CrtRequestContext {
2525
private final AsyncExecuteRequest request;
26-
private final int readBufferSize;
26+
private final long readBufferSize;
2727
private final HttpClientConnectionManager crtConnPool;
2828
private final MetricCollector metricCollector;
2929

@@ -42,7 +42,7 @@ public AsyncExecuteRequest sdkRequest() {
4242
return request;
4343
}
4444

45-
public int readBufferSize() {
45+
public long readBufferSize() {
4646
return readBufferSize;
4747
}
4848

@@ -56,7 +56,7 @@ public MetricCollector metricCollector() {
5656

5757
public static class Builder {
5858
private AsyncExecuteRequest request;
59-
private int readBufferSize;
59+
private long readBufferSize;
6060
private HttpClientConnectionManager crtConnPool;
6161

6262
private Builder() {
@@ -67,7 +67,7 @@ public Builder request(AsyncExecuteRequest request) {
6767
return this;
6868
}
6969

70-
public Builder readBufferSize(int readBufferSize) {
70+
public Builder readBufferSize(long readBufferSize) {
7171
this.readBufferSize = readBufferSize;
7272
return this;
7373
}

http-clients/aws-crt-client/src/main/java/software/amazon/awssdk/http/crt/internal/request/CrtRequestBodyAdapter.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ final class CrtRequestBodyAdapter implements HttpRequestBodyStream {
2727
private final SdkHttpContentPublisher requestPublisher;
2828
private final ByteBufferStoringSubscriber requestBodySubscriber;
2929

30-
CrtRequestBodyAdapter(SdkHttpContentPublisher requestPublisher, int readLimit) {
30+
CrtRequestBodyAdapter(SdkHttpContentPublisher requestPublisher, long readLimit) {
3131
this.requestPublisher = requestPublisher;
3232
this.requestBodySubscriber = new ByteBufferStoringSubscriber(readLimit);
3333
requestPublisher.subscribe(requestBodySubscriber);

0 commit comments

Comments
 (0)