From 7018f6547fc8625f471c96b1a55390d7d5fd2113 Mon Sep 17 00:00:00 2001 From: Amy D'Entremont Date: Wed, 3 Nov 2021 17:15:49 -0400 Subject: [PATCH 1/2] explain how the max connection settings are used --- .../java/com/hubspot/horizon/HttpConfig.java | 27 +++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/HorizonCore/src/main/java/com/hubspot/horizon/HttpConfig.java b/HorizonCore/src/main/java/com/hubspot/horizon/HttpConfig.java index ac538de..59242a6 100644 --- a/HorizonCore/src/main/java/com/hubspot/horizon/HttpConfig.java +++ b/HorizonCore/src/main/java/com/hubspot/horizon/HttpConfig.java @@ -63,10 +63,37 @@ public static Builder newBuilder() { return new Builder(); } + /** + * The HttpClient will use this setting to throttle requests. + * + * If the client gets a request, but the max connections are already in use, + * the client will block indefinitely until it has a free connection for the request, + * then make the request once it's able. + * + * The default value is 100. + */ public int getMaxConnections() { return maxConnections; } + /** + * Unlike maxConnections, the HttpClient will use this per-host setting to IMMEDIATELY FAIL any requests + * that would cause it to exceed the connections per host limit. + * The client does NOT block / wait for any amount of time if it gets a request when the max connections per host are already used up; + * instead, a TooManyConnectionsPerHostException is thrown from the client immediately. + * + * Note, the `connectTimeout` doesn't come into play in this connection limiting. + * Instead, the internal `acquireTimeout` is the timeout for acquiring a connection permit; + * this setting isn't exposed and the default is 0. + * + * If you want to use the client to throttle requests indefinitely without throwing exceptions for connection limits, + * setting maxConnectionsPerHost to a higher number than maxConnections works most of the time + * (except there's some race condition that can be hit when the client is being totally overwhelmed). + * If possible, it can be better to limit requests to the client. + * For example, it might be possible to limit a thread pool that uses the client accordingly. + * + * The default value is 25. + */ public int getMaxConnectionsPerHost() { return maxConnectionsPerHost; } From 0c12ae3bd979aecc065c37f26e54e3a79b4cc409 Mon Sep 17 00:00:00 2001 From: Steve Gutz Date: Fri, 11 Feb 2022 12:19:40 -0500 Subject: [PATCH 2/2] Update javadoc --- .../src/main/java/com/hubspot/horizon/HttpConfig.java | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/HorizonCore/src/main/java/com/hubspot/horizon/HttpConfig.java b/HorizonCore/src/main/java/com/hubspot/horizon/HttpConfig.java index 59242a6..0437903 100644 --- a/HorizonCore/src/main/java/com/hubspot/horizon/HttpConfig.java +++ b/HorizonCore/src/main/java/com/hubspot/horizon/HttpConfig.java @@ -77,18 +77,18 @@ public int getMaxConnections() { } /** - * Unlike maxConnections, the HttpClient will use this per-host setting to IMMEDIATELY FAIL any requests + * Unlike {@link #getMaxConnections()}, the HttpClient will use this per-host setting to IMMEDIATELY FAIL any requests * that would cause it to exceed the connections per host limit. * The client does NOT block / wait for any amount of time if it gets a request when the max connections per host are already used up; - * instead, a TooManyConnectionsPerHostException is thrown from the client immediately. + * instead, a {@link org.asynchttpclient.shaded.exception.TooManyConnectionsPerHostException} is thrown from the client immediately. * - * Note, the `connectTimeout` doesn't come into play in this connection limiting. + * Note, {@link #getConnectTimeoutMillis()} doesn't come into play in this connection limiting. * Instead, the internal `acquireTimeout` is the timeout for acquiring a connection permit; * this setting isn't exposed and the default is 0. * * If you want to use the client to throttle requests indefinitely without throwing exceptions for connection limits, - * setting maxConnectionsPerHost to a higher number than maxConnections works most of the time - * (except there's some race condition that can be hit when the client is being totally overwhelmed). + * use {@link Builder#setMaxConnectionsPerHost(int)} to a higher number than {@link #getMaxConnections()} works + * most of the time (except there's some race condition that can be hit when the client is being totally overwhelmed). * If possible, it can be better to limit requests to the client. * For example, it might be possible to limit a thread pool that uses the client accordingly. *