In a spring boot application, I am creating a connection pool using PoolingHttpClientConnectonManager as follows:
@Bean
public PoolingHttpClientConnectionManager createCM() {
PoolingHttpClientConnectionManager pcm = new PoolingHttpClientConnectionManager();
poolingHttpClientConnectionManager.setMaxTotal(100);
poolingHttpClientConnectionManager.setDefaultMaxPerRoute(100);
return pcm;
}
Since I have only one route, I keep the values of setMaxTotal and setDefaultMaxPerRoute same.
The underlying httpClient configuration is as follows:
@Bean
public CloseableHttpClient createHttpClient(PoolingHttpClientConnectionManager pcm, RequestConfig rc) {
CloseableHttpClient httpClient = HttpClientBuilder
.create()
.setConnectionManager(pcm)
.setDefaultRequestConfig(rc)
.build();
return httpClient;
}
Now the problem is that when I stress test my application under very heavy loads to see how my connection pool would behave, I don't see the expected. I monitor the threads of the application using jConsole and every single time I see only 2 connection pool threads in runnable state namely https-jsse-nio-80-ClientPoller-1 and https-jsse-nio-80-ClientPoller-2.
I presume under heavy loads of the order of 1500 requests per second, it should have done it by more than 2 (default) connections in the pool. wondering what's going wrong or if my configuration is not correct.
In my case I'm using http component as soap client library and I use a class implementing WebServiceGatewaySupport. On this i do as follows:
httpComponentsRequestFactory = new HttpComponentsClientHttpRequestFactory();
httpComponentsRequestFactory.setReadTimeout(readTimeout);
httpComponentsRequestFactory.setConnectTimeout(connectionTimeout);
httpComponentsRequestFactory.setHttpClient(createHttpClient(createConnectionManager(), createRequestConfig()));
client.setMessageSender(new ClientHttpRequestMessageSender(httpComponentsRequestFactory));
and enabling logging to level DEBUG for org.apache.http I see now:
Connection released: [id: 0][route: {}->http://host:8080][total available: 1; route allocated: 1 of 100; total allocated: 1 of 100]
so I manged to rise the default to 100 connections.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.