arthas 火焰图(async-profiler)在云交易中的运用

在日常工作中经常会遇到系统应用出现 full gc、cpu 内存飙高等场景,如果想要快速解决这些线上问题就需要首先能快速定位,最好能定位到具体代码。本文旨在通过一款线上监控诊断产品,阿里巴巴的 arthas(阿尔萨斯)内部集成的火焰图工具 async-profiler 结合自身系统应用中的使用,方便我们能够快速定位线上问题。
一、背景
1、在订单域任务系统,master 机器和 slaver 机器频繁出现 full gc 和 cpu 间歇性升高的现象,young GC 也出现平均 1 分钟 10 次。master 机器线程也增加到 1500 左右。系统应用采用的是 CMS 垃圾回收器,4c8g 分配堆内存大小 4G。但是堆内存和非堆内存正常。
2、随着时间推移,full gc 从每隔 20 分钟一次变成 每个 5 分钟或者 3 分钟一次,stop the world。FULL GC 和 Young GC 不正常,如下图。


堆内存和非堆内存正常。

CPU 一分钟一次达到高点,部分机器达到 75%以上。线程,在上午超过 1400,重启后正常。


系统稳定性受到挑战,需要尽快排查出问题所在。
二、工具选型及实践
市面上很多排查工具,怎样才能快速排查出问题。结合 arthas、async-profiler 火焰图(采样)、visualVM(跨时间 dump 文件对比)、gceasy 这四种工具,都进行实战对比。
1、arthas 分析
下图分析 master 机器是反序列化商品域渠道配置接口对象耗 CPU

下图也发现反查快手任务也会引起高 cpu。分析这台机器既是 master,又是 slaver。slaver 会执行反查快手任务。

2、visualVM 分析
dump 两个文件,跨时一天,进行对比。
启动 visualVM
cd /Library/Java/JavaVirtualMachines/jdk1.8.0_191.jdk/Contents/Home/bin
jvisualvm
/Library/Java/JavaVirtualMachines/jdk1.8.0_191.jdk/Contents/Home/lib/visualvm 目录下 visualvm.conf 修改内存空间大小

对比发现,最大是查询 ES 的数据,反序列化对象并不是最大,但是也能在 dump 文件中查找到。因为 arthas 查的是 CPU 和线程,dump 文件是内存,所以不完全一致。

一次 500 个

3、gceasy 分析
修改 jvm,-XX:+PrintGCDetails -XX:+PrintGCTimeStamps -Xloggc:./gc.log,打印 gc 日志。
通过gceasy.io线上对比工具,没有内存泄露,但是也未发现 gc 产生的具体原因。

4、async-profiler 火焰图

从上图,看到主要分为两大部分,左边的反查快手任务(因 master 机器,既是 master,也是 slaver),右边是扫描 es 里面代扣任务的反序列化对象占用很大比重。和 arthas 分析的一样。
下载内存火焰图, 可以看到左边也是快手反查,右边则是查询 ES(包含反序列化对象)。和 dump 文件比较能核对上。

三、修复上线
根据上述四种工具的排查过程,可以明显看到使用 arthas 集成的 async-profiler 更直观和方便,便于定位问题。在修改对应的代码后,上线进行后续观察系统稳定正常。

四、使用步骤
async-profiler 火焰图。
1、申请堡垒机(root 权限)
2、登陆以后下载 最新的 jar 包 wget https://alibaba.github.io/arthas/arthas-boot.jar
3、安装(admin 权限 cd)java -jar arthas-boot.jar
4、查看 cpu 耗时、dashboard(q 命令表示退出)、thread
5、profiler start 启动火焰图工具进行采样

profiler getSamples
profiler status
profiler stop --format html。生成火焰图
6、下载火焰图

7、多种维度:
lock 锁对象\alloc 内存\默认 cpu

8、效果


CPU\内存等不同的火焰图
9、其他
还可以反编译 jar 包的代码

统计方法调用时间

以上。本文旨在通过具体的场景运用和实操,介绍 arthas 火焰图如何在系统中快速定位问题,欢迎感兴趣的同事一起学习探讨。
作者:交易研发 郭森
来源:京东零售技术 转载请注明来源
版权声明: 本文为 InfoQ 作者【京东零售技术】的原创文章。
原文链接:【http://xie.infoq.cn/article/517dbcd2eee06ece37266abcc】。文章转载请联系作者。
评论