简体   繁体   中英

Connection Pool - OkHttp

We are using OkHttp in WAS environment Could you please help us with the below queries -:

Question 1-: What should be the ideal connection pool size and keep Alive for a container environment, is there any formula to calculate it, we will be using Okhttp client to connect to two different URL's

Question 2-: - We dont want to have any client side failures, how does OkHttp handle stale connections, I dont see any parameter in OkHttp to check for stale connections?

http java client java has this parameter to turn on stale connection check

http.connection.stalecheck

We are using OkHttp client as mentioned below, is there any important configuration am I missing?

new OkHttpClient.Builder()
              .readTimeout(10,TimeUnit.SECONDS)
              .retryOnConnectionFailure(false)
              .connectTimeOut(5,TimeUnit.SECONDS)
              .connectionPool(new ConnectionPool(10,5,TimeUnit.SECONDS)
              .build();

What should be the ideal connection pool size and keep Alive for a container environment

Take 256 as a starting point. It's big enough that you'll get a good hit rate and small enough that you won't notice the memory used.

If you hit lots of different hosts frequently you may adjust it up. If you are running on very small containers or have memory sensitivity you may adjust it down.

We dont want to have any client side failures

There's a setting on OkHttpClient.Builder, retryOnConnectionFailure . It's true by default and will handle client-side failures for you. If you did want to handle client-side failures you'd set this to false.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM