OkHttpClient: Enhancing Network Performance
<p>The remarkable abstractions provided by Square’s networking library, OkHttp, tend to overshadow the optimizations it brings, often escaping the notice of application developers. It uses the standard TCP handshake based connection for new requests and offers a default connection pool of 5 connections (each active for 5 minutes) to reuse previously setup TCP connection for subsequent requests.</p>
<pre>
class ConnectionPool internal constructor(
internal val delegate: RealConnectionPool
) {
constructor(
maxIdleConnections: Int,
keepAliveDuration: Long,
timeUnit: TimeUnit
) : this(RealConnectionPool(
taskRunner = TaskRunner.INSTANCE,
maxIdleConnections = maxIdleConnections,
keepAliveDuration = keepAliveDuration,
timeUnit = timeUnit
))
constructor() : this(5, 5, TimeUnit.MINUTES)
...
}
</pre>
<h1>Under the hood</h1>
<p>How does a connection pool enhance network performance? This can be verified using a OkHttp call specific EventListener.</p>
<p><a href="https://medium.com/@debuggingisfun/okhttpclient-enhancing-network-performance-33a3c8459e6f"><strong>Visit Now</strong></a></p>