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

线上资源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…..

评论

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注

这个站点使用 Akismet 来减少垃圾评论。了解你的评论数据如何被处理