when handling a request, my backend will trigger many HTTP request using Apach HttpClient to a host.
I find now every time it trigger a HTTP reqeust,a new HttpClient (DefaultHttpClient, which is deprecated) will be created and used.
Altought these requests are HTTP requests, but their target host are the same, the only different thing is their POST body.
Q1. So, can I reuse a keep-alive connection (which should be a keep-alive TCP connection if there is) to trigger these request to reduce cost time on client.execute?
What I have tried:
I think everytime a new DefaultHttpClient instance obviously cannot hold a keep-alive connection, so I register a HttpClient spring Bean and resue it.
and when creating the HttpClient Bean:
return HttpClientBuilder.create()
.setConnectionManager(new PoolingHttpClientConnectionManager(3000, TimeUnit.MICROSECONDS))
set a PoolingHttpClientConnectionManager for it.
However, The final result shows that the time spent on httpClient.execute increases instead.
Q2. the PoolingHttpClientConnectionManager, is its target to make a HttpClient able to be reused to open many connection and doesn't it match my goal (there should be only one connection and many POST requests are made concurrently based on this connection)?
Thanks a lot.