Libraries
HttpClient Connection Management
Clients could Jersey Client, Apache Client, Google Client
Client could use Connection Manager e.g. Apache Pooled Connection Manager
HttpClient Connection Management
Focus on timeouts for complex connection issues
Connection Manager
Apache PoolingHttpClientConnectionManager
Has socket timeout
Clients
Request config has socket timeout, connection timeout, connection request timeout
Connection Request Timeout - How long to wait when trying to checkout a connection from the connection pool before throwing an exception (the connection pool won't return immediately if, for example, all the connections are checked out)
Connection Timeout - Determines the timeout in milliseconds until a connection is established.
Socket Timeout - Defines the socket timeout (SO_TIMEOUT) in milliseconds, which is the timeout for waiting for data or, put differently, a maximum period inactivity between two consecutive data packets).
Apacha Client use request config with all 3 timeouts
Jersey Client does not use request config, however has socket timeout and connection timeout
Request has socket timeout
Usually socket timeout is overridden from request based on read\write bandwidth
The connection timeout is critical, however could be longer if connection request timeout can save the caller
Example timeouts: Socket timeout - 15s, Connection timeout - 15s, Connection request timeout - 2s
Socket timeout - 15s, Connection timeout - 2s iff connection request timeout is not present, this is to nullify impact on caller if connection takes a bit longer
setSoKeepAlive - Sets value of the CoreConnectionPNames.SO_KEEPALIVE parameter. Defines whether or not TCP is to send automatically a keepalive probe to the peer after an interval of inactivity (no data exchanged in either direction) between this host and the peer. The purpose of this option is to detect if the peer host crashes. This is part of socket config.
Quoting the HttpClient 4.3.3. reference: “If the Keep-Alive header is not present in the response, HttpClient assumes the connection can be kept alive indefinitely.” (See the HttpClient Reference). To get around this, and be able to manage dead connections we need a customized strategy implementation and build it into the HttpClient.
The only timeout that can be set at the time when pooled connection manager is configured is the socket timeout.