调优神器-Arthas的安装与简单使用

其实由于Arthas是阿里开源的,中文文档写的非常好,所以也就不用搬了,直接看官方中文文档:

https://arthas.aliyun.com/doc/

一、Arthas的安装

1、安装非常简单,下载jar包后,java -jar 运行即可:

curl -O  
java -jar arthas-boot.jar

没有比这更简单的软件了!

2、运行后,交互输入我们需要监控的应用程序的编号即可(自动挂载):

[root@tcosmo-test-szls-baas01 ~]# java -jar arthas-boot.jar 
[INFO] arthas-boot version: 3.6.2
[INFO] Found existing java process, please choose one and input the serial number of the process, eg : 1. Then hit ENTER.
* [1]: 44919 thingsboard-3.3.1-boot.jar
1
[INFO] Start download arthas from remote server: https://arthas.aliyun.com/download/3.6.2?mirror=aliyun
[INFO] Download arthas success.
[INFO] arthas home: /root/.arthas/lib/3.6.2/arthas
[INFO] Try to attach process 44919
[INFO] Attach process 44919 success.
[INFO] arthas-client connect 127.0.0.1 3658
  ,---.  ,------. ,--------.,--.  ,--.  ,---.   ,---.                           
 /  O  \ |  .--. ''--.  .--'|  '--'  | /  O  \ '   .-'                          
|  .-.  ||  '--'.'   |  |   |  .--.  ||  .-.  |`.  `-.                          
|  | |  ||  |\  \    |  |   |  |  |  ||  | |  |.-'    |                         
`--' `--'`--' '--'   `--'   `--'  `--'`--' `--'`-----'                          

wiki       https://arthas.aliyun.com/doc                                        
tutorials  https://arthas.aliyun.com/doc/arthas-tutorials.html                  
version    3.6.2                                                                
main_class                                                                      
pid        44919                                                                
time       2021-06-21 14:27:26


二、简单使用(不断更新)

官方教程肯定是最全的,我这只列举我喜欢用的。

1、dashboard命令:整体看程序的运行情况:

image.png

2、如果某个线程异常(CPU过高,死锁等),直接使用:thread #线程号

[arthas@44919]$ thread 41
"transport-consumer-5-thread-1" Id=41 RUNNABLE (in native)
    at java.base@11.0.12/sun.nio.ch.EPoll.wait(Native Method)
    at java.base@11.0.12/sun.nio.ch.EPollSelectorImpl.doSelect(EPollSelectorImpl.java:120)
    at java.base@11.0.12/sun.nio.ch.SelectorImpl.lockAndDoSelect(SelectorImpl.java:124)
    at java.base@11.0.12/sun.nio.ch.SelectorImpl.select(SelectorImpl.java:136)
    at org.apache.kafka.common.network.Selector.select(Selector.java:869)
    at org.apache.kafka.common.network.Selector.poll(Selector.java:465)
    at org.apache.kafka.clients.NetworkClient.poll(NetworkClient.java:561)
    at org.apache.kafka.clients.consumer.internals.ConsumerNetworkClient.poll(ConsumerNetworkClient.java:265)
    at org.apache.kafka.clients.consumer.internals.ConsumerNetworkClient.poll(ConsumerNetworkClient.java:236)
    at org.apache.kafka.clients.consumer.KafkaConsumer.pollForFetches(KafkaConsumer.java:1296)
    at org.apache.kafka.clients.consumer.KafkaConsumer.poll(KafkaConsumer.java:1237)
    at org.apache.kafka.clients.consumer.KafkaConsumer.poll(KafkaConsumer.java:1210)
    at org.thingsboard.server.queue.kafka.TbKafkaConsumerTemplate.doPoll(TbKafkaConsumerTemplate.java:91)
    at org.thingsboard.server.queue.common.AbstractTbQueueConsumerTemplate.poll(AbstractTbQueueConsumerTemplate.java:101)
    at org.thingsboard.server.common.transport.service.DefaultTransportService.lambda$init$1(DefaultTransportService.java:216)
    at org.thingsboard.server.common.transport.service.DefaultTransportService$$Lambda$1160/0x0000000800bd7c40.run(Unknown Source)
    at java.base@11.0.12/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1128)
    at java.base@11.0.12/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:628)
    at java.base@11.0.12/java.lang.Thread.run(Thread.java:834)

3、反编译项目代码:jad 包名.类名

[arthas@44919]$ jad org.thingsboard.server.controller.TenantProfileController

ClassLoader:                                                                                                                                                                
+-org.springframework.boot.loader.LaunchedURLClassLoader@4c70fda8                                                                                                           
  +-jdk.internal.loader.ClassLoaders$AppClassLoader@4b85612c                                                                                                                
    +-jdk.internal.loader.ClassLoaders$PlatformClassLoader@197abec4                                                                                                         

Location:                                                                                                                                                                   
file:/tb/thingsboard-3.3.1-boot.jar!/BOOT-INF/classes!/                                                                                                                     

        package org.thingsboard.server.controller;
        
        import org.slf4j.Logger;
        import org.slf4j.LoggerFactory;
        import org.springframework.http.HttpStatus;
        import org.springframework.security.access.prepost.PreAuthorize;
        import org.springframework.web.bind.annotation.PathVariable;
        import org.springframework.web.bind.annotation.RequestBody;
        import org.springframework.web.bind.annotation.RequestMapping;
        import org.springframework.web.bind.annotation.RequestMethod;
        import org.springframework.web.bind.annotation.RequestParam;
        import org.springframework.web.bind.annotation.ResponseBody;
        import org.springframework.web.bind.annotation.ResponseStatus;

最新代码是否发布成功,一目了然,运维无法狡辩!

image.png

4、火焰图:用图形化的方式来展现profiler工具采集的性能数据:

对数据进行统计和分析,方便找出性能热点

[arthas@44919]$ profiler start
Profiling started

#燃烧个一两分钟差不多

[arthas@44919]$ profiler stop
OK
profiler output file: /tb/arthas-output/20220621-145221.html

image.png

jiguiquan@163.com

文章作者信息...

留下你的评论

*评论支持代码高亮<pre class="prettyprint linenums">代码</pre>

相关推荐