How to configure apache httpasncyclient with http/2 and healthy connections

62 views Asked by At

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.

  1. What is the different between the two socket timeout values, one in the reactor config and one in the connection config?
  2. Is the socket keep alive configuration necessary? What exactly does it do?
  3. Does the TTL means that connections will be evicted and re-created even if they are healthy?
  4. What is the connection, if any, between the methods setValidateAfterInactivity and evictIdleConnections? Can either one of them be used without the other?
  5. 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();
0

There are 0 answers