Connection pooling - AsyncHttpClient/async-http-client Wiki

async-http-client supports HTTP persistent connections. Connections are stored in a ChannelPool.

The default ChannelPool is DefaultChannelPool.

Optionally, connection pool behaviour can be configured via AsyncHttpClientConfig:

import static org.asynchttpclient.Dsl.*;

AsyncHttpClient http = asyncHttpClient(config()
    .setMaxConnections(500)
    .setMaxConnectionsPerHost(200)
    .setPooledConnectionIdleTimeout(100)
    .setConnectionTtl(500)
);

Default values can found in ahc-default.properties

Per-implementation configuration

DefaultChannelPool

By default, DefaultChannelPool will lease connections on a Last In, First Out basis. This has a few advantages:

Alternatively, some users may prefer to keep an artificially large number of connections, for example, to be able to handle bursty load. This can be achieved by configuring DefaultChannelPool to lease connections on a First In, First Out basis:

import static org.asynchttpclient.Dsl.*;

HashedWheelTimer timer = new HashedWheelTimer();
timer.start();
ChannelPool pool =
  new DefaultChannelPool(60000, -1, DefaultChannelPool.PoolLeaseStrategy.FIFO, timer);
AsyncHttpClient httpClient = asyncHttpClient(config()
    .setNettyTimer(timer)
    .setChannelPool(pool)
);