On 18/03/2024 03:01, Jonathan Amir wrote:
Thank you again for your detailed answer.
I am wondering about the pros and cons of validateAfterInactivity vs.
evictIdleConnections.

validateAfterInactivity - I am guessing, for lack of any other information,
that inactivity here is meant to be the same as idleness. Thus, after the
connection is idle for a while it will be validated.
If it is valid then it is kept. If it isn't, then it is dropped and at the
next request httpclient will create a new connection.

#validateAfterInactivity is performed by the connection manager while processing connection lease requests. Basically if the client is idle and there are no lease requests stale connections can get stuck in the pool indefinitely.


evictIdleConnections - after a while the connection is dropped (evicted)
unconditionally and then at the next request we pay the price to create a
new connection.


#evictIdleConnections proactively evicts idle connections irrespective of client activity (or inactivity).


It seems to me that the performance characteristics are as follows.
If the connection is no longer valid:
- validate - we pay the price to validate the connection and the price to
create a new one.
- evict - we only pay the price to create a new connection.
If the connection is still good:
- validate - we pay the price of validating it and that's it.
- evict - we pay the price of creating a new connection, but it was not
really necessary.

Is the cost of validating a connection comparable to the cost of creating a
new one?

Certainly new connection creation is more expensive than a single validation check, especially if TLS is involved. However if one executes thousands of requests over the same connection the total cost of validation can become significant. The whole point of having the #evictIdleConnections setting is to reduce instances of validation checks. Let's say if the connection was operational 1 second ago, it is quite likely to be still valid. After 30 seconds, who knows?

So, if I think that idle connections will mostly stay valid, the validation
option is better. If I think they'll mostly go bad, the eviction is better.


Pretty much. One should probably employ both settings, but keep #evictIdleConnections invocations infrequent, say, every 3 minutes of so, just to make sure the connection pool gets flushed if there is no activity for a long period of time and there are no lease requests that could cause stale connections to get evicted.

Oleg

---------------------------------------------------------------------
To unsubscribe, e-mail: httpclient-users-unsubscr...@hc.apache.org
For additional commands, e-mail: httpclient-users-h...@hc.apache.org

Reply via email to