记redis一次Could not get a resource from the pool 异常的解决过程
最近有个项目中的redis每天都会报 "Could not get a resource from the pool"的错误,而这套代码在另一地方部署又没有问题。一直找不到错误原因。按字面意思是连接池中资源不够。
1. 有可能是并发太高而连接池太小,尝试修改连接池上限来解决问题,修改方法如下:
- <!-- redis连接池的配置 -->
- <bean id="jedisPoolConfig" class="redis.clients.jedis.JedisPoolConfig">
- <property name="maxTotal" value="${spring.redis.maxTotal}"/>
- <property name="maxIdle" value="${spring.redis.maxIdle}"/>
- <property name="minIdle" value="${spring.redis.minIdle}"/>
- <property name="testOnBorrow" value="${spring.redis.testOnBorrow}"/>
- <property name="testOnReturn" value="${spring.redis.testOnReturn}"/>
- </bean>
修改 maxTotal 到 60 100 300,可以改变连接池大小
- spring.redis.maxTotal=8
- spring.redis.maxIdle=8
- spring.redis.minIdle=1
- spring.redis.testOnBorrow=true
- spring.redis.testOnReturn=true
将连接池上限修改到很大,运行后发现还是没有解决,仍然报错,有时还会报 "clusterdown the cluster is down"。将maxIdle与minIdle调大,也是一样没有效果。
2. 有网友说有可能是redis连接没有被释放,连接池设再大也没用。项目使用了spring-data-redis,按理释放是不需要自己处理的,项目使用的配置如下:
- <bean id="redisTemplate" class="org.springframework.data.redis.core.RedisTemplate">
- <property name="connectionFactory" ref="jedisConnectionFactory" />
- <property name="keySerializer" ref="stringRedisSerializer" />
- <property name="hashKeySerializer" ref="stringRedisSerializer" />
- <property name="valueSerializer" ref="stringRedisSerializer"/>
- </bean>
这里并没有使用redis事务功能,默认情况下 RedisTemplate 的 enableTransactionSupport = false, 所以不需要手动释放连接。
关于开启事务后手动释放的代码,参考这里(https://www.cnblogs.com/DDgougou/p/10268206.html)
3.网上有网友说有可能是jedis版本的问题,当前项目使用的版本为:
- <dependency>
- <groupId>redis.clients</groupId>
- <artifactId>jedis</artifactId>
- <version>2.9.0</version>
- </dependency>
更新到2.9.3,继续测试。
- <dependency>
- <groupId>redis.clients</groupId>
- <artifactId>jedis</artifactId>
- <version>2.9.3</version>
- </dependency>
测试发现,提示终于有变化了,不再显示"Could not get a resource from the pool",但问题还是没有解决,因为项目使用集群的原因,变成提示"Too many Cluster redirections",这是什么鬼???确实没有了连接池的错误提示,但又出现新的问题。
4. 检查redis集群,"Too many Cluster redirections"的意思是连不上其中一个节点,尝试连另一个配置的节点,如果都连不上,就会提示这个错误。检查redis集群方法如下:
- 利用redis-cli命令进行远程检查
- redis-cli -h 127.0.0.1 -p
- // 连接成功 如果设置了密码,需要运行命令 auth xxx xxx为密码
- 运行 cluster info 检查
执行结果,集群正常
- xxx:> cluster info
- cluster_state:ok
- cluster_slots_assigned:
- cluster_slots_ok:
- cluster_slots_pfail:
- cluster_slots_fail:
- cluster_known_nodes:
- cluster_size:
- cluster_current_epoch:
- cluster_my_epoch:
- cluster_stats_messages_sent:
- cluster_stats_messages_received:
- (.53s)
集群没问题,但总会偶尔连不上,因为把做了3个节点(redis与mysql装在同一台服务器上),全连不上的机率不大,所以最大的可能就是服务器或者服务器的网络出问题,造成"Too many Cluster redirections"这个错误的发生。
最后通过观察发现出错的规律,当mysql在执行一个很耗时的存储过程CPU高得飞起时,就很容易出现报错的情况。最终基本确定是服务器突然卡引起的异常,所以才会一会正常偶尔又会报错。
经过一天的验证与解决,出现"Could not get a resource from the pool"进的解决方法总结如下:
1. 参数问题,有可能是连接池太小引起
2. jedis版本问题引起
3.服务器性能引起
最终把redis移到另一台服务器上,问题解决。
记redis一次Could not get a resource from the pool 异常的解决过程的更多相关文章
- Redis的安装以及spring整合Redis时出现Could not get a resource from the pool
Redis的下载与安装 在Linux上使用wget http://download.redis.io/releases/redis-5.0.0.tar.gz下载源码到指定位置 解压:tar -xvf ...
- redis中 Could not get a resource from the pool 异常解决
https://blog.csdn.net/qh_java/article/details/54669973
- 记一次 java 连接 linux ssh服务 权限验证失败的原因和解决过程
下面的问题我是通过之前的ssh测试类找出原因的,因为我的测试类跑通了,但是程序跑不通,看了一下源码发现还有一处没有进行解密,所以才会权限验证失败. // 出现权限验证失败的原因就在这里,因为老板要求对 ...
- Redis一个异常的解决办法,异常描述:Could not get a resource from the pool
异常描述: redis.clients.jedis.exceptions.JedisConnectionException: Could not get a resource from the poo ...
- 再记一次w3wp占用CPU过高的解决过程(Dictionary和线程安全)
在此之前项目有发生过两次类似的状况,都得以解决,但最近又会发现偶尔CPU会跑满,虽然之前使用过WinDbg解决过两次问题但人的记忆是不可靠的,今天处理同样问题的时候还是遇到了一些障碍,这一次希望可以记 ...
- redis提示Could not get a resource from the pool(jedis连接池配置)
起初在JedisPool中配置了50个活动连接,但是程序还是经常报错:Could not get a resource from the pool 连接池刚开始是这样配置的: JedisPoolCon ...
- redis.clients.jedis.exceptions.JedisConnectionException: Could not get a resource from the pool
超时 Exception in thread "main" redis.clients.jedis.exceptions.JedisConnectionException: jav ...
- redis性能调优笔记(can not get Resource from jedis pool和jedis connect time out)
对这段时间redis性能调优做一个记录. 1.单进程单线程 redis是单进程单线程实现的,如果你没有特殊的配置,redis内部默认是FIFO排队,即你对redis的访问都是要在redis进行排队,先 ...
- redis客户端可以连接集群,但JedisCluster连接redis集群一直报Could not get a resource from the pool
一,问题描述: (如题目)通过jedis连接redis单机成功,使用JedisCluster连接redis集群一直报Could not get a resource from the pool 但是使 ...
随机推荐
- .lib和.dll文件
LIB文件中存放的是函数调用的信息,值得一提的是数据库有静态数据库(.lib文件)和动态数据库(.dll文件). 静态编译 静态编译将导出声明和实现都放在lib中.编译后所有代码都嵌入到宿主程序. 静 ...
- 检测是否安装或者开启flash
function flashChecker() { var hasFlash = 0; //是否安装了flash var flashVersion = 0; //flash版本 if(document ...
- [E2E_L9]类化和级联化
一.多车辆识别可能和车辆车牌分割: 这样一张图,可以识别多车辆和车牌,问题是如何区分并且配对. 0 1 7 8 是否是车牌可以通过图片的大小进行判断.而配对是前后顺序的. // ------- ...
- np.concatenate
- centos7.6环境编译安装php-7.2.24修复最新 CVE-2019-11043 漏洞
先编译安装php-7.2.24,然后编译安装扩展 主版本地址地址:https://www.php.net/distributions/php-7.2.24.tar.gz # 编译 php-7.2.24 ...
- C# winform判断窗体是否已打开
Form1 form; /// <summary> /// 开始检测 /// </summary> /// <param name="sender"& ...
- 非LODOP的打印其他问题-简短问答
该文是一些应用软件,或打印机,即使不使用lodop,也可能会常见的问题.一般和操作系统,电脑硬件打印机硬件等有关. 1.错误-正在打印 怎么解决这个是打印机队列的状态,排查下电脑和打印机的连线是否正常 ...
- 【linux基础】ubuntu16.04 安装后,屏幕分辨率过低且不可调节
前言 安装CUDA和NVIDIA驱动之后,屏幕分辨率过低且不可调节,尝试了几种方法都没成功解决,特此讲解决方法记录下来. 解决过程 注销进入登录界面,按ctrl+alt+F1进入命令行终端,输入账户名 ...
- [LeetCode] 801. Minimum Swaps To Make Sequences Increasing 最少交换使得序列递增
We have two integer sequences A and B of the same non-zero length. We are allowed to swap elements A ...
- C++全排列 next_permutation
全排列函数 next_permutation 这是C++的STL中专门用来排列的函数(可以自动处理存在重复数据集的排列问题) 使用时要加上头文件 #include <algorithm> ...