What is the difference between different apache-httpclient5 config provided by Apache HttpClient 5?

Versions (relevant - OpenSearch/Dashboard/Server OS/Browser):
OpenSearch: 2.11.1
opensearch-java: 2.8.1
Apache Http Client5 Transport

Describe the issue:
I am trying to understand various underlying Apache HttpClient 5 configs that can be used when setting up OpenSearch Java client, which uses Apache HttpClient 5. There are bunch of config provided by Apache HttpClient5 to modify how you use the client. But, these seems to be the most important: RequestConfig, and CloseableHttpAsyncClient, which includes IOReactorConfig and PoolingAsyncClientConnectionManager, which then includes ConnectionConfig. Here is the hierarchy of how I list them and what I think they mean based on the information I have found:

1. RequestConfig: Configure the request made by the http client. 
- setConnectionRequestTimeout(Timeout): Timeout for the request made by the http client to get a connection from the connection pool.
- setConnectTimeout(Timeout): Timeout for the request made by the http client to get a connection from the host. 
- setResponseTimeout(Timeout): Timeout for the request made by the http client to get a response from the host.
- setConnectionKeepAlive(TimeValue): Timeout for the active connection to the host when not set via Keep-Alive response header.
2. CloseableHttpAsyncClient: Configure the http client. 
- evictIdleConnections(TimeValue): Evict idle connections from the connection pool after the set time. 
- evictExpiredConnections(): If set to true, evict expired connections from the connection pool after some time.
- setIOReactorConfig(IOReactorConfig): Configure the I/O Reactor that manages I/O requests made by the http client. 
  - setSoTimeout(Timeout): Socket timeout for I/O requests made by the http client. Or maximum time for a blocked operation to finish its operation before throwing SocketTimeoutException. 
  - setSoKeepAlive(boolean): Something will send requests to detect broken or idle connections. 
  - setIoThreadCount(int): Number of threads used by the I/O Reactor. 
  - setSelectInterval(TimeValue): Time interval when I/O Reactor checks for socket timeout or some session requests.
- setConnectionManager(PoolingAsyncClientConnectionManager): Connection Manager that manages the connection pool used by the http client. 
  - setMaxConnTotal(int): Maximum threads in the connection pool. 
  - setDefaultConnectionConfig(ConnectionConfig): Connection Manager additional configuration. 
    - setConnectTimeout(Timeout): No idea what this is. This might be similar to either RequestConfig setConnectionRequestTimeout() or setConnectTimeout(), or might be different all together.
    - setValidateAfterInactivity(TimeValue): Time period after which the active connections to the host needs to be validated if they are broken or stale. 
    - setSocketTimeout(Timeout): No idea what this is. This might be similar to IOReactorConfig setSoTimeout(), or might be completely different.
    - setTimeToLive(TimeValue): TTL for a connection in the connection pool. 

I am not sure how are these related or different from each other. Can anyone provide an explanation if my understanding of them are incorrect or how they are related, and how I can use them in my services that interacts with the OpenSearch cluster in production? Thank you!

Hey @chintan_patel

There are indeed many of those, the ones ApacheHttpClient5TransportBuilder makes explicit use of at the moment are:

RequestConfig: Configure the request made by the http client. 
- setConnectTimeout(Timeout): Timeout for the request made by the http client to get a connection from the host. 
- setResponseTimeout(Timeout): Timeout for the request made by the http client to get a response from the host.

These and other parameters could be set using HttpClientConfigCallback while building Apache HttpClient 5 based transport and solely depend on what application or service need. Thanks you.

1 Like

Hey @reta ,
But, don’t you need to use other configs to configure the number of clients connecting to OpenSearch and number of threads in the connection pool? Or is that managed by default by OpenSearch when using ApacheHttpClient5TransportBuilder? Thank you!

@chintan_patel We do use other configs you’ve been asking about the ones related to different timeouts, please check ApacheHttpClient5TransportBuilder [1] for more details, thank you

[1] opensearch-java/java-client/src/main/java/org/opensearch/client/transport/httpclient5/ApacheHttpClient5TransportBuilder.java at main · opensearch-project/opensearch-java · GitHub

1 Like