Wednesday 9 October 2013

Use HttpClient in Multithreaded Environment

Basic recommendations

1) We need to create one instance of the httpClient[1].

2) Recommend to use PoolingClientConnectionManager (or PoolingHttpClientConnectionManager in (4.3)) and specify defaults.

3) Good article for defaults configs - Sensible Defaults for Apache HttpClient:
http://dev.bizo.com/2013/04/sensible-defaults-for-apache-httpclient.html

 Resume table:


Configuration
Connection timeout
Socket timeout
MaxTotal
MaxPerRoute
SameRegion
125 ms
125 ms
200
100
SameRegionWithUSEastFailover
1 second
1 second
200
100
CrossRegion
10 seconds
10 seconds
200
100
MaxTimeout
1 minute
5 minutes
200
100



4) Once the call is made ​​to the resource, the connection can be reused by his manager if the method call releaseConnections () is done, from here  - HttpClient - Best Pratices : http://vincentdevillers.blogspot.fr/2011/09/httpclient-best-pratices.html

References:

1) From documentation - "Generally it is recommended to have a single instance of HttpClient per communication component or even per application. However, if the application makes use of HttpClient only very infrequently, and keeping an idle instance of HttpClient in memory is not warranted, it is highly recommended to explicitly shut down the multithreaded connection manager prior to disposing the HttpClient instance. This will ensure proper closure of all HTTP connections in the connection pool."

2) Http Client - Performance  - http://hc.apache.org/httpclient-legacy/performance.html

2 comments:

  1. Great analysis, thank you!

    ReplyDelete
  2. Nice assortment of resources, thanks!

    ReplyDelete