Skip to content
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

Tune connection pool behavior: timeouts, limits + connection selection #1397

Closed
slackhappy opened this issue Feb 12, 2015 · 4 comments
Closed
Labels
enhancement Feature not a bug
Milestone

Comments

@slackhappy
Copy link

I'm not 100% sure, but I think ConnectionPool is using an LRU scheme. For connections from the phone, our app would probably perform better with an MRU scheme. The reason is that older connections are more likely to have their tcp connections reset, either by the client or by the server (though we are now setting all of the timeouts from the ConfigureTimeouts.java recipe).

In our particular case, reconnecting can be pretty expensive. Our DNS load balancing usually causes each new resolution to go to a different SSL terminator, meaning we may not resume the SSL session, so we also have to redo the handshake, but in any case, it would would be preferable to just use the connection whose tcp connection is the most likely to be active, which is the one that was just returned to the pool.

We are currently trying to mitigate by making sure our keepAlive timeout is slightly smaller than the tcp timeouts (thereby ensuring any member selected by ConnectionPool.get is probably alive), but it would be nice to also play around with a different selection policy like MRU.

Any advice on connection best practices, anything I am missing or misinterpreting?

Thanks!

@swankjesse
Copy link
Member

The current implementation prefers to return connections that have been in the pool the longest. This strategy wins for some usage patterns, and loses for others.

I'd love to get some data and see some experiments here. Not exactly sure how to conduct that though, particularly on reporting real-world behavior back.

@swankjesse swankjesse added the enhancement Feature not a bug label Feb 23, 2015
@swankjesse swankjesse added this to the 3.0 milestone Feb 23, 2015
@swankjesse swankjesse changed the title MRU as an option or default for ConnectionPool.get? Tune connection pool behavior: timeouts, limits + connection selection Feb 23, 2015
@aaronzirbes
Copy link

👍

@swankjesse
Copy link
Member

By the way, it’s very straightforward to implement this with our newest ConnectionPool rewrite. Instead of returning on the first connection that matches, return either the one with the oldest idle period or the newest idle period.

Anyone who makes that change & does experiments it in the wild has the option of significantly improving OkHttp’s performance for everyone!

@swankjesse swankjesse modified the milestones: Icebox, 3.0 Dec 31, 2015
@yschimke
Copy link
Collaborator

yschimke commented Aug 1, 2019

I don't think this last comment is still relevant. This ticket is effectively a dupe of #4530 and #5191

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement Feature not a bug
Projects
None yet
Development

No branches or pull requests

4 participants