user1679671
user1679671

Reputation:

OkHttp do not keep idle connections for keep alive duration

Why it could be that OkHttp does not keep an idle connection in the pool for the keep-alive duration? That results in connection count spiking back and forth much faster than actual keep alive duration.

There's only one host with just 1 rps. maxIdleConnections is set to 20, keepAlive is set to 20 minutes. The latencies though might reach up to 2 seconds per call.

Connection count is spiking from 1 to 3 and back constantly, like every few minutes.

Upvotes: 2

Views: 2790

Answers (1)

Jesse Wilson
Jesse Wilson

Reputation: 40593

Have you configured maxIdleConnections ? If you're hitting lots of hosts then OkHttp will close connections to stay within that limit.

https://square.github.io/okhttp/4.x/okhttp/okhttp3/-connection-pool/-init-/

Upvotes: 2

Related Questions