JVM learning Summary 5-performance monitoring and troubleshooting tools

Source: Internet
Author: User
Tags visualvm

I have mentioned four theories before, and this article can finally be started. In this article, we will introduce some common JVM tools that are useful for monitoring the JVM status, troubleshooting, and tuning analysis. However, before we start, I still need to say two things: the tool is only used to help us solve the problem, and we want to solve the problem quickly and accurately, the most important thing is to understand the internal theory and rich practical experience. If you do not know about the JVM memory processing mechanism, you should take a hard look. Well, the son said: "to do good deeds, you must first sharpen your tools. ", Let's start with the introduction below. I. All java developers of the JDK command line tool know that the bin directory of JDK stores the javac required for compiling java and the java command tools required for running java programs, however, many people did not notice that, in addition to these two tools, there are still many tools in this directory. These tools actually provide us with a lot of convenient and powerful functions, the following section describes the functions of each tool. For more information, see jdk/jre bin: the name acts as the jps JVM Process Status Tool. It specifies all the HotSpot VM processes in the system, jstatsJVM Statistics Monitoring Tool, and is used to collect the running parameters jinfoConfiguration Info for Java in various aspects of the Hotspot VM, real-world virtual machine configuration information jmapMemory map for java, generate a VM memory dump snapshot jhatJVM heap D Unp Browser is used to analyze the heapdump file. It creates an HTTP/HTML service, allowing you to view jstackStack Track for java in a Browser, below the VM thread snapshot is displayed, let's look at each simple usage: 1. jsp should actually say that most people are familiar with this command. Generally, we want to prevent the program from being started twice, to determine whether a java Process is alive or not, you can use this command to obtain all the currently running java processes of the system, and then determine based on the process name. Of course, you can also obtain the id of the corresponding process (this id refers to the LVMID in JVM, but it is consistent with the system process ID) and kill it to end the program. The syntax is as follows: copy the code syntax structure: jsp [options] [hostid] parameter: -q only outputs ID-l to display the master class executed by the VM-m to display the parameter-v sent to the main to output the JVM parameter copy code for startup 2. jstat is used to monitor various running status information of the VM, it can display class loading, memory, garbage collection, JIT compilation and other running data in local or remote virtual machine processes. Without GUI, it is the preferred tool for performance analysis. Jstat-<option> [-t] [-h <lines>] <vmid> [<interval> [<count>] parameter: Options-option, we generally use-gcutil to view the gc vmid-VM process number, that is, the currently running java Process number interval-interval, in seconds or milliseconds count-number of prints, if the default value is exceeded, the percentage of used space in Region vor space 0 of S0-Heap is printed: percentage of space used in Region 1 of region vor space on S1-Heap Eden space on E-Heap the percentage of space used in the Old space area on the O-Heap percentage of space used in the P-Perm space area YGC-number of Young GC times from application startup to sampling YGCT-from application startup to collection The time used by Young GC in seconds) FGC-number of Full GC times from application startup to sampling FGCT-time taken from application startup to Full GC at sampling (in seconds) GCT-copy the code from application startup to the total time used for garbage collection (unit: seconds) during sampling 3. jinfo can be used to view and adjust JVM running parameters in real time, it should be noted that this tool is only useful in linux. Although it is provided in Windows, it is very limited. The usage is as follows: parameter: -v view all the parameters in the explicit parameter-flag [+/-] of the VM. +/-You can add or reduce the runtime parameter-sysprops print System. getProperties () content 4. jmap is used to generate heapdump (for JVM memory status analysis, which is a key reference data for troubleshooting or tuning ), you can also query the finalize queue, java heap, and permanent generation details. In addition, the tool is also disabled in win. Parameter:-dump: [live,] format = B, file = <filename> uses the hprof binary format to output the jvm heap content to the file =. the live sub-option is optional. If the live option is specified, only the live object is output to the file. -finalizerinfo: prints the information of the object awaiting recycling. -heap: displays the heap summary, GC algorithm, heap configuration, and wise heap usage. -histo [: live]: prints the number of instances of each class, memory usage, and full name information of the class. the prefix "*" is added at the beginning of the VM internal class name "*". if the live sub-parameter is added, only the number of live objects is counted. -permstat: prints information about the persistent layer of classload and jvm heap. contains the name, activity, address, parent classloader, and number of loaded classes for each classloader. in addition, the number of internal strings and the amount of memory occupied are printed. -F force. no pid If yes, use the-dump or-histo parameter. in this mode, the live sub-parameter is invalid. -h |-help print the auxiliary information-J transmits the parameter to the jvm started by jmap. copy Code 5 and jhat are usually used together with jmap to analyze the heapdump file generated by jmap. It has a built-in simple HTTP server (Haha, I am also writing a web server recently, in fact, the general principle of the discovery is quite simple. The trouble is that the design of web application interfaces, internal processing details, and concurrent processing have been implemented. For more information, see: easy-httpserver), you can view the analysis results in a browser. In fact, this tool is not very useful. On the one hand, its function is simple, there is a certain gap with commonly used tools such as VisualVM, and on the other hand, it performs resource-consuming analysis and processing in the production environment, it is estimated that many companies are making taboos. Generally, heapdump is directed to the local machine. I will not describe the usage here. You can Google Baidu. 6. The jstack name is related to the stack, the private data stored in the stack is the private data of each thread (local variable table, method exit, operand stack, object reference, etc ), therefore, this command is used to generate a thread snapshot of the current Virtual Machine (threaddump, which can be used to analyze the reasons why a thread of the virtual machine is quite correct for a long time, such as deadlocks, dead loops, and resource requests that take too long ). Copy the code syntax structure: jstack [option] pid parameter:-F when the 'jstack [-l] pid 'does not have a corresponding value, forcibly print the stack information-l long list. print the additional information about the lock, such as java. util. concurrent ownable synchronizers list. -m prints all stack information of java and native c/c ++ frameworks. -h |-help print help information copy code 2. JDK visualization tools: JConsole and VisualVM, both of which provide powerful functions, I will not describe it this time. Let's wait for the next article to analyze it with a small example. It seems a bit pitfall, sleepy, sleep first, upset recently, wait for adjustment to continue ^_^.

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.