How to use VISUALVM for performance analysis and tuning

Source: Internet
Author: User
Tags memory usage thread versions cpu usage root directory visualvm

Overview

In the process of developing large Java applications, there are some problems such as memory leak, performance bottleneck and so on, such as file, network, database connection is not released, the algorithm is not optimized. As the application continues to run, it can cause the entire system to run less efficiently and, in a serious case, cause the system to crash. In order to find out the hidden problems in the program, the performance analysis tools are often used to analyze and optimize the performance of the application during the late development of the project.

VISUALVM is a free performance analysis tool. It obtains real-time data from the program runtime through Jvmstat, JMX, SA (serviceability Agent) and Attach API, and performs dynamic performance analysis. At the same time, it can automatically choose faster and more lightweight technology to minimize the impact of performance analysis on the application and improve the accuracy of performance analysis.

In this paper, we will introduce the main functions of VISUALVM and discuss how to use the obtained data for performance analysis and tuning.

Background knowledge

Main methods of performance analysis

Monitoring: Monitoring is a common way to view the run-time behavior of an application. There are often multiple views (view) that display CPU usage, memory usage, thread state, and other useful information in real time, so that users can quickly discover the key to the problem.

Dump: The profiling tool obtains current state data from memory and stores it in a file for static profiling. A Java program triggers a dump operation by adding the appropriate condition parameters when the Java program is started. It consists of the following three species:

System dumps: A dump of the local system generated by the JVM, also known as a core dump. In general, the system dumps large amounts of data, requiring platform-related tools to analyze, such as WinDbg on Windows and gdb on Linux.

Java dumps: Formatted data that is generated internally by the JVM, including thread information, loading information for classes, and statistical data for the heap. It is also commonly used to detect deadlocks.

Heap dumps: The JVM stores the heap contents of all objects to a file.

Snapshots: After the application starts, the Profiling Tools start collecting various run-time data, some of which are displayed directly in the Watch view, and most of the data is kept internally until the user asks for a snapshot, and the statistics based on the saved data are displayed. Snapshots contain information about the execution of an application over time, typically with both CPU snapshots and memory snapshots.

CPU snapshots: Primarily contains the invocation relationships and run-time of functions in an application that can often be viewed in the CPU snapshot view.

Memory snapshots: mainly include memory allocation and usage, all classes loaded, existing object information, and reference relationships between objects. This information can often be viewed in the memory snapshot view.

Performance Analysis: Performance analysis is to help developers locate the part of the program that needs to be optimized by collecting the execution data of the program runtime, thereby increasing the speed of the program or the efficiency of memory usage, mainly in the following three aspects:

CPU Performance Analysis: CPU performance analysis is the main purpose of statistical function calls and execution time, or, more simply, to count the application CPU usage. CPU monitoring and CPU snapshots are usually used to display CPU profiling results.

Memory performance Analysis: The main purpose of memory performance analysis is to detect possible memory leak problems and determine the direction of optimized memory usage through statistical memory usage. Memory monitoring and memory snapshots are usually used to display memory profiling results.

Threading Profiling: Threading profiling is primarily used to determine the problem of memory in multithreaded applications. Typically includes the state of the thread, the deadlock situation, and the distribution of the state within the thread's lifetime

VISUALVM Installation

VISUALVM is a profiling tool that has been part of the Oracle JDK since JDK 6 Update 7 and is located under the Bin folder in the JDK root directory. VISUALVM itself will run on the version above JDK6, but it will be able to monitor the applications in the JDK1.4 version above. The following describes how to install VISUALVM and plug-ins on various VISUALVM.

Install VISUALVM

The official website of the VISUALVM project is currently available in both English and multi-language versions. Multi-language versions mainly support English, Japanese, and Chinese three languages. If you download and install a multilingual version of VISUALVM, the installer installs the appropriate VISUALVM language version according to the current locale of the operating system. The most supported operating systems for the latest VISUALVM version are: Microsoft Windows (7, Vista, XP, Server), Linux, Sun Solaris, Mac OS X, HP-UX 11i. This article takes Microsoft Windows XP as the installation environment and supports Chinese.

Download the VISUALVM installer from the official website of the VISUALVM project.

Unzip the VISUALVM installer to the local system.

Navigate to the Bin directory of the VISUALVM installation directory, and then start Jvisualvm.exe.

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.