连接池 - OkHttp [英] Connection Pool - OkHttp

查看:91
本文介绍了连接池 - OkHttp的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们在 WAS 环境中使用 OkHttp 能否请您帮助我们进行以下查询 -:

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

问题 1-: 容器环境中理想的连接池大小和保持 Alive 应该是多少,是否有计算公式,我们将使用 Okhttp 客户端连接到两个不同的 URL

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

问题 2-: - 我们不希望出现任何客户端故障,OkHttp 如何处理陈旧连接,我在 OkHttp 中没有看到任何用于检查陈旧连接的参数?

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 客户端 java 有这个参数开启过时连接检查

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

http.connection.stalecheck

我们正在使用下面提到的 OkHttp 客户端,我缺少什么重要的配置吗?

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

以 256 为起点.它足够大,您可以获得良好的命中率,并且足够小,您不会注意到使用的内存.

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

OkHttpClient.Builder 上有一个设置,retryOnConnectionFailure.默认情况下为 true,将为您处理客户端故障.如果您确实想处理客户端故障,则可以将其设置为 false.

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.

这篇关于连接池 - OkHttp的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