首页 技术 正文
技术 2022年11月16日
0 收藏 663 点赞 2,735 浏览 2074 个字

记一次使用arthas排查jvm中CPU占用过高问题。这工具屌爆了 碾压我目前使用的全部JVM工具。

安装 小试

curl -O https://arthas.aliyun.com/arthas-boot.jar
java -jar arthas-boot.jar --repo-mirror aliyun --use-http

jar后面的参数也可以不加 加上只是为了下载速度更快

接下来arthas 控制台中显示了当前机器上jvm进程列表 输入需要排查的jvm进程号即可进入监控命令模式

找出CPU的元凶

处理问题之前 先想想如何去找到问题的原因 这个是解决问题个人觉得最重要的一步。

当前的现状是jvm启动后 cpu直接飙升到80+%。而内存是正常的,可以认为大概率是某个线程占用了计算资源 导致的。所以第一步需要先把占用过高线程给揪出来。

这次使用arthas排查。也顺便提一下以前记录过用top -Hp的方法找出占用资源的线程PID 方法 top -Hp方法参考

输入命令 thread 查看所有线程信息 默认是按照cpu资源占用排名的

可以看到当前线程lettuce-nioEventLoop-4-1 占用cpu高达47.75。其实这个线程名称已经能定位到具体某个方向的问题了,所以线程名称的定义需要有意义 为了方便排查问题。

可以看出因为我们程序使用了lettuce做redis的客户端,主要是使用了redis stream

StreamMessageListenerContainer.StreamMessageListenerContainerOptions<String, ObjectRecord<String, String>> containerOptions =
StreamMessageListenerContainer.StreamMessageListenerContainerOptions.builder()
.batchSize(10) // 一次性最多拉取多少条消息
.targetType(String.class) // 目标类型。统一使用 String
.executor(mqConsumerExecutor)
.pollTimeout(Duration.ZERO)//0不超时
.build();

.pollTimeout(Duration.ZERO)这一句改为 .pollTimeout(Duration.ofMillis(10))cpu就正常了。原因就是设置了永不超时 资源得不到释放。改为指定时间超时后 程序一点问题都没有了。

查看线程栈的参数

可以直接使用thread pid 上图占用最高的id为22 则输入 thread 22 能看到类似jstack的功能

"lettuce-nioEventLoop-4-1" Id=22 RUNNABLE
at sun.nio.ch.EPollArrayWrapper.epollWait(Native Method)
at sun.nio.ch.EPollArrayWrapper.poll(EPollArrayWrapper.java:269)
at sun.nio.ch.EPollSelectorImpl.doSelect(EPollSelectorImpl.java:93)
at sun.nio.ch.SelectorImpl.lockAndDoSelect(SelectorImpl.java:86)
at sun.nio.ch.SelectorImpl.select(SelectorImpl.java:97)
at sun.nio.ch.SelectorImpl.select(SelectorImpl.java:101)

还有一个更好用的命令 -n参数能显示top-n-threads 比上面一种更详细

"lettuce-nioEventLoop-4-1" Id=22 cpuUsage=49.51% deltaTime=99ms time=392976ms RUNNABLE
at sun.nio.ch.EPollArrayWrapper.epollWait(Native Method)
at sun.nio.ch.EPollArrayWrapper.poll(EPollArrayWrapper.java:269)
at sun.nio.ch.EPollSelectorImpl.doSelect(EPollSelectorImpl.java:93)
at sun.nio.ch.SelectorImpl.lockAndDoSelect(SelectorImpl.java:86)
at sun.nio.ch.SelectorImpl.select(SelectorImpl.java:97)
at sun.nio.ch.SelectorImpl.select(SelectorImpl.java:101)

可以看出使用arthas排除这类问题 比使用top -Hp方便太多。当然这只是它的一个小功能而已。

原文 https://peachyy.gitee.io/2022/08/31/jvm_cpu_arthas_check/

公众号

相关推荐
python开发_常用的python模块及安装方法
adodb:我们领导推荐的数据库连接组件bsddb3:BerkeleyDB的连接组件Cheetah-1.0:我比较喜欢这个版本的cheeta…
日期:2022-11-24 点赞:878 阅读:8,910
Educational Codeforces Round 11 C. Hard Process 二分
C. Hard Process题目连接:http://www.codeforces.com/contest/660/problem/CDes…
日期:2022-11-24 点赞:807 阅读:5,435
下载Ubuntn 17.04 内核源代码
zengkefu@server1:/usr/src$ uname -aLinux server1 4.10.0-19-generic #21…
日期:2022-11-24 点赞:569 阅读:6,250
可用Active Desktop Calendar V7.86 注册码序列号
可用Active Desktop Calendar V7.86 注册码序列号Name: www.greendown.cn Code: &nb…
日期:2022-11-24 点赞:733 阅读:6,061
Android调用系统相机、自定义相机、处理大图片
Android调用系统相机和自定义相机实例本博文主要是介绍了android上使用相机进行拍照并显示的两种方式,并且由于涉及到要把拍到的照片显…
日期:2022-11-24 点赞:512 阅读:7,693
Struts的使用
一、Struts2的获取  Struts的官方网站为:http://struts.apache.org/  下载完Struts2的jar包,…
日期:2022-11-24 点赞:671 阅读:4,731