日本免费高清视频-国产福利视频导航-黄色在线播放国产-天天操天天操天天操天天操|www.shdianci.com

學(xué)無(wú)先后,達(dá)者為師

網(wǎng)站首頁(yè) 編程語(yǔ)言 正文

Spring boot 集成Redis客戶端Lettuce,導(dǎo)致服務(wù)線程數(shù)不斷增加

作者:爆發(fā)的~小宇宙 更新時(shí)間: 2022-05-17 編程語(yǔ)言

概述

最近在部署web 項(xiàng)目時(shí)突然發(fā)現(xiàn)項(xiàng)目服務(wù)停止,經(jīng)過排查得知服務(wù)啟動(dòng)后線程數(shù)在不斷增加,從而導(dǎo)致集群資源不夠,服務(wù)停止。

環(huán)境

Spring boot:2.1.6
Redis:4.0.8
jdk:1.8

<groupId>org.springframework.bootgroupId>
<artifactId>spring-boot-starter-data-redisartifactId>
<version>2.1.5.RELEASEversion>

原因排查

  1. 服務(wù)啟動(dòng)后觀察查看線程數(shù)
pstree -p pid|wc -l
  1. 發(fā)現(xiàn)線程數(shù)一直再增加,此時(shí)查看該進(jìn)程的堆棧信息
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)

從堆棧信息中我們可以看出出現(xiàn)了很多l(xiāng)ettuce線程,此時(shí)差不多應(yīng)該定位到了應(yīng)該是spring boot集成redis出現(xiàn)的問題了。
當(dāng)時(shí)為了解決問題發(fā)布上線進(jìn)行了如下配置:

#連接池中的最大空閑連接
#spring.redis.lettuce.pool.max-idle=5
#連接池最大連接數(shù)
#spring.redis.lettuce.pool.max-active=8
#連接池中的最小空閑連接
#spring.redis.lettuce.pool.min-idle=1

并且服務(wù)重啟,線程數(shù)不會(huì)增加。

雖然問題解決但是但是但是,坑的地方也在在此。本質(zhì)并沒有找到。。。

后面服務(wù)正常后把配置注釋,線程數(shù)也不會(huì)增加了。說(shuō)明并不是因?yàn)榕渲昧薼ettuce.pool相關(guān)信息解決問題。
目前還沒有還原當(dāng)時(shí)的場(chǎng)景 。

原文鏈接:https://blog.csdn.net/yu0_zhang0/article/details/103863447

欄目分類
最近更新