2

生产系统CPU飙高问题排查 - 架构成长指南

 1 year ago
source link: https://www.cnblogs.com/waldron/p/16801111.html
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

生产系统CPU飙高问题排查

生产系统CPU占用过高,并且进行了报警

image-20221015112157560

执行top命令,查看是那个进程导致的,可以确定是pid为22168的java应用导致的

image-20221015112629314

执行top -Hp命令,查看这个进程的那个线程导致cpu过高,如下图,可以看到是22749线程导致的

top -Hp 22168

image-20221015112956811

由于jstack里面的线程号为16进制,需要转换线程号为16进制,如下图得到16进制值为58dd

printf "%x\n" 22749

image-20221015113705448

执行jstack生成线程快照保存至1.txt文件中,22168为进程id

jstack 22168>1.txt

根据16进制线程号,查询线程信息

grep 58dd 1.txt

image-20221015114338404

如上图,可以看到是调用DesenUtils.desen方法导致,此方法作用是数据脱敏,里面用了较为复杂的正则表达式,所以分析是由于特定字符正好遇到此正则表达式,进行大量计算导致,具体细节请访问(https://cloud.tencent.com/developer/article/1780881),为了快速解决此问题,先去除掉此代码的调用,重新发布即可。

线上问题定位,相对比较简单,难点主要在于保留现场,有了现场就能快速定位问题,以下是二种常用排查方式

  1. CPU飙高通过jstack命令,定位到线程信息。
  2. 内存飙高通过jmap dump出堆栈信息,在通过mat这些工具定位那个类占用过多内存。

About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK