Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add config for http client connect timeout #16831

Merged
merged 2 commits into from
Aug 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions docs/configuration/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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.<br /><br />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

Expand Down Expand Up @@ -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|
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
import org.joda.time.Period;

import javax.validation.constraints.Min;
import java.util.concurrent.TimeUnit;

/**
*
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -129,6 +133,11 @@ public boolean isEagerInitialization(boolean defaultValue)
return eagerInitialization;
}

public long getClientConnectTimeout()
{
return clientConnectTimeout;
}

private static HumanReadableBytes computeDefaultMaxQueuedBytes()
{
return HumanReadableBytes.valueOf(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -91,7 +88,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());
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It would be better to remove CLIENT_CONNECT_TIMEOUT_MILLIS variable as well

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

+1

httpClient.setRequestBufferSize(config.getRequestBuffersize());
final QueuedThreadPool pool = new QueuedThreadPool(config.getNumMaxThreads());
pool.setName(JettyHttpClientModule.class.getSimpleName() + "-threadPool-" + pool.hashCode());
Expand Down
Loading