Skip to content
Tom Fitzhenry edited this page Jun 13, 2016 · 14 revisions

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 DefaultAsyncHttpClientConfig.Builder:

DefaultAsyncHttpClientConfig.Builder builder = new DefaultAsyncHttpClientConfig.Builder()
    .setMaxConnections(500)
    .setMaxConnectionsPerHost(200)
    .setPooledConnectionIdleTimeout(100)
    .setConnectionTtl(500)
    .build();
AsyncHttpClient http = new DefaultAsyncHttpClient(builder);

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:

  • keeps the fewest number of connections active, thus allowing the remaining connections to be terminated via idle timeouts, thus conserving resources
  • by leasing recently-used connections, there's less chance the leased connections are closed, or are in the process of being closed

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 a First In, First Out basis:

ChannelPool pool = new DefaultChannelPool(cfg, PoolLeaseStrategy.FIFO, timer);
DefaultAsyncHttpClientConfig.Builder builder = new DefaultAsyncHttpClientConfig.Builder()
    .setChannelPool(pool)
    .build();
AsyncHttpClient http = new DefaultAsyncHttpClient(builder);
Clone this wiki locally