Java Virtual Machine (vi): JVM Tuning-Tools

Source: Internet
Author: User
Tags visualvm jconsole

Tools as a graphical interface to show more intuitive discovery problems, on the other hand, some performance analysis (dump file analysis) will not be directly analyzed in production, often dump files up to about 1G, manual analysis of low efficiency, so the use of tools to analyze JVM-related issues, Long can reach a multiplier effect.

JVM monitoring analysis tools are generally divided into two categories, one is the JDK comes with the tool, one is a third-party analysis tools. The JDK comes with tools that are generally available under the JDK Bin directory, and can be used directly as an EXE, including analysis tools that are already powerful, almost all in every way, But we use only two of the most commonly used: Jconsole.exe and Jvisualvm.exe; third-party analysis tools have a lot of different emphases, the more representative: MAT (Memory Analyzer tool), Gchisto and so on.

For large JAVA applications, fine testing is also hard to block all vulnerabilities, even though we have done a lot of good work during the testing phase, many problems are exposed in the production environment and are difficult to reproduce in a test environment. The JVM is able to record some of the operational state of the system when the problem occurs and store it in a heap dump file, providing an important basis for us to analyze and diagnose the problem. One of the VISUALVM and mat is the dump file Analysis tool.

JDK's own tools

Jconsole

Jconsole (Java Monitoring and Management console) is a Java monitoring and management console that comes from Java5, and is built into the JDK, to monitor memory, threads, and classes in the JVM, and is a JMX-based (Java Management extensions) GUI performance monitoring tool. Jconsole uses the JVM's extensibility mechanism to obtain and present information such as the performance and resource consumption of applications running in virtual machines.

Click Jconsole.exe directly in the Jdk/bin directory to start, the interface is as follows:

In the pop-up box, you can select the native Java application to monitor the native, or you can select a remote Java service to monitor if the remote service needs to be monitored by adding the following code to the Tomcat startup script:

-Dcom.sun.management.jmxremote.port=6969   -Dcom.sun.management.jmxremote.ssl=false   -Dcom.sun.management.jmxremote.authenticate=false

Once connected, you can see the Jconsole overview diagram and the main features: overview, memory, threads, classes, VMS, MBeans

    • Overview, a chart showing the heap memory usage, the number of active threads, the loaded class, the cup occupancy rate of the line chart, can be very clearly observed in the process of program execution changes.

    • Memory, mainly showing the use of memory, while you can see the heap and non-heap memory changes in comparison, you can click on the execution of GC to punish the execution of GC

    • Thread, the main interface shows the number of threads of activity and peak, while clicking on the lower left thread can view the details of the thread, such as what the state of the thread is, the contents of the stack, etc., and can also click "Detect deadlock" to check if there is a deadlock between threads.

    • Class that mainly shows information about the loaded class.
    • A VM profile that shows a summary of all information about the JVM, including basic information, thread-related, heap-related, operating system, VM parameters, and so on.
    • Mbean, view the properties, methods, etc. of the mbean.

VisualVM

Brief introduction

VisualVM is a tool that provides a visual interface for viewing detailed information about Java-based applications (Java applications) running on Java virtual machines (Java machine, JVM). VisualVM organizes the data about the JVM software retrieved by the Java Development Kit (JDK) tool and provides that information in a way that enables you to quickly view data about multiple Java applications. You can view data about the local application and the applications running on the remote host. In addition, you can capture data about a JVM software instance and save that data to a local system for later viewing or sharing with other users.

VisualVM is JAVAJDK's best tuning tool, and I use the most tuning tools, almost all aspects of JVM tuning. Also in the Jdk/bin directory under the double-click Jvisualvm.exe can be used, starting up and Jconsole same can choose local and remote, if you need to monitor the remote also need to configure the relevant parameters, the main interface is as follows;

VISUALVM can be installed according to the needs of different plug-ins, each plug-in has different concerns, and some of the main monitoring GC, some of the main monitoring memory, some monitoring threads and so on.

How to install:

1. Select "Tools" > "Plugins" from the main menu.
2. In the Available Plugins tab, select the Install check box for the plugin. Click Install.
3, gradually complete the plug-in installation program.

Here I take Eclipse (PID 22296) as an example, double-click to expand directly, the main interface shows the system and JVM two chunks of content, click on the lower right JVM parameters and System properties can refer to the detailed parameter information.

Because VISUALVM plug-in too many, I here mainly introduce three I mainly use a few: monitoring, threading, Visual GC

The monitored home page is actually a graph of CPU, memory, class, thread

There's no big difference between threading and jconsole features.

Visual GC is a feature that is often used to clearly see the changes in memory in the younger generation, the old age, and the GC frequency, GC time, and so on.

The above functions in fact jconsole almost, VISUALVM more comprehensive more intuitive some, in addition VISUALVM a lot of other functions, can analyze dump memory snapshot, dump out the thread snapshot and analysis, there are many other plug-ins you can explore

Third-party tuning tools

MAT

What is Mat?

MAT, a Memory analyzer tool, is a fast, feature-rich Java heap Analysis tool that helps us to find memory leaks and reduce memory consumption. Use the Memory analysis tool to analyze from a multitude of objects to quickly calculate the size of objects in memory, to see who is preventing the garbage collector from recycling, and to visually look at the objects that may be causing the results through the report.

Often memory leak analysis is considered a difficult task, typically performed by a team of experienced people. However, the MAT (Eclipse Memory Analyzer) is considered to be a "fool-like" Heap Dump file analysis tool, you can generate a professional analysis report with a single click of the mouse. Compared to other memory leak analysis tools, MAT is very easy to use, basic can achieve a key in place, even the novice can quickly get started.

The mat is installed as an Eclipse plug-in, and the specific installation process is not described, and you can generate an analysis report in the eclipse mat by using VISUALVM or the Jmap command to produce a heap file:

Production of this report will also generate three copies of the dump file in the same sibling directory (Dump_top_consumers.zip, Dump_leak_suspects.zip, Dump_top_ Components.zip) Analysis of the results of the HTML file, easy to send to the relevant colleagues to view.

The following actions, Reports, and step by step regions are to be concerned:

    • Histogram: Lists objects in memory, number and size of objects, supports regular expression lookups, or calculates retained size for all objects of that class

    • Dominator Tree: Lists the largest objects and their dependent on the surviving object (size is sorted by retained heap)

    • Top consumers: List the largest object by graph

    • Duplicate classes: Detecting classes loaded by multiple class loaders

    • Leak Suspects: Memory leak analysis

    • TOP components: Lists 1 of reports that are larger than the total heap count.

    • Component Report: The analysis object belongs to the same package or is loaded by the same ClassLoader

The above is just a beginner's introduction, Mat has more powerful use, such as contrast heap memory, in the production environment often in order to locate the problem, every few minutes dump a memory snapshot, and then in contrast to different time heap memory changes to find the problem.

Gchisto

Gchisto is a professional analysis of GC log tool, can be analyzed by GC log: Minor GC, full GC time, frequency, etc., through the list, reports, charts and other forms to respond to GC situation. Although the interface is slightly rough, but the function is good.

Once you have configured your local JDK environment, double-click Gchisto.jar and click Add to select Gc.log Log in the popup input box

    • GC Pause Stats: The number of times a GC can be viewed, GC time, GC overhead, maximum GC time and minimum GC time, and corresponding histogram

    • GC Pause Distribution: View the detailed distribution of GC pauses, the x-axis indicates garbage collection pause times, and the y-axis represents the number of pauses.

    • GC Timeline: Show garbage collection across the timeline

However, this tool is no longer maintained and does not recognize the latest JDK log files.

Gcviewer

Gcviewer is also an analysis gadget used to visualize the log of garbage collectors generated by sun/oracle, IBM, HP and BEA Java virtual machines, gcviewer a personal feeling that the interface is not gchisto more professional.

The above two GC analysis logs, a less maintenance, a less professional, to recommend a better GC analysis tool

This article is reproduced from

The pure smile of the original

Original address: http://www.cnblogs.com/ityouknow/p/5603287.html

Java Virtual Machine (vi): JVM Tuning-Tools

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.