当前位置:网站首页>Arthas practice documentation
Arthas practice documentation
2022-06-11 15:13:00 【Small y online coding】
Arthas Documentation of practical operations
The first 1 Chapter Arthas Brief introduction
1.1 Arthas What is it?
arthas Alibaba open source Java Diagnostic tools , The basic usage scenario is to locate and reproduce some problems that are difficult to locate in the production environment . You can check problems online , And dynamic tracking Java Code , Real-time monitoring JVM Status and so on , Official website address :https://arthas.aliyun.com/doc/.
1.2 Arthas Can do
A class from that jar Package loaded ? Why are all kinds of exceptions reported ? ( You can get the loading path and exception information of the specified class through the command )
The modified code is not implemented to ? It's not commit It's the wrong branch or something ?( You can get the code information of the class through decompiling )
I can't get online when I have a problem debug, Can't we just add logs and redistribute them ?( Can pass jdk 1.5 Of instrument To dynamically replace the code )
There is a problem with the data processing of a user online , But online also can't debug, It can't be reproduced offline !(arthas You can see a very detailed jvm Status and some convenient tools , Like decompiling , Online debugging, etc )
Is there a global perspective to see the health of the system ?(dashboard Command view jvm Details of )
How to quickly locate the hot spot of application , Generate flame chart ?
How to directly from JVM Find an instance of a class in ?
1.3 Arthas Supported versions
Support JDK 6+ Support Linux/Mac/Windows
The first 2 Chapter Arthas Use
2.1Arthas Installation (windows)
There are many ways to download and install , Here is a manual installation method .
Download the installation package manually :https://arthas.aliyun.com/download/latest_version?mirror=aliyun;
Linux Please refer to the official website for the installation and use of :https://arthas.aliyun.com/doc/install-detail.html#
2.2Arthas Use
Download the installation package and unzip it cmd Access control , Then enter the unzipped file directory ;

Enter the command :.\as.bat pid( Viewing program pid have access to java Self contained java VisualVM Visualization tools )


Select the... To be monitored and analyzed java process , Successful startup Arthas after , Will see Arthas The interface of , You can also directly access the corresponding port through the browser ;

Get into Arthas You can input the corresponding commands in this interface to analyze the program ;
2.3Arthas Basic command introduction and actual use
Be careful : If you don't remember the order , have access to idea plug-in unit arthas idea Generate arthas Relevant command ;

dashboard command
Enter this command to view the real-time data panel of the current system ;

jvm command
Enter this command to see the current jvm Details of ;

thread command
Enter this command to view the stack details of the thread ;

trace command
trace Command can actively search the method call path , And output the time consumption of each node on the method path , Render and count all performance overhead and trace call links on the entire call link .
Examples of use :
Now listen SysUserController Under class user() Method call chain :

Enter the command :
trace com.pig4cloud.pigx.admin.controller.SysUserController user -n 5 --skipJDKMethod false
Be careful :trace The following is the full path of classes and methods ;
Call the method , Then you can see in arthas The interface outputs the call chain of the method and the time consumption of each method on the link , This method can be used to find time-consuming methods for targeted optimization ;

watch command
watch Command allows users to easily observe the call of the specified method . The range that can be observed is : Return value 、 Throw an exception 、 Enter the reference , By writing OGNL Expression to view the corresponding variable .
Examples of use : Observe SysUserController Under class user() Method ;

The first 3 Chapter profiler Generate flame chart ( Support only Linux/Mac)
profiler The command supports the generation of flame diagrams of application hotspots . Essentially through continuous sampling , Then the collected sampling results are generated into a flame diagram , It can be used to quickly troubleshoot online performance problems .
The flame diagram is based on perf The result is SVG picture , Used to display CPU Call stack .

y Axis represents call stack , Each layer is a function . The deeper the call stack , The higher the flame , At the top is the function being executed , Below are all its parent functions .
x The axis represents the number of samples , If a function is in x The wider the width occupied by the axis , It means it's drawn more times , That is, the execution time is long . Be careful ,x The axis does not represent time , But after all call stacks are merged , In alphabetical order .
The flame graph is to see which function of the top layer occupies the largest width . As long as there is " flat roof "(plateaus), It means that the function may have performance problems .
Color has no special meaning , Because the flame graph shows CPU How busy , So the general choice of warm colors .
Interval length . Be careful ,x The axis does not represent time , But after all call stacks are merged , In alphabetical order .
The flame graph is to see which function of the top layer occupies the largest width . As long as there is " flat roof "(plateaus), It means that the function may have performance problems .
Color has no special meaning , Because the flame graph shows CPU How busy , So the general choice of warm colors .
Please refer to the official website for specific use :https://arthas.gitee.io/profiler.html
The first 4 Chapter Actual problem simulation
4.1 Performance problem simulation
1. First, write a long-running loop :
private void test() {
int a = 1;
while (a < 9999999) {
a++;
System.out.println(out(a));
}
}
2. Call... In the method that adds the user test() Method 
3. Start the service , use arthas monitor user Method
trace com.pig4cloud.pigx.admin.controller.SysUserController user -n 5 --skipJDKMethod false
4. Call the interface for adding users , The interface responds successfully after a long time , You can see arthas The console outputs the call stack of this method 
You can see test() Methods take the longest .
4.2 cpu Simulation of soaring height problem
1. Transform the above program into an endless loop 
2. Also call... In the interface where the user is added test() Method 
3. Restart the service before starting arthas.
4. Enter... Before calling add user interface thread command , At this point, you can see that all threads are normal , Here's the picture :
5. Now call the interface to add the user , Input again thread command , You can see one of them id by 308 Threads of cause cpu Soaring to more than 90% .
6. Print out threads ID by 308 Details of , You can see the specific code location and number of lines that caused the problem .
边栏推荐
- Leetcode daily question - Search insertion position
- 19. 二叉搜索树的插入删除修剪
- Avenue to Jane | Comment concevoir un vit pour configurer l'auto - attraction est - il le plus raisonnable?
- 做自媒体剪辑真的能挣钱吗?
- Uniapp settings page Jump effect - navigateto switching effect - Global animationtype animation
- 19. 二叉搜索樹的插入删除修剪
- 大道至簡 | 設計 ViT 到底怎麼配置Self-Attention才是最合理的?
- MySQL用户权限总结【用户授权必会】
- 浅析分布式系统之体系结构-事务与隔离级别(多对象、多操作)下篇
- 深度剖析「圈组」关系系统设计 | 「圈组」技术系列文章
猜你喜欢

老虎国际季报图解:营收5263万美元 持续国际化布局

【SystemVerilog 之 过程块和方法】~ 域、always过程块、initial过程块、函数 function、任务 task、生命周期

深度剖析「圈組」關系系統設計 | 「圈組」技術系列文章

03 _ 事务隔离:为什么你改了我还看不见?

What is excess product power? Find the secret key of the second generation cs75plus in the year of the tiger

Summary of some classic embedded C interview questions

回溯法/解空间树 排列树

数据库优化

High number_ Chapter 6 infinite series__ Marklaurin series

3年亏损136亿,上市能救活威马吗?
随机推荐
06 _ 全局锁和表锁 :给表加个字段怎么有这么多阻碍?
The server prevents repeated payment of orders
做自媒体剪辑真的能挣钱吗?
Learnopongl notes (IV) - Advanced OpenGL II
高数_第6章无穷级数__马克劳林级数
Microservices - use of Nacos
Avenue to simplicity | how to configure self attention for vit is the most reasonable?
Database optimization
Qcustomplot 1.0.1 learning (3) - plotting quadratic functions
容易让单片机程序跑飞的原因
Backtracking / activity scheduling maximum compatible activities
See from the minute, carve on the details: Exploration of SVG generated vector format website icon (favicon)
Nomad application layout scheme 04 of hashicopy (scaling and updating a job)
2021 go developer survey
[mysql_11] addition, deletion and modification of data processing
浅析分布式系统之体系结构-事务与隔离级别(多对象、多操作)下篇
02 _ 日志系统:一条SQL更新语句是如何执行的?
C语言简易版webserver
深度解读:分布式系统韧性架构压舱石OpenChaos
【SystemVerilog 之 接口】~ Interface