From 8384e58fbdfb259846eed59812da1edaa67883b2 Mon Sep 17 00:00:00 2001 From: Waqar Ahmed Khan Date: Mon, 12 Aug 2024 08:52:56 -0700 Subject: [PATCH] Connection Manager Updates (#815) --- .gitignore | 3 ++ crt/aws-c-auth | 2 +- crt/aws-c-common | 2 +- crt/aws-c-io | 2 +- crt/aws-c-sdkutils | 2 +- crt/s2n | 2 +- .../crt/http/HttpClientConnectionManager.java | 8 +++- .../HttpClientConnectionManagerOptions.java | 46 ++++++++++++++++++- src/native/http_connection_manager.c | 6 ++- 9 files changed, 64 insertions(+), 9 deletions(-) diff --git a/.gitignore b/.gitignore index 253b8e165..7623ed85e 100644 --- a/.gitignore +++ b/.gitignore @@ -97,3 +97,6 @@ docs/ # graalvm manually generated config files graalvm-configuration + +# LSP +.cache diff --git a/crt/aws-c-auth b/crt/aws-c-auth index 300ae823a..52bf59161 160000 --- a/crt/aws-c-auth +++ b/crt/aws-c-auth @@ -1 +1 @@ -Subproject commit 300ae823aa0d5cacfabe901f55096f0452c4ca89 +Subproject commit 52bf591613d1a001c43ec99af7376f871759c5fe diff --git a/crt/aws-c-common b/crt/aws-c-common index 67601bbbc..2add521b7 160000 --- a/crt/aws-c-common +++ b/crt/aws-c-common @@ -1 +1 @@ -Subproject commit 67601bbbce6ea1c26191f235afc50007a4e796c5 +Subproject commit 2add521b78d69f9f043a701232e751f43cf123e6 diff --git a/crt/aws-c-io b/crt/aws-c-io index e455d9032..c345d7727 160000 --- a/crt/aws-c-io +++ b/crt/aws-c-io @@ -1 +1 @@ -Subproject commit e455d90320c569300f0ba50535d7a1a5f9aff399 +Subproject commit c345d77274db83c0c2e30331814093e7c84c45e2 diff --git a/crt/aws-c-sdkutils b/crt/aws-c-sdkutils index 8c7af71f9..4658412a6 160000 --- a/crt/aws-c-sdkutils +++ b/crt/aws-c-sdkutils @@ -1 +1 @@ -Subproject commit 8c7af71f91ed5b9d2a043d51f120495f43723f80 +Subproject commit 4658412a61ad5749db92a8d1e0717cb5e76ada1c diff --git a/crt/s2n b/crt/s2n index 138e3ece9..79c0f1b43 160000 --- a/crt/s2n +++ b/crt/s2n @@ -1 +1 @@ -Subproject commit 138e3ece9e457c2f824a85b63095737f30d624a9 +Subproject commit 79c0f1b434742d9f1152c48d3781433649f6f8fe diff --git a/src/main/java/software/amazon/awssdk/crt/http/HttpClientConnectionManager.java b/src/main/java/software/amazon/awssdk/crt/http/HttpClientConnectionManager.java index de1508b5d..3161673ff 100644 --- a/src/main/java/software/amazon/awssdk/crt/http/HttpClientConnectionManager.java +++ b/src/main/java/software/amazon/awssdk/crt/http/HttpClientConnectionManager.java @@ -136,7 +136,9 @@ private HttpClientConnectionManager(HttpClientConnectionManagerOptions options) options.getMaxConnectionIdleInMilliseconds(), monitoringThroughputThresholdInBytesPerSecond, monitoringFailureIntervalInSeconds, - expectedHttpVersion.getValue())); + expectedHttpVersion.getValue(), + options.getMaxPendingConnectionAcquisitions(), + options.getConnectionAcquisitionTimeoutInMilliseconds())); /* we don't need to add a reference to socketOptions since it's copied during connection manager construction */ addReferenceTo(clientBootstrap); @@ -267,7 +269,9 @@ private static native long httpClientConnectionManagerNew(HttpClientConnectionMa long maxConnectionIdleInMilliseconds, long monitoringThroughputThresholdInBytesPerSecond, int monitoringFailureIntervalInSeconds, - int expectedProtocol) throws CrtRuntimeException; + int expectedProtocol, + long maxPendingConnectionAcquisitions, + long connectionAcquisitionTimeoutInMilliseconds) throws CrtRuntimeException; private static native void httpClientConnectionManagerRelease(long conn_manager) throws CrtRuntimeException; diff --git a/src/main/java/software/amazon/awssdk/crt/http/HttpClientConnectionManagerOptions.java b/src/main/java/software/amazon/awssdk/crt/http/HttpClientConnectionManagerOptions.java index 1a050cbb0..124d63a6f 100644 --- a/src/main/java/software/amazon/awssdk/crt/http/HttpClientConnectionManagerOptions.java +++ b/src/main/java/software/amazon/awssdk/crt/http/HttpClientConnectionManagerOptions.java @@ -33,8 +33,10 @@ public class HttpClientConnectionManagerOptions { private HttpMonitoringOptions monitoringOptions; private long maxConnectionIdleInMilliseconds = 0; private HttpVersion expectedHttpVersion = HttpVersion.HTTP_1_1; + private long connectionAcquisitionTimeoutInMilliseconds; + private long maxPendingConnectionAcquisitions; - private static final String HTTP = "http"; + private static final String HTTP = "http"; private static final String HTTPS = "https"; /** @@ -286,6 +288,48 @@ public HttpClientConnectionManagerOptions withMaxConnectionIdleInMilliseconds(lo return this; } + /** + * @return Return the connection acquisition timeout in miliseconds + */ + public long getConnectionAcquisitionTimeoutInMilliseconds() { + return connectionAcquisitionTimeoutInMilliseconds; + } + + + /** + * If set, {@link HttpClientConnectionManager#acquireConnection()} + * will give up after waiting this long for a connection from the pool, + * failing with error AWS_ERROR_HTTP_CONNECTION_MANAGER_ACQUISITION_TIMEOUT. + * @param connectionAcquisitionTimeoutInMilliseconds timeout in milliseconds. + * @return this + */ + public HttpClientConnectionManagerOptions withConnectionAcquisitionTimeoutInMilliseconds(int connectionAcquisitionTimeoutInMilliseconds) { + this.connectionAcquisitionTimeoutInMilliseconds = connectionAcquisitionTimeoutInMilliseconds; + return this; + } + + + /** + * @return Return the max pending connection acquisitions + */ + public long getMaxPendingConnectionAcquisitions() { + return maxPendingConnectionAcquisitions; + } + + + /** + * If set, {@link HttpClientConnectionManager#acquireConnection()} will fail with + * AWS_ERROR_HTTP_CONNECTION_MANAGER_MAX_PENDING_ACQUISITIONS_EXCEEDED if there are already pending acquisitions + * equal to `maxPendingConnectionAcquisitions`. + * + * @param maxPendingConnectionAcquisitions maximum pending acquisitions allowed + * @return this + */ + public HttpClientConnectionManagerOptions withMaxPendingConnectionAcquisitions(int maxPendingConnectionAcquisitions) { + this.maxPendingConnectionAcquisitions = maxPendingConnectionAcquisitions; + return this; + } + /** * @return How long to allow connections to be idle before reaping them */ diff --git a/src/native/http_connection_manager.c b/src/native/http_connection_manager.c index eed131498..203811104 100644 --- a/src/native/http_connection_manager.c +++ b/src/native/http_connection_manager.c @@ -115,7 +115,9 @@ JNIEXPORT jlong JNICALL Java_software_amazon_awssdk_crt_http_HttpClientConnectio jlong jni_max_connection_idle_in_milliseconds, jlong jni_monitoring_throughput_threshold_in_bytes_per_second, jint jni_monitoring_failure_interval_in_seconds, - jint jni_expected_protocol_version) { + jint jni_expected_protocol_version, + jlong jni_max_pending_connection_acquisitions, + jlong jni_connection_acquisition_timeout_ms) { (void)jni_class; (void)jni_expected_protocol_version; @@ -187,6 +189,8 @@ JNIEXPORT jlong JNICALL Java_software_amazon_awssdk_crt_http_HttpClientConnectio /* TODO: this variable needs to be renamed in aws-c-http. Come back and change it next revision. */ manager_options.enable_read_back_pressure = jni_manual_window_management; manager_options.max_connection_idle_in_milliseconds = jni_max_connection_idle_in_milliseconds; + manager_options.max_pending_connection_acquisitions = jni_max_pending_connection_acquisitions; + manager_options.connection_acquisition_timeout_ms = jni_connection_acquisition_timeout_ms; struct aws_http_connection_monitoring_options monitoring_options; AWS_ZERO_STRUCT(monitoring_options);