Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Springs RestTemplate default connection pool

Just wondering if RestTemplate out of the box uses connection pooling or does it simply establish a new connection each time ?

like image 631
Sam Avatar asked May 25 '17 19:05

Sam


People also ask

Does RestTemplate use connection pooling?

Yes, Spring RestTemplateBuilder uses Apache HttpClient for pooling (usage).

Which connection pool is best for spring boot?

Spring Boot uses HikariCP as the default connection pool, due to its remarkable performance and enterprise-ready features.

What is HTTP connection pooling?

When you set up connection pooling, instead of closing the client HTTP connection after use, CICS keeps the connection open and stores it in a pool in a dormant state. The dormant connection can be reused by the same application or by another application that connects to the same host and port.

Does RestTemplate use HTTP client?

RestTemplate delegates to a ClientHttpRequestFactory, and one of the implementations of this interface uses Apache's HttpClient.


1 Answers

Yes, Spring RestTemplateBuilder uses Apache HttpClient for pooling (usage). RestTemplateBuilder creates HttpComponentsClientHttpRequestFactory and uses HttpClientBuilder.

HttpClientBuilder, by default, sets pool size per route (host) to 5 and total pool size to 10 (source):

s = System.getProperty("http.maxConnections", "5");  int max = Integer.parseInt(s);  poolingmgr.setDefaultMaxPerRoute(max);  poolingmgr.setMaxTotal(2 * max);               

To check connection pool logging set logging level as follows:

org.apache.http.impl.conn.PoolingHttpClientConnectionManager=TRACE 
like image 89
Volodymyr Kret Avatar answered Sep 24 '22 12:09

Volodymyr Kret