Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

OkHttp how to set maximum connection pool size (not max idle connections)

In OkHttp I cannot find a way to set a hard maximum connection pool size. From the documentation https://square.github.io/okhttp/3.x/okhttp/okhttp3/ConnectionPool.html it is clear that you can set a maximum idle connections, but not an overall max. That means that with high load it can grow beyond any limit.

Is there a way to maximize the pool? If not, why not?

like image 351
user1120821 Avatar asked Sep 13 '17 20:09

user1120821


People also ask

How many connection pools should I have?

For optimal performance, use a pool with eight to 16 connections per node. For example, if you have four nodes configured, then the steady-pool size must be set to 32 and the maximum pool size must be 64.

What is connection pool settings?

Specifies the maximum number of physical connections that you can create in this pool. These are the physical connections to the backend resource. When this number is reached, no new physical connections are created.

What is OkHttp connection pool?

What is OkHttp? OkHttp is an HTTP client from Square for Java and Android applications. It's designed to load resources faster and save bandwidth. OkHttp is widely used in open-source projects and is the backbone of libraries like Retrofit, Picasso, and many others.


1 Answers

Connections are either active and held by a particular in-flight call, or idle and in the pool. Limit the total number of connections by limiting the number of threads executing HTTP calls. If you’re using Call.execute() (synchronous) just size your thread pool appropriately. If you’re using Call.enqueue() (asynchronous) the limits are in Dispatcher.

like image 82
Jesse Wilson Avatar answered Oct 04 '22 21:10

Jesse Wilson