java-Using Arthas full link statistics method call chain and execution time consumption
environment
- Springboot v1.5.6.RELEASE
- arthas 3.6.2
introduction
After benchmarking the method using the JMH framework, it was found that the execution effect was not satisfactory. Since there are many business functions called by the top-level method,
it is difficult to locate the points that need to be optimized. I don't know which method has performance overhead. If I want to optimize it, I can't start without data support.
There is an urgent need for a full-link statistical method call chain and execution time-consuming tool. The trace command in the Arthas (Alsace) monitoring and diagnosis product perfectly solved my problem.
And Arthas is non-intrusive and will not pollute your business code.
document
Troubleshooting process
Run the Springboot application
It can be deployed locally, debugged, or deployed on the server. Just run Arthas on the same host machine.
Here we use the application run by bebug.
Run Arthas
Arthas needs to be started separately.
cd xxx/arthas-boot.jar --定位到jar目录
java -jar arthas-boot.jar --启动
After starting, it will print all the processes that java has started, select the serial number of the application to be monitored and press Enter;
[INFO] arthas-boot version: 3.6.2
[INFO] Process 2672 already using port 3658
[INFO] Process 2672 already using port 8563
[INFO] Found existing java process, please choose one and input the serial number of the process, eg : 1. Then hit ENTER.
* [1]: 2672 xxx.StartApplication
[2]: 17056 xxx
[3]: 19232 xxx
Execute the trace command
After selecting the application, it will be attached to the process, and the test will execute the trace command, and attach it to the class and method we need to track for statistics; syntax:
trace class name method name
trace uses wildcard matching by default, such as: monitor all under testController The method
trace com.controller.testController
listens to all methods under the com.controller package
trace com.controller. *
Note: The more methods of trace monitoring, the greater the performance overhead
[arthas@2672]$ trace com.controller.* * --trace命令
Press Q or Ctrl+C to abort.
Affect(class count: 2 , method count: 4) cost in 66 ms, listenerId: 6 -- 监听到2个类的4个方法
`---ts=2023-03-21 15:11:21;thread_name=http-nio-8080-exec-10;id=73;is_daemon=true;priority=5;TCCL=org.springframework.boot.context.embedded.tomcat.TomcatEmbeddedWebappClassLoader@3d67f2e
`---[151.9948ms] xxx.test.getXxx()
`---[99.96% 151.9402ms ] org.springframework.cglib.proxy.MethodInterceptor:intercept()
`---[99.96% 151.8739ms ] xxx.test.getXxx()
+---[74.63% 113.3481ms ] xxx.test.getXxx() #143
| `---[99.99% 113.3338ms ] xxx.test.getXxx()
| +---[76.14% 86.2936ms ] xxx.test.getXxx() #86
| | `---[99.98% 86.273ms ] xxx.test.getXxx()
| | `---[99.97% 86.246ms ] xxx.test.getXxx() #82
| +---[0.01% 0.0127ms ] xxx.test.getXxx() #88
| +---[0.01% 0.0082ms ] xxx.test.getXxx() #88
| `---[22.13% 25.0795ms ] xxx.test.getXxx() #91
| `---[32.16% 8.0653ms ] xxx.test.getXxx()
| `---[99.87% 8.0552ms ] xxx.test.getXxx() #93
| `---[99.82% 8.0408ms ] xxx.test.getXxx()
| +---[0.36% 0.0292ms ] xxx.test.getXxx() #99
| +---[2.47% 0.1985ms ] xxx.test.getXxx() #100
| +---[0.19% 0.0155ms ] xxx.test.getXxx() #106
| +---[0.11% 0.0092ms ] xxx.test.getXxx() #112
| +---[0.19% 0.0155ms ] xxx.test.getXxx() #113
| +---[0.16% 0.0132ms ] xxx.test.getXxx() #115
| +---[94.97% 7.636ms ] xxx.test.getXxx() #117
| `---[0.23% 0.0187ms ] org.apache.commons.collections.CollectionUtils:isNotEmpty() #118
+---[0.01% 0.011ms ] xxx.test.getXxx() #144
+---[11.69% 17.7584ms ] xxx.test.getXxx() #144
+---[0.01% 0.0127ms ] xxx.test.getXxx() #145
+---[13.57% 20.6134ms ] xxx.test.getXxx() #145
+---[0.01% min=0.0038ms,max=0.0107ms,total=0.0145ms,count=2] xxx.test.getXxx() #147
+---[0.01% 0.0077ms ] xxx.test.getXxx() #147
+---[0.00% 0.0049ms ] xxx.test.getXxx() #147
`---[0.01% 0.0142ms ] xxx.test.getXxx() #147
Summarize
Arthas monitoring and diagnosis products have many functions, which can help us to diagnose problems online without interruption. Using jmh with Arthas can perform basic tests such as throughput and average execution time and performance monitoring and analysis, helping developers scientifically locate performance bottlenecks and optimization points.