加入收藏 | 设为首页 | 会员中心 | 我要投稿 济南站长网 (https://www.0531zz.com/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 站长学院 > MySql教程 > 正文

记一次找因Redis使用不当导致应用卡死Bug的过程

发布时间:2019-10-14 00:39:00 所属栏目:MySql教程 来源:小木
导读:副标题#e# 首先说下问题现象:内网sandbox环境API持续1周出现应用卡死,所有api无响应现象 刚开始当测试抱怨环境响应慢的时候 ,我们重启一下应用,应用恢复正常,于是没做处理。但是后来问题出现频率越来越频繁,越来越多的同事开始抱怨,于是感觉代码可能

随意找一个线程查看堆内存

  1. thread -428 

记一次找因Redis使用不当导致应用卡死Bug的过程

这是能确认就是api一直转圈的问题,就是这个redis获取连接的代码导致的,

解读这段内存代码  所有线程都在等 @53e5504e这个对象释放锁。于是jstack 全局搜了一把53e5504e ,没有找到这个对象所在线程。

自此。问题原因能确定是 redis连接获取的问题。但是什么原因造成获取不到连接的还不能确定

再次执行 arthas 的thread -b (thread -b, 找出当前阻塞其他线程的线程)

记一次找因Redis使用不当导致应用卡死Bug的过程

没有结果。这边和想的不一样,应该是能找到一个阻塞线程的,于是看了下这个命令的文档,发现有下面的一句话

记一次找因Redis使用不当导致应用卡死Bug的过程

好吧,我们刚好是后者。。。。

再次整理下思路。这次修改redis pool 配置,将获取连接超时时间设置为2s,然后等问题再次复现时观察应用最后正常时干过什么。

添加一下配置

  1. JedisConnectionFactory jedisConnectionFactory = new JedisConnectionFactory();  
  2. .......  
  3. JedisPoolConfig config = new JedisPoolConfig();  
  4. config.setMaxWaitMillis(2000);  
  5. .......  
  6. jedisConnectionFactory.afterPropertiesSet(); 

重启服务,等待。。。。

又过一天,再次复现

ssh 服务器,检查tomcat accesslog ,发现大量api 请求出现500,

  1. org.springframework.data.redis.RedisConnectionFailureException: Cannot get Jedis connection; nested exception is redis.clients.jedis.exceptions.JedisConnectionException: Could not get a resource fr 
  2.  om the pool  
  3.     at org.springframework.data.redis.connection.jedis.JedisConnectionFactory.fetchJedisConnector(JedisConnectionFactory.java:140)  
  4.     at org.springframework.data.redis.connection.jedis.JedisConnectionFactory.getConnection(JedisConnectionFactory.java:229)  
  5.     at org.springframework.data.redis.connection.jedis.JedisConnectionFactory.getConnection(JedisConnectionFactory.java:57)  
  6.     at org.springframework.data.redis.core.RedisConnectionUtils.doGetConnection(RedisConnectionUtils.java:128)  
  7.     at org.springframework.data.redis.core.RedisConnectionUtils.getConnection(RedisConnectionUtils.java:91)  
  8.     at org.springframework.data.redis.core.RedisConnectionUtils.getConnection(RedisConnectionUtils.java:78)  
  9.     at org.springframework.data.redis.core.RedisTemplate.execute(RedisTemplate.java:177)  
  10.     at org.springframework.data.redis.core.RedisTemplate.execute(RedisTemplate.java:152)  
  11.     at org.springframework.data.redis.core.AbstractOperations.execute(AbstractOperations.java:85)  
  12.     at org.springframework.data.redis.core.DefaultHashOperations.get(DefaultHashOperations.java:48) 

找到源头第一次出现500地方,

(编辑:济南站长网)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

热点阅读