Spring boot 集成Redis客户端Lettuce,导致服务线程数不断增加

概述

最近在部署web 项目时突然发现项目服务停止,经过排查得知服务启动后线程数在不断增加,从而导致集群资源不够,服务停止。

环境

Spring boot:2.1.6
Redis:4.0.8
jdk:1.8

<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-redis</artifactId>
<version>2.1.5.RELEASE</version>

原因排查

  1. 服务启动后观察查看线程数
pstree -p pid|wc -l
  1. 发现线程数一直再增加,此时查看该进程的堆栈信息
jstack pid|tee -a /opt/1-3.log 
  • 堆栈信息
"lettuce-epollEventLoop-4-3" #509 daemon prio=5 os_prio=0 tid=0x00007f2b6c011000 nid=0x1cde runnable [0x00007f2e86aeb000]
   java.lang.Thread.State: RUNNABLE
	at io.netty.channel.epoll.Native.epollWait0(Native Method)
	at io.netty.channel.epoll.Native.epollWait(Native.java:114)
	at io.netty.channel.epoll.EpollEventLoop.epollWait(EpollEventLoop.java:256)
	at io.netty.channel.epoll.EpollEventLoop.run(EpollEventLoop.java:281)
	at io.netty.util.concurrent.SingleThreadEventExecutor$5.run(SingleThreadEventExecutor.java:906)
	at io.netty.util.internal.ThreadExecutorMap$2.run(ThreadExecutorMap.java:74)
	at io.netty.util.concurrent.FastThreadLocalRunnable.run(FastThreadLocalRunnable.java:30)
	at java.lang.Thread.run(Thread.java:748)

"lettuce-timer-3-1" #29 prio=5 os_prio=0 tid=0x00007f2e7804e800 nid=0x1cdd waiting on condition [0x00007f2e86ced000]
   java.lang.Thread.State: TIMED_WAITING (sleeping)
	at java.lang.Thread.sleep(Native Method)
	at io.netty.util.HashedWheelTimer$Worker.waitForNextTick(HashedWheelTimer.java:579)
	at io.netty.util.HashedWheelTimer$Worker.run(HashedWheelTimer.java:478)
	at io.netty.util.concurrent.FastThreadLocalRunnable.run(FastThreadLocalRunnable.java:30)
	at java.lang.Thread.run(Thread.java:748)

从堆栈信息中我们可以看出出现了很多lettuce线程,此时差不多应该定位到了应该是spring boot集成redis出现的问题了。
当时为了解决问题发布上线进行了如下配置:

#连接池中的最大空闲连接
#spring.redis.lettuce.pool.max-idle=5
#连接池最大连接数
#spring.redis.lettuce.pool.max-active=8
#连接池中的最小空闲连接
#spring.redis.lettuce.pool.min-idle=1

并且服务重启,线程数不会增加。

虽然问题解决但是但是但是,坑的地方也在在此。本质并没有找到。。。

后面服务正常后把配置注释,线程数也不会增加了。说明并不是因为配置了lettuce.pool相关信息解决问题。
目前还没有还原当时的场景 。

评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值