港Strive 2022-07-12 00:02 采纳率: 0%
浏览 787

Redisson-Netty导致服务器cpu飙高。

  1. 问题遇到的现象和发生背景
    最近选用Redisson来处理分布式锁的问题,测试环境运行项目后,java 进程Cpu会有规律性的起伏飙高。

  2. 相关版本与配置如下
    测试服务内存大小:512m
    redisson版本:3.17.1
    redis版本:3.2.1
    redisson配置如下:

     @Bean
     public RedissonClient redissonClient() {
         Config config = new Config();
         config.setLockWatchdogTimeout(15000)
                 .setThreads(4)
                 .setNettyThreads(4)
                 .useSingleServer()
                 .setAddress("redis://" + host + ":" + port)
                 .setPassword(password)
                 .setDatabase(1);
         return Redisson.create(config);
     }
    
  3. 运行结果及报错内容
    使用arthas监控发现 main线程组中 有个ConbainerBackgroud的守护线程导致cpu过高,时间在7-8秒会循环一次。

img

进一步使用 thread -n tid 查看堆栈信息。发现循环输出以下内容。

"redisson-netty-2-3" Id=428 cpuUsage=0.0% deltaTime=0ms time=62ms RUNNABLE (in native)
    at sun.nio.ch.WindowsSelectorImpl$SubSelector.poll0(Native Method)
    at sun.nio.ch.WindowsSelectorImpl$SubSelector.poll(Unknown Source)
    at sun.nio.ch.WindowsSelectorImpl$SubSelector.access$400(Unknown Source)
    at sun.nio.ch.WindowsSelectorImpl.doSelect(Unknown Source)
    at sun.nio.ch.SelectorImpl.lockAndDoSelect(Unknown Source)
    at sun.nio.ch.SelectorImpl.select(Unknown Source)
    at sun.nio.ch.SelectorImpl.select(Unknown Source)
    at io.netty.channel.nio.SelectedSelectionKeySetSelector.select(SelectedSelectionKeySetSelector.java:68)
    at io.netty.channel.nio.NioEventLoop.select(NioEventLoop.java:803)
    at io.netty.channel.nio.NioEventLoop.run(NioEventLoop.java:457)
    at io.netty.util.concurrent.SingleThreadEventExecutor$4.run(SingleThreadEventExecutor.java:989)
    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(Unknown Source)

"redisson-netty-2-4" Id=429 cpuUsage=0.0% deltaTime=0ms time=62ms RUNNABLE (in native)
    at sun.nio.ch.WindowsSelectorImpl$SubSelector.poll0(Native Method)
    at sun.nio.ch.WindowsSelectorImpl$SubSelector.poll(Unknown Source)
    at sun.nio.ch.WindowsSelectorImpl$SubSelector.access$400(Unknown Source)
    at sun.nio.ch.WindowsSelectorImpl.doSelect(Unknown Source)
    at sun.nio.ch.SelectorImpl.lockAndDoSelect(Unknown Source)
    at sun.nio.ch.SelectorImpl.select(Unknown Source)
    at sun.nio.ch.SelectorImpl.select(Unknown Source)
    at io.netty.channel.nio.SelectedSelectionKeySetSelector.select(SelectedSelectionKeySetSelector.java:68)
    at io.netty.channel.nio.NioEventLoop.select(NioEventLoop.java:803)
    at io.netty.channel.nio.NioEventLoop.run(NioEventLoop.java:457)
    at io.netty.util.concurrent.SingleThreadEventExecutor$4.run(SingleThreadEventExecutor.java:989)
    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(Unknown Source)

"redisson-timer-4-1" Id=425 cpuUsage=0.0% deltaTime=0ms time=0ms TIMED_WAITING
    at java.lang.Thread.sleep(Native Method)
    at io.netty.util.HashedWheelTimer$Worker.waitForNextTick(HashedWheelTimer.java:569)
    at io.netty.util.HashedWheelTimer$Worker.run(HashedWheelTimer.java:465)
    at io.netty.util.concurrent.FastThreadLocalRunnable.run(FastThreadLocalRunnable.java:30)
    at java.lang.Thread.run(Unknown Source)

4.我的解答思路和尝试过的方法
起初怀疑是默认线程问题,后续将线程改为4依旧存在Cpu飙高情况。
后续网上Google堆栈信息无果。是否与Netty实现有关。

5.我想要达到的结果
降低cpu占有率,并且想明白输出的堆栈信息是否为正常现象,望各位指点一二。

  • 写回答

2条回答 默认 最新

  • Juwell16 2022-07-12 09:25
    关注

    使用Redssion和netty没毛病,问题肯定是出在你的代码中,我猜那个守护线程应该是垃圾回收线程,高并发的话,你可以把容器换了,垃圾回收机制也换一下

    评论

报告相同问题?

问题事件

  • 创建了问题 7月12日

悬赏问题

  • ¥200 解决登录微信老版本限制封号问题
  • ¥15 mysql中时间处理问题
  • ¥20 讲解此音频放大电路原理及关键部分
  • ¥15 rtsp 转 m3u8 执行后卡在Decoding VUI
  • ¥20 微信小程序转发链接问题,已禁止转发仍能转发的场景
  • ¥15 关于#硬件架构#的问题:根据开片的IC来判断是哪一款
  • ¥15 matlab simulink
  • ¥15 rtos搭建sip协议开发包
  • ¥100 TM4C1290NCPDT 在线调试
  • ¥15 window系统获取某进程打开的文件路径