Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to use JFR to analyze performance in troubleshoot

2025-01-16 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >

Share

Shulou(Shulou.com)06/02 Report--

Troubleshoot how to use JFR to analyze performance, many novices are not very clear about this, in order to help you solve this problem, the following editor will explain for you in detail, people with this need can come to learn, I hope you can gain something.

GC performance event

Generally speaking, GC will have an important impact on the performance and operation of java programs. We can use jfr to monitor jdk.GCPhasePause events.

Here is an example of jdk.GCPhasePause:

Jfr print-events jdk.GCPhasePause flight_recording_1401comflydeanTestMemoryLeak89268.jfr

Output result:

Jdk.GCPhasePause {startTime = 19 duration 51 duration = 41.1 ms gcId = 2 name = "GC Pause"}

Through GCPhasePause events, we can count the total GC pause time and the average time per GC pause.

Generally speaking, GC is executed in the background, so we don't need to pay attention to the execution time of GC itself, because this does not affect the performance of the program. What we need to focus on is the time the application is paused because of GC.

Consider the following two situations where the first separate GC causes the GC pause time to be too long. The second is that the total GC pause time is too long.

If this is the first case, you may need to consider switching to a GC type, because different GC types will be handled differently directly in the balance of pause time and throughput. At the same time, we need to reduce finalizers use.

If it is the second case, we can solve it from the following aspects.

Increase the size of heap space. The larger the heap space, the longer the interval between GC. The shorter the total GC pause time will be.

Minimize the allocation of tmp objects. We know that JVM uses TLAB technology to improve the performance of multithreading. Generally speaking, small objects are allocated in TLAB, but if they are large objects, they are allocated directly in heap space. But most objects are allocated in TLAB. So we can focus on two events other than TLAB and TLAB: jdk.ObjectAllocationInNewTLAB and dk.ObjectAllocationOutsideTLAB.

Reduce the allocation frequency. We can analyze it through jdk.ThreadAllocationStatistics.

Synchronization performance

In a multithreaded environment, because multithreads compete for shared resources, the synchronization of resources, or the use of locks, will affect the performance of the program.

We can monitor jdk.JavaMonitorWait events.

Jfr print-events jdk.JavaMonitorWait flight_recording_1401comflydeanTestMemoryLeak89268.jfr

Let's look at one result:

Jdk.JavaMonitorWait {startTime = 19 0x7FFBB7007F08 eventThread 51 monitorClass 25.395 duration = 2 m 0 s monitorClass = java.util.TaskQueue (classLoader = bootstrap) notifier = N Band A timeout = 2 m 0 s timedOut = true address = 0x7FFBB7007F08 eventThread = "JFR Recording Scheduler" (javaThreadId = 17) stackTrace = [java.lang.Object.wait (long) java.util.TimerThread.mainLoop () line: 553 java.util.TimerThread.run () line: 506]}

By analyzing JavaMonitorWait events, we can find the most competitive locks for deeper analysis.

IO performance

If the application has a lot of IO operations, then IO operations are also a key part of the performance impact.

We can monitor two types of IO: socket IO and File IO.

The corresponding events are: dk.SocketWrite,jdk.SocketRead,jdk.FileWrite,jdk.FileRead.

Performance of code execution

The code is run through CPU, and if CPU is used too much, it may also affect the performance of the program.

We can analyze the CPULoad by listening for jdk.CPULoad events.

Jfr print-events jdk.CPULoad flight_recording_1401comflydeanTestMemoryLeak89268.jfr

Take a look at the running results:

Jdk.CPULoad {startTime = 19 machineTotal 53 jvmUser = 0.63% jvmSystem = 0.37% machineTotal = 20.54%}

If jvm uses less cpu, but the CPU utilization of the entire machine is relatively high, this indicates that other programs are taking up CPU.

If JVM's own CPU usage is high, then you need to find the thread that occupies CPU for further analysis.

Other useful event

In addition to the event mentioned above, there are some other useful event that we can follow.

For example, thread-related: jdk.ThreadStart,jdk.ThreadEnd,jdk.ThreadSleep,jdk.ThreadPark.

If you use JMC, you can visually view the various events of JFR.

Is it helpful for you to read the above content? If you want to know more about the relevant knowledge or read more related articles, please follow the industry information channel, thank you for your support.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Internet Technology

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report