Using Apache HttpClient 5.2, I am creating a CloseableHttpAsyncClient for HTTP/2 only traffic. Here is the basic template:
CloseableHttpAsyncClient client;
IOReactorConfig ioReactorConfig = IOReactorConfig.custom()
.setSoTimeout(Timeout.ofSeconds(soTimeout))
.build();
client = HttpAsyncClients.customHttp2()
.setIOReactorConfig(ioReactorConfig)
.build();
Under high load, I occasionally get a ConnectionClosedException, and I am not sure if it is coming from the server or from my side.
I am considering several options to improve the resiliency of the client's internal connection pool, as shown in the code below, but I don't understand them as they are very under-documented, and it seems that some of them overlap. I'd appreciate any pointers to real documentation or example.
- What is the different between the two socket timeout values, one in the reactor config and one in the connection config?
- Is the socket keep alive configuration necessary? What exactly does it do?
- Does the TTL means that connections will be evicted and re-created even if they are healthy?
- What is the connection, if any, between the methods
setValidateAfterInactivity
andevictIdleConnections
? Can either one of them be used without the other? - what are the recommended values for socket timeout, connection timeout, idle time to eviction, and so on?
CloseableHttpAsyncClient client;
IOReactorConfig ioReactorConfig = IOReactorConfig.custom()
.setSoTimeout(Timeout.ofSeconds(soTimeout))
.setSoKeepAlive(true)
.build();
ConnectionConfig connConfig = ConnectionConfig.custom()
.setConnectTimeout(connectionTimeout)
.setSocketTimeout(soTimeout)
.setTimeToLive(ttl)
.setValidateAfterInactivity()
.build();
client = HttpAsyncClients.customHttp2()
.setIOReactorConfig(ioReactorConfig)
.setDefaultConnectionConfig(connConfig)
.evictIdleConnections(evictIdleTimeValue)
.build();