From 1b8636b7b3daae898149c3cb483c62e83cf0ccf3 Mon Sep 17 00:00:00 2001 From: Atul Mohan Date: Thu, 1 Aug 2024 15:46:03 -0700 Subject: [PATCH 1/2] Add config for client connect timeout --- docs/configuration/index.md | 4 ++++ .../apache/druid/guice/http/DruidHttpClientConfig.java | 9 +++++++++ .../apache/druid/guice/http/JettyHttpClientModule.java | 2 +- 3 files changed, 14 insertions(+), 1 deletion(-) diff --git a/docs/configuration/index.md b/docs/configuration/index.md index 3b3c2711d3b4..435517e64e5e 100644 --- a/docs/configuration/index.md +++ b/docs/configuration/index.md @@ -841,6 +841,7 @@ All Druid components can communicate with each other over HTTP. |`druid.global.http.readTimeout`|The timeout for data reads.|`PT15M`| |`druid.global.http.unusedConnectionTimeout`|The timeout for idle connections in connection pool. The connection in the pool will be closed after this timeout and a new one will be established. This timeout should be less than `druid.global.http.readTimeout`. Set this timeout = ~90% of `druid.global.http.readTimeout`|`PT4M`| |`druid.global.http.numMaxThreads`|Maximum number of I/O worker threads|`max(10, ((number of cores * 17) / 16 + 2) + 30)`| +|`druid.global.http.clientConnectTimeout`|The timeout (in milliseconds) for establishing client connections.|500| ### Common endpoints configuration @@ -1880,6 +1881,8 @@ client has the following configuration options. |`druid.broker.http.unusedConnectionTimeout`|The timeout for idle connections in connection pool. The connection in the pool will be closed after this timeout and a new one will be established. This timeout should be less than `druid.broker.http.readTimeout`. Set this timeout = ~90% of `druid.broker.http.readTimeout`|`PT4M`| |`druid.broker.http.maxQueuedBytes`|Maximum number of bytes queued per query before exerting [backpressure](../operations/basic-cluster-tuning.md#broker-backpressure) on channels to the data servers.

Similar to `druid.server.http.maxScatterGatherBytes`, except that `maxQueuedBytes` triggers [backpressure](../operations/basic-cluster-tuning.md#broker-backpressure) instead of query failure. Set to zero to disable. You can override this setting by using the [`maxQueuedBytes` query context parameter](../querying/query-context.md). Druid supports [human-readable](human-readable-byte.md) format. |25 MB or 2% of maximum Broker heap size, whichever is greater.| |`druid.broker.http.numMaxThreads`|`Maximum number of I/O worker threads|max(10, ((number of cores * 17) / 16 + 2) + 30)`| +|`druid.broker.http.clientConnectTimeout`|The timeout (in milliseconds) for establishing client connections.|500| + ##### Retry policy @@ -2240,3 +2243,4 @@ Supported query contexts: |`druid.router.http.numMaxThreads`|Maximum number of worker threads to handle HTTP requests and responses|`max(10, ((number of cores * 17) / 16 + 2) + 30)`| |`druid.router.http.numRequestsQueued`|Maximum number of requests that may be queued to a destination|`1024`| |`druid.router.http.requestBuffersize`|Size of the content buffer for receiving requests. These buffers are only used for active connections that have requests with bodies that will not fit within the header buffer|`8 * 1024`| +|`druid.router.http.clientConnectTimeout`|The timeout (in milliseconds) for establishing client connections.|500| diff --git a/server/src/main/java/org/apache/druid/guice/http/DruidHttpClientConfig.java b/server/src/main/java/org/apache/druid/guice/http/DruidHttpClientConfig.java index 70ed44f2eb8a..ff5025701bcc 100644 --- a/server/src/main/java/org/apache/druid/guice/http/DruidHttpClientConfig.java +++ b/server/src/main/java/org/apache/druid/guice/http/DruidHttpClientConfig.java @@ -27,6 +27,7 @@ import org.joda.time.Period; import javax.validation.constraints.Min; +import java.util.concurrent.TimeUnit; /** * @@ -72,6 +73,9 @@ public class DruidHttpClientConfig @JsonProperty private Boolean eagerInitialization = null; + @JsonProperty + private long clientConnectTimeout = TimeUnit.MILLISECONDS.toMillis(500); + public int getNumConnections() { return numConnections; @@ -129,6 +133,11 @@ public boolean isEagerInitialization(boolean defaultValue) return eagerInitialization; } + public long getClientConnectTimeout() + { + return clientConnectTimeout; + } + private static HumanReadableBytes computeDefaultMaxQueuedBytes() { return HumanReadableBytes.valueOf( diff --git a/server/src/main/java/org/apache/druid/guice/http/JettyHttpClientModule.java b/server/src/main/java/org/apache/druid/guice/http/JettyHttpClientModule.java index 3c2ad854f23f..c6933464b31b 100644 --- a/server/src/main/java/org/apache/druid/guice/http/JettyHttpClientModule.java +++ b/server/src/main/java/org/apache/druid/guice/http/JettyHttpClientModule.java @@ -91,7 +91,7 @@ public HttpClient get() httpClient.setIdleTimeout(config.getReadTimeout().getMillis()); httpClient.setMaxConnectionsPerDestination(config.getNumConnections()); httpClient.setMaxRequestsQueuedPerDestination(config.getNumRequestsQueued()); - httpClient.setConnectTimeout(CLIENT_CONNECT_TIMEOUT_MILLIS); + httpClient.setConnectTimeout(config.getClientConnectTimeout()); httpClient.setRequestBufferSize(config.getRequestBuffersize()); final QueuedThreadPool pool = new QueuedThreadPool(config.getNumMaxThreads()); pool.setName(JettyHttpClientModule.class.getSimpleName() + "-threadPool-" + pool.hashCode()); From e18d4331f0f9ccf0317ae1873b2ff9648eb3adc3 Mon Sep 17 00:00:00 2001 From: Atul Mohan Date: Mon, 5 Aug 2024 08:35:41 -0700 Subject: [PATCH 2/2] Timeout constant is no longer needed --- .../org/apache/druid/guice/http/JettyHttpClientModule.java | 3 --- 1 file changed, 3 deletions(-) diff --git a/server/src/main/java/org/apache/druid/guice/http/JettyHttpClientModule.java b/server/src/main/java/org/apache/druid/guice/http/JettyHttpClientModule.java index c6933464b31b..c4eefa027042 100644 --- a/server/src/main/java/org/apache/druid/guice/http/JettyHttpClientModule.java +++ b/server/src/main/java/org/apache/druid/guice/http/JettyHttpClientModule.java @@ -33,15 +33,12 @@ import javax.net.ssl.SSLContext; import java.lang.annotation.Annotation; -import java.util.concurrent.TimeUnit; /** * */ public class JettyHttpClientModule implements Module { - private static final long CLIENT_CONNECT_TIMEOUT_MILLIS = TimeUnit.MILLISECONDS.toMillis(500); - public static JettyHttpClientModule global() { return new JettyHttpClientModule("druid.global.http", Global.class);