Reputation: 5916
When using HttpOk in sync. mode with a connection pool, the maxIdleConnections is a limit per host or global?
In the source code I can see a comment saying it is per address but however I can't find this information in a public documentation (javadoc, wiki) and also when looking at the source code it seems to be global (I only see it used in connectionsCleanupRunnable without knowledge of the address).
If all the "cached" connections are being used and another thread wants to establish a connection, a new one will be created right? Will it be closed at the end of the exchange or added to the connection pool, and closed + cleaned up when next time connectionsCleanupRunnable is being run?
Thanks :)
Upvotes: 3
Views: 4617
Reputation: 4132
In okHTTP3 the connection pooling is not global anymore
Note: as of OkHttp3, it is recommended you declare this object as a singleton because changes in OkHttp3 no long require a global connection pool.
ref# https://guides.codepath.com/android/Using-OkHttp
There is no longer a global singleton connection pool. In OkHttp 2.x, all OkHttpClient instances shared a common connection pool by default. In OkHttp 3.x, each new OkHttpClient gets its own private connection pool. Applications should avoid creating many connection pools as doing so prevents connection reuse. Each connection pool holds its own set of connections alive so applications that have many pools also risk exhausting memory!
The best practice in OkHttp 3 is to create a single OkHttpClient instance and share it throughout the application. Requests that needs a customized client should call OkHttpClient.newBuilder() on that shared instance. This allows customization without the drawbacks of separate connection pools.
ref# https://github.com/amplitude/Amplitude-Android/issues/79
Upvotes: 3
Reputation: 40593
It's per-host. Idle connections will be removed from the pool if they've been there for 5 minutes.
Upvotes: 4