Apache-Http-Client : Ideal Value for Keep-Alive Timeout

Viewed 411

I have a server-client setup, both being Java applications. I am using Spring's RestTemplate with PoolingHttpClientConnectionManager at the client end to call the server. The server (tomcat) has the default keep-alive value of an http-connection as 60 seconds. This means that if the client uses the same connection (lying idle in pool) again after 60 seconds for another request, the server will close the connection. Then, client automatically creates another connection object and sends the request via this connection to the server.

Without going into the code and internal working, I simply want to know that what is the best practice regarding http-client's keep-alive time? Do I

  1. keep the default value (connection is kept-alive indefinitely by the client), OR
  2. set the keep-alive time less than server keep-alive time? In this case http-client will always check, before leasing a connection, that whether that connection has expired or not. If expired, it is discarded from the pool, a new connection is created and leased to the requesting thread.
0 Answers
Related