1

I'm a beginner to request/response service programming using apache HTTP clients and am trying to understand how a client with a connection pool to a server might have some connections go stale in that pool.

Here's what I currently understand:

  • stale connections are a result of the server disconnecting the connection but the client not knowing
  • trying to use a stale connection on a request could result in org.apache.http.NoHttpResponseException
  • connection pools should have an eviction policy to clean up stale connections and remake new ones, however there is a tradeoff for performance because new connections are expensive to make

I currently have a service that is getting called about 20 req/second and I get org.apache.http.NoHttpResponseException (presumably due to stale connections) about 15 times an hour. How can I calculate my eviction policy?

I'm using a threadpool of 10 threads. Current eviction policy is to scan the pool every 5 seconds and remove threads that are idle for 30 seconds or more.

I'm interested in if there is a rough estimation process for structuring my eviction policy?

Olaf Kock
  • 46,930
  • 8
  • 59
  • 90
gurdingering
  • 207
  • 5
  • 12
  • Trying to use a stale connection *will fail.* There is no 'tradeoff for performance', as there is no correct behaviour with a stale connection. Only you know how long your server will hold a kept-alive HTTP connection, so only you can determine the correct idle timeout. Unclear what you're asking. – user207421 Jul 25 '20 at 10:15
  • Check if [this answer](https://stackoverflow.com/a/50901789/2834978) helps a bit. Your eviction policy might be too long. – LMC Jul 28 '20 at 23:43

0 Answers0