“This is the sixth day of my participation in the Gwen Challenge.

The previous article covered memory leaks and memory spills in Java, followed by the next part of the JVM monitoring and diagnostic tool -GUI.

A, JProfiler

Basic overview

introduce

  1. When running Java, you sometimes want to test the memory footprint of the runtime, so you need to use the test tool to check. There is the Eclipse Memory Analyzer Tool (MAT) plug-in in Eclipse for testing, and there is a plug-in in IDEA, called JProfiler.
  2. JProfiler is a Java application performance diagnostic tool developed by EJ-Technologies. Powerful, but charged.
  3. The official download address: www.ej-technologies.com/products/jp…

The main function

The method call

Can an analysis of method calls help you understand what your application is doing and find ways to improve its performance

Memory allocation

Analyzing objects on the heap, reference chains, and garbage collection can help you fix memory leaks and optimize memory usage

Threads and locks

JProfiler provides a variety of analytical views on threads and locks to help you find multithreading problems

High level subsystem

Many performance problems occur at higher semantic levels. For example, for JDBC calls, you might want to find the slowest SQL statement to execute. JProfiler supports integration analysis of these subsystems

Installation and Configuration

Download and Install

Download: www.ej-technologies.com/download/jp…

Configure IDEA in JProfiler

The IDEA of integration of JProfiler

The specific use

Data collection mode

JProfiler data collection methods can be divided into two types: Sampling and Instrumentation.

Instrumentation: This is JProfiler full function mode. Before the class is loaded, JProfiler writes the relevant functionality code into the bytecode of the class that is being analyzed for requirements, which has some impact on the running JVM.

  1. Advantages: Powerful. In this setting, the call stack information is accurate.
  2. Disadvantages: If there are a large number of classes to be analyzed, the performance of the application is greatly affected and the CPU overhead may be high (depending on Filter control). Therefore, this pattern is typically used in conjunction with filters to analyze only specific classes or packages.

Sampling: Similar to sample statistics, the information in method stack of each thread stack shall be counted out at a certain interval (5ms).

  1. Advantages: Very low CPU overhead, minimal application impact (even if you don’t configure any filters)
  2. Disadvantages: Some data/features are not available (e.g., number of method calls, execution time)

Note: JProfiler itself does not specify the type of collection for the data; the collection type here is for method calls. Because most of the core functionality of JProfiler relies on data collected by method calls, it is straightforward to think of this as JProfiler’s data collection type.

Remote sensing monitoring Telemetries

Memory view Live Memory

The heap walker

CPU views CPU views

Threads view

JProfiler monitors thread history to determine its health, monitors for thread blocking, and presents methods managed by a thread in a tree form. Profiling threads.

Thread History displays a timeline of activity with Thread activity and Thread state.

Thread Monitor displays a list of all active threads and their current active status.

Thread dump Thread Dumps shows the stack trace for all threads.

Thread analysis is mainly concerned with three aspects:

  1. Maximum number of threads for a Web container. For example, the Tomcat thread capacity should be slightly larger than the maximum number of concurrent requests.
  2. Thread block
  3. The thread deadlock

Monitor & Lock Monitor &locks

Monitors and Locks Monitors & Locks The holding of Locks by all threads and lock information. Observe the JVM’s internal threads and view the status:

  1. Current Locking Graph: Displays the Current deadlock Graph in the JVM.
  2. Current Monitors in use: Displays the Monitors currently in use and includes their associated threads.
  3. Locking History Graph: Displays the Locking History recorded in the JVM.
  4. Monitor History: Displays the History of significant waiting events and blocking events.
  5. Monitor uses Statistics Monitor Usage Statistics: Displays statistical monitoring data for group monitoring, threads, and monitoring classes

Second, Arthas

Basic overview

background

Earlier, we introduced free tools such as JVisualVM, which comes with the JDK, as well as commercial tools such as JProfiler. JVisualVM and JProfiler are also well-known tools in the industry. Their advantage is that they can see performance data of various dimensions on the graphical interface. Users can make comprehensive analysis according to these data and then determine where performance problems occur.

However, both tools have the disadvantage of having to configure monitoring parameters in the server project process. The tool then connects to the project process remotely to retrieve the relevant data. This can cause some inconvenience, for example, the network of the online environment is isolated, and the local monitoring tool cannot connect to the online environment. And commercial tools, like JProfiler, are paid for.

Is there a tool that doesn’t require a remote connection, doesn’t require monitoring parameters, and still provides rich performance monitoring data? Arthas is an open source performance analysis tool from Alibaba.

An overview of the

Arthas is an open source Java diagnostics tool on Alibaba that developers love. Troubleshoot faults online without restart. Dynamically trace Java code; Monitor JVM status in real time.

Arthas supports JDK6+, Linux/Mac/Windows, command line interaction, and Tab auto-completion to further locate and diagnose problems.

