Discussion:
Using Connection pooling gives no performance gain
Sreyan Chakravarty
2018-06-16 17:32:44 UTC
Permalink
Hi,

I am using Apache HTTP Client with Springs Rest Template service to have
connection pooling implemented for my REST Client. The code for connection
pooling is from the documentation and is similar to this-:

PoolingHttpClientConnectionManager cm = new
PoolingHttpClientConnectionManager();

cm.setMaxTotal(200);

cm.setDefaultMaxPerRoute(20);

HttpHost host = new HttpHost("java.com", 80);
cm.setMaxPerRoute(new HttpRoute(host), 50);

CloseableHttpClient httpClient = HttpClients.custom()
.setConnectionManager(cm)
.build();

I got this code from :
https://hc.apache.org/httpcomponents-client-ga/tutorial/html/connmgmt.html

Making REST calls with and without connection pooling gives no performance
benefits. My REST calls still need 1.3ms to complete even if I make them
one after the other.

Am I doing something wrong? Is this the correct way to implement HTTP
Connection Pooling?

*Does HTTP Connection Pooling mean that subsequent HTTP requests on the
same thread will happen faster?*

Thanks,
Sreyan
Alexey Panchenko
2018-06-16 17:54:25 UTC
Permalink
Hi Sreyan,

It's a little bit not clear what is compared, as you provided only one code
snippet.
PoolingHttpClientConnectionManager is used even if you create HttpClient
with HttpClients.createDefault(), just parameters are different.

A performance benefit can happen if the services called support persistent
connections <https://en.wikipedia.org/wiki/HTTP_persistent_connection>.
In order to understand what happens you can enable debug logging for
HttpClient.

Regards,
Alex

On Sun, Jun 17, 2018 at 12:33 AM Sreyan Chakravarty <
Post by Sreyan Chakravarty
Hi,
I am using Apache HTTP Client with Springs Rest Template service to have
connection pooling implemented for my REST Client. The code for connection
PoolingHttpClientConnectionManager cm = new
PoolingHttpClientConnectionManager();
cm.setMaxTotal(200);
cm.setDefaultMaxPerRoute(20);
HttpHost host = new HttpHost("java.com", 80);
cm.setMaxPerRoute(new HttpRoute(host), 50);
CloseableHttpClient httpClient = HttpClients.custom()
.setConnectionManager(cm)
.build();
https://hc.apache.org/httpcomponents-client-ga/tutorial/html/connmgmt.html
Making REST calls with and without connection pooling gives no performance
benefits. My REST calls still need 1.3ms to complete even if I make them
one after the other.
Am I doing something wrong? Is this the correct way to implement HTTP
Connection Pooling?
*Does HTTP Connection Pooling mean that subsequent HTTP requests on the
same thread will happen faster?*
Thanks,
Sreyan
Sreyan Chakravarty
2018-06-17 16:12:18 UTC
Permalink
Hi Alex,

So just to clarify, you are saying that if the webservice supports
Persistent connection, then only I will get the performance benefit that I
want?

Am I correct?

Regards,
Sreyan
Post by Alexey Panchenko
Hi Sreyan,
It's a little bit not clear what is compared, as you provided only one code
snippet.
PoolingHttpClientConnectionManager is used even if you create HttpClient
with HttpClients.createDefault(), just parameters are different.
A performance benefit can happen if the services called support persistent
connections <https://en.wikipedia.org/wiki/HTTP_persistent_connection>.
In order to understand what happens you can enable debug logging for
HttpClient.
Regards,
Alex
On Sun, Jun 17, 2018 at 12:33 AM Sreyan Chakravarty <
Post by Sreyan Chakravarty
Hi,
I am using Apache HTTP Client with Springs Rest Template service to have
connection pooling implemented for my REST Client. The code for
connection
Post by Sreyan Chakravarty
PoolingHttpClientConnectionManager cm = new
PoolingHttpClientConnectionManager();
cm.setMaxTotal(200);
cm.setDefaultMaxPerRoute(20);
HttpHost host = new HttpHost("java.com", 80);
cm.setMaxPerRoute(new HttpRoute(host), 50);
CloseableHttpClient httpClient = HttpClients.custom()
.setConnectionManager(cm)
.build();
https://hc.apache.org/httpcomponents-client-ga/tutorial/html/connmgmt.html
Post by Sreyan Chakravarty
Making REST calls with and without connection pooling gives no
performance
Post by Sreyan Chakravarty
benefits. My REST calls still need 1.3ms to complete even if I make them
one after the other.
Am I doing something wrong? Is this the correct way to implement HTTP
Connection Pooling?
*Does HTTP Connection Pooling mean that subsequent HTTP requests on the
same thread will happen faster?*
Thanks,
Sreyan
Loading...