spring-redis异常could not get a resource from the pool或read timed out

redis服务器是windows版的。

项目使用spring集成redis,偶尔会出现read timed out的情况,刚开始以为是网络不稳定引起的。后面发现影响业务测试的准确性,才认真去看这个问题,实际是could not get a resource from the pool,连接池不够用。

网上看了很多博客都大同小异:

1. 说redis连接池配置不正确,最大连接数配置太小

尝试调整maxTotal为500、1000,依然出现异常

2. 说使用redisTemplate时未关闭连接,需要手动关闭

查看了源码,如果是非事务性调用不存在这个问题,每一次的调用都会自动关闭

 

在redis客户端层面的调整都无法解决这个异常,只能转向服务端了。

既然短连接不够用,考虑是否可以换成长连接,于是在配置文件中找到了一个参数

# TCP keepalive.
#
# If non-zero, use SO_KEEPALIVE to send TCP ACKs to clients in absence
# of communication. This is useful for two reasons:
#
# 1) Detect dead peers.
# 2) Take the connection alive from the point of view of network
#    equipment in the middle.
#
# On Linux, the specified value (in seconds) is the period used to send ACKs.
# Note that to close the connection the double of the time is needed.
# On other kernels the period depends on the kernel configuration.
#
# A reasonable value for this option is 60 seconds.
tcp-keepalive 0

tcp-keepalive默认是0,但上面推荐了一个合理值,设置为60。

重启redis,异常不见了,妥妥的。

具体原因还不清楚,表象是服务端提供的资源不能满足客户端的需求,是否有什么工具可以检测供求情况,用了Redis Desktop Manager 没看出什么苗头来,各位大佬懂的可以指教。

181341_W2Ir_1993461.png

 

上面的方案仅供参考,还要根据实际情况而定。因为生产环境使用的某云的Redis服务,未发现该问题。

转载于:https://my.oschina.net/u/1993461/blog/1795302

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值