-
Notifications
You must be signed in to change notification settings - Fork 9.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
TTL on connections #3374
Comments
Just to confirm I understand: because the network topology is dynamic, you’d like to impose a maximum lifetime on a connection? We can do that, though it’s not a great fit for the problem. Whatever time period we use will be too long when you want to change your topology, and too short when you don’t. My experience is that whenever we add configuration options like this many users want to use them, and this would be problematic. A more natural fit would be for the client or server that’s being taken out of the network to terminate manually. For webservers this is adding |
As one option yes. Another option would be to monitor DNS changes and only recycle connections if DNS records actually change. We ended up creating our own Instead of doing this from the consumer side, I think it would be beneficial if |
Cool. I think that’s a good fix. |
@swankjesse Why it is problematic? If the particular configuration option is excessively used, isn't that indication that it's needed? |
It is not how HTTP works. Clients aren’t supposed to have special configuration for their endpoints. In particular, browsers don’t do this. Instead the solution must be server-side. |
Thanks @swankjesse, that's a good point. |
I have one more usecase, which in my option is not solved by server-side connection termination. Disaster recovery. This is not AWS related, bear in mind please. In case a loadbalancer fails (stops listening to its port), we do the failover by switching the hostname resolution on DNS. As this is not predictable, we can't expect the failing loadbalancer to terminate connections. |
this expected feature exists for apache httpClient connection pool. check timeToLive parameter for this class: https://hc.apache.org/httpcomponents-client-4.5.x/current/httpclient/apidocs/org/apache/http/impl/conn/PoolingHttpClientConnectionManager.html what's the issue: expected: |
Linking to #190 just in case anyone is looking for OkHttp's timeToLive (TTL), max age, max lifetime. AKA keepAliveDuration. |
Leaving a comment for those who might attempt the Putting this here for documentation, as this issue seems to be one of the top results on search engines. Relates to #4530 |
What kind of issue is this?
already exists! Don’t send pull requests to implement new features without first getting our
support. Sometimes we leave features out on purpose to keep the project small.
We are using OkHttp as an HTTP client as part of a multi service application in AWS.
Our services are behind ELBs and we are using a connection pool per client (with a client per downstream service). ELBs use DNS round robing with a TTL of 60 seconds. Our idle timeout is set to 50 seconds.
We are seeing persistent connections that are in use for a long period of time. In particular we observer errors in cases where a downstream service/stack gets replaced (which will replace the ELB nodes) and those connections become stale.
In addition to errors, we are also not fully leveraging ELB nodes being scaled out, due to the fact that connections in the pool live for significantly longer than the DNS TTL and new nodes are not being used.
This is unlikely to be a problem when OkHttp is used for mobile clients as there are many clients with significantly fewer load balancer nodes, but in our case we are looking at a much smaller set of client nodes that connect to the ELB/LB nodes.
We have a couple of options here (as far as I can tell):
maxIdleConnections
seems to mostly do this)The former might be ok for the parts that are not directly on the user request path, but it would be unfortunate if we couldn't use connection pooling at all.
The latter is an approach that we have implemented, but it has some gremlins as care needs to be taken to properly manage the lifetime of the client and its pool and the scheduled task that periodically evicts connections.
Is there interest in allowing clients to specify a connection time-to-live in addition to the idle timeout? Managing this as part of the client or (more likely) the pool seems much better in terms of properly managing the lifecycle of the pool and its management thread.
Or are we misusing OkHttp in the way we use it?
The text was updated successfully, but these errors were encountered: