We are using AsynHttpClient in our application. We have a use case where we have to make huge number of fire and forget requests, As this uses NIo we thought its a good approach.
The AHC Client as mentioned in the documentation suggests it shares life cycle as application("AsyncHttpClient instances are intended to be global resources that share the same lifecycle as the application").
So I initialized the AHC client once and kept on using it.
An overview of what the functionality is:
public class Client{
private static AsyncHttpClientConfig asyncHttpClientConfig = new AsyncHttpClientConfig().Builder().setRequestTimeout(someMs).setMaxRetryCount()
private static AsyncHttpClient asyncHttpClient = AsyncHTTPClientFactory.getAsyncHttpClient(asyncHttpClientConfig)
public static AsyncHttpClient getClient(){
return asyncHttpClient;
}
}
public class Usageclass{
// some code
AsyncHttpClient asyncHttpClient = Client.getClient();
Future response = asyncHttpClient.setRootEndpoint(url).setBody(body).execute();
}
We would be able to monitor the JVM memory available through a dashboard provided by other team. I see that the JVM memory available in the application goes down with incoming requests, as soon as GC(garbage collector) kicks in I see the memory is not completely freed up. Each time garbage collection done the available JVM memory is reduced from previous runs.
I wanted to know if this is because we are not closing the AHC connection ? If so what would be the right approach ?