zoukankan      html  css  js  c++  java
  • Cpu飚高show-busy-java-threads一件脚本排查与Arthas线上诊断工具排查实战

    spring boot 模拟飚高代码

    @Service
    public class TestWhile
    {
        /* 操作内存对象 */
        ConcurrentHashMap map = new ConcurrentHashMap();
        private void whileTrue(String threadName) {
            // 不设置退出条件,死循环
            while (true) {
                // 在死循环中不断的对map执行put操作,导致内存gc
                for (int i = 0; i <= 100000; i++) {
                    map.put(Thread.currentThread().getName() + i, i);
                } // end for
            }// end while
        }
        @PostConstruct
        public void testWhile() {
            // 循环size,创建多线程,并发执行死循环
            for (int i = 0; i < 20; i++) {
                int finalI = i;
                // 新建并启动线程,调用whileTrue方法
                new Thread(() -> {
                    whileTrue("李文-" + finalI);
                }).start();
            }
        }
    }

    top

    1577416718696-696.png

     

    使用  淘宝开源  show-busy-java-threads  快速排查

    1.  介绍:
      1. 作者 :淘宝 李鼎(哲良) oldratlee
      2. 用于快速排查Java的CPU性能问题(top us值过高),自动查出运行的Java进程中消耗CPU多的线程,并打印出其线程栈,从而确定导致性能问题的方法调用。
      3.  Git地址:https://github.com/oldratlee/useful-scripts

     执行:  curl -sLk 'https://raw.github.com/oldratlee/useful-scripts/release-2.x/bin/show-busy-java-threads' | bash -s -- -a 2.log  

     输出到 2.log 文件。

    1577416959477-763.png

    结果:GC引起的CPU 飚高, 【5】 引起GC的线程与执行代码方法。 可以定位到 whileTrue 方法有问题。

     

    使用 淘宝开源 Arthas 排查问题

    1. 介绍: Arthas 是Alibaba开源的Java诊断工具 ,业界最强。
    2. GIT地址 : https://github.com/alibaba/arthas/blob/master/README_CN.md
    3. 不光是CPU线程问题排查,几乎可以包括所有问题的排查,在线反编译,动态热更新运行中的代码,在线请求链路跟踪等等功能。
    curl -O https://alibaba.github.io/arthas/arthas-boot.jar
    java -jar arthas-boot.jar

    选择需要排查的那个进程

    1  + Enter

    执行 dashboard  命令

    1577417445506-590.png

    初步可以判断为GC引发的CPU飚高

     

    执行  thread -n 3 -i 5000  查看CPU使用率Top N线程的栈

    1577417597516-899.png

    结果: GC引起的CPU 飚高, 可以定位到线程运行链接方法 whileTrue  有问题。

    推荐在服务出现问题, 执行以下  c  curl -sLk 'https://raw.github.com/oldratlee/useful-scripts/release-2.x/bin/show-busy-java-threads' | bash -s -- -a 2.log    然后在重启,这样重启后也会有写问题记录

  • 相关阅读:
    CSU 1333 Funny Car Racing
    FZU 2195 检查站点
    FZU 2193 So Hard
    ZOJ 1655 FZU 1125 Transport Goods
    zoj 2750 Idiomatic Phrases Game
    hdu 1874 畅通工程续
    hdu 2489 Minimal Ratio Tree
    hdu 3398 String
    洛谷 P2158 [SDOI2008]仪仗队 解题报告
    POJ 1958 Strange Towers of Hanoi 解题报告
  • 原文地址:https://www.cnblogs.com/atliwen/p/12106503.html
Copyright © 2011-2022 走看看