Arthas can help you when you are stuck with a problem like the following:

  1. From which JAR is this class loaded? Why are all kinds of class-related exceptions reported?
  2. Why didn’t the code I changed execute? Did I not commit? Got the branch wrong?
  3. If you encounter a problem, you can’t debug it online. Can you only re-publish it by logging?
  4. There is a problem with a user’s data processing online, but it cannot be debugged online, and it cannot be reproduced offline!
  5. Is there a global vision to see the health of the system?
  6. Is there any way to monitor the real-time health of the JVM?
  7. How to quickly locate application hot spots, generate flame map?

Based on what tools

  1. Reys-anatomy :Arthas code is based on Greys secondary development. Thank you for all of Greys’ previous work and for all of Greys’ original authors’ comments and suggestions on Arthas!
  2. Termd :Arthas command implementation is based on TerMD. Arthas is an excellent command programming framework and feels that TerMD provides an excellent framework.
  3. Crash :Arthas’s text rendering feature is based on the text rendering feature in Crash, the source code can be seen here, thanks to Crash for doing a great job on this.
  4. Cli :Arthas’s command-line interface is based on the VERt. x CLI library, thanks to vert.x for a great job in this area.
  5. Compiler Arthas the source of the in-memory compiler code
  6. Telnet Client code source in Apache Commons Net Arthas
  7. JavaAgent: Interceptor that runs before main and has a built-in method named premain, meaning that the premain method is executed before main.
  8. SM: A general-purpose Java bytecode manipulation and analysis framework. It can be used to modify existing classes or to generate classes dynamically directly in binary form. ASM provides common bytecode conversion and analysis algorithms from which you can build custom complex conversion and code analysis tools. ASM provides similar functionality to other Java bytecode frameworks, but focuses on performance. Because it is designed and implemented as small and fast as possible, it is ideal for use in dynamic systems (and of course statically, as in v in compilers)

Official usage document

arthas.aliyun.com/zh-cn/

Installation and use

The installation

Installation Method 1: You can directly download it from Linux or Github. If the download speed is slow, you can try Gitee.

  1. Making wget download alibaba. Making. IO/arthas/arth…
  2. Wget arthas.gitee. IO /arthas-boot…

Installation method 2: can directly in the browser to visit alibaba. Making. IO/arthas/arth…

uninstall

In Linux/Unix/Mac platforms

Delete the following files:

rm -rf ~/.arthas/
rm -rf ~/logs/arthas
Copy the code

Windows platform directly delete the. Arthas and logs/arthas directories under user Home

Project directory

Arthas-agent: Agent based on JavaAgent technology

Bin: Some startup scripts

Arthas-boot :Java version of the one-click install startup script

Arthas – client: Telnet client code

Arthas-common: Some common utility classes and enumeration classes

Arthas-core: Core class, interaction and implementation of various arthas commands

Arthas-demo: Sample code

Arthas-memorycompiler: memorycompiler code, Fork from github.com/skalogs/Ska…

Arthas-packaging: Maven packaging related

Arthas – site: arthas site

Arthas-spy: Facets woven into the target class

Static: indicates static resources

Arthas – testcase: test

Start the

Arthas is just a Java program, so you can run it directly from Java-JAR.

Upon successful execution, Arthas provides a command line interaction where arthas detects Java processes on the current server and displays a list of processes for the user to enter a number (1, 2, 3, 4…). Make a selection and press Enter.

Method 1: java-jar arthas-boot.jar

Select process (enter [] id (not PID) press Enter) [INFO] arthas-boot version:3.14.
[INFO] Found existing java process, please choose one and hit RETURN.
* [1] :11616 com.Arthas
  [2] :8676
  [3] :16200 org.jetbrains.jps.cmdline.Launcher
  [4] :21032 org.jetbraiins.idea.maven.server.RemoteMavenServer
Copy the code

Method 2: Select a Java process PID during runtime

java -jar arthas-boot.jar [PID]

Check the process

See the log

cat ~/logs/arthas/arthas.log

See the help

java -jar arthas-boot.jar -h

web console

exit

Correlation diagnostic instruction

Basic instructions

The JVM related

The class/this correlation

Monitor/watch/trace

other

Java Mission Control

history

An overview of the

Function: Monitors JVM runtime status in real time

Other tools

Flame Graphs

Flame chart, which simply measures time by the width of the x axis, and the y axis represents the level of thread stack.

Tprofiler

TProfiler configuration, deployment, remote operation, and log reading are all very simple. But it was a hit, instant hit that helped us overcome the performance bottleneck of GC too often.

The most important feature of TProfiler is the ability to count the top methods on your JVM at any given time, and these top methods are most likely the cause of your JVM’s performance bottlenecks. This is something that most other JVM tuning tools don’t have, including JRockit Mission Control. JRokit lead developer Marcus Hirt, in a comment on his personal blog Low Overhead Method Profiling with Java Mission Control, made it clear that JRMC does not support the TOP Method.

TProfiler download: github.com/alibaba/TPr…

conclusion

This chapter introduces the second part of the JVM monitoring and diagnostics tool GUI, including the use of JProfiler, Arthas, Java Mission Controll, and more. The next article covers JVM runtime parameters.

Welcome everyone to pay attention to the public account (MarkZoe) to learn from each other and communicate with each other.