当前位置:网站首页>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 ;

 Insert picture description here

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

 Insert picture description here

 Insert picture description here

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 ;

 Insert picture description here

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 ;

 Insert picture description here

dashboard command

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

 Insert picture description here

jvm command

Enter this command to see the current jvm Details of ;

 Insert picture description here

thread command

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

 Insert picture description here

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 :

 Insert picture description here

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 ;

 Insert picture description here

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 ;

 Insert picture description here

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 .

 Insert picture description here

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
 Insert picture description here
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
 Insert picture description here
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
 Insert picture description here
2. Also call... In the interface where the user is added test() Method
 Insert picture description here
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 :
 Insert picture description here
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% .
 Insert picture description here
6. Print out threads ID by 308 Details of , You can see the specific code location and number of lines that caused the problem .
 Insert picture description here

原网站

版权声明
本文为[Small y online coding]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/162/202206111504119121.html