英文:
Why do HTTP connections in a pool become stale? And are there guidelines on how can I calculate an eviction policy?
问题
我是初学者,正在尝试使用Apache HTTP客户端进行请求/响应服务编程,希望能够理解具有连接池的客户端在与服务器通信时可能会出现某些连接失效的情况。
以下是我目前的理解:
- 失效的连接是由服务器断开连接而客户端不知情所导致的。
- 在请求中使用失效的连接可能会导致
org.apache.http.NoHttpResponseException
错误。 - 连接池应该有驱逐策略来清理失效的连接并创建新的连接,然而这会涉及性能权衡,因为创建新连接的代价较高。
我目前的服务大约每秒会被调用约 20 次请求,但每小时会大约出现 15 次 org.apache.http.NoHttpResponseException
错误(可能是由于失效的连接引起)。我该如何计算适合的驱逐策略呢?
我使用了一个由10个线程组成的线程池。当前的驱逐策略是每隔5秒扫描一次连接池,并移除那些空闲了30秒或更久的线程。
我想知道是否有大致的估算过程,可以用来构建我的驱逐策略?
英文:
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?
专注分享java语言的经验与见解,让所有开发者获益!
评论