关于springboot:排查线上CPU飙升原因

3次阅读

共计 696 个字符,预计需要花费 2 分钟才能阅读完成。

线上资源 cpu 飙升是咱们工作中常见的问题,一篇文章搞定排查办法

一、问题复现

  • 当初我有两个接口,代码如下

    @RestController
    public class CPUCheck {@RequestMapping("/hello")
      public String helloWorld(){return "hello World";}
    
      @RequestMapping("/run")
      public void run(){while (true){}}
    }
  • 代码很简略 接口 1“/hello”返回“hello World”,接口 2“/run”进入死循环,这样就保障了拜访接口 2cpu 升高。

    二、测试

  • 咱们将我的项目打包部署在服务器上,并启动
  • 测试接口

    curl http://localhost:9901/thing-test/hello
  • 测试接口 2,并查看 cpu 状况

    curl http://localhost:9901/thing-test/run
  • 三、排查

  • 通过 top 命令能够查看到有一个 java 过程占用 cpu 资源异样
  • 获取 pid 为32306
  • 通过命令查问tid

    命令:ps -mp【pid】-o THREAD,tid,time
    实例:ps -mp 32306 -o THREAD,tid,time
  • 能够看到引起 cpu 异样的 tid 是32327
  • 因为当初的 tid32327是十进制的,须要将其转化为十六进制

    命令:printf "%x\n"【十进制 tid】实例:printf "%x\n" 32327
  • 依据 pid 和 tid 查问导致 cpu 飙升的代码

    命令:jstack【10 进制 pid】| grep【16 进制 tid】-A 20
    实例:jstack 32306 | grep 7e47 -A 20

END…..

正文完
 0