Skip to content
GFoniX edited this page Jan 7, 2023 · 14 revisions

Download installer

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:

  • 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 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)
);