Chapter 7 JVM performance monitoring and troubleshooting tools (1), jvm troubleshooting

Source: Internet
Author: User

Chapter 7 JVM performance monitoring and troubleshooting tools (1), jvm troubleshooting

1. Locate System Problems

  • Basis
    • GC log
    • Heapdump/hprof File)
    • Thread snapshot (threaddump/javacore file)
    • Running log
    • Exception Stack
  • Tools used for analysis
    • Jps: displays all JVM processes in a specified system.
    • Jstat: Collects JVM running data.
    • Jinfo: displays JVM configuration information.
    • Jmap: forming a heapdump snapshot (heapdump file)
    • Jhat: analyzes heapdump files
    • Jstack: displays JVM thread snapshots.
    • Jconsole
    • VisualVM

Note: The following two types have graphical interfaces.

 

2. jps (the basis of all other commands)

Purpose: list all jvm vm processes.

Format: jps-l

 

3. jstat (the first choice for locating JVM performance problems at runtime without a GUI)

Purpose: View gc data and class load and unload data

Format: jstat option PID interval count

Meaning: option is performed every interval milliseconds and count is performed in total.

Note: S0 (from) uses 41.74%; S1 (to) uses 0; E (Eden) uses 54.35%; O (Old, Old) uses 62.41%; P (Perment, permanent generation) uses 99.63%, YGC (Young GC) uses 32 times, YGCT (Young GC Time) consumes 0.132 seconds, and FGC (Full GC) uses 1 Time, FGCT (Full GC Time) Costs 0.102 seconds; GCT (GC Time) Total costs 0.234 seconds.

Analysis: in fact, the above query results show that we need to increase P (permanent generation)

Note: 3683 classes are loaded, with a total of 4355.3 bytes. 0 classes are uninstalled, and the number of bytes of the unmounted classes is 0. The total cost of loading and uninstalling classes is 3.16 seconds.

For more use of jstat, see http://my.oschina.net/skyline520/blog/304805

 

4. jinfo

Purpose: view and modify JVM configuration parameters at runtime

Format: jinfo-flag parameter PID

Views the value of the MaxTenuringThreshold parameter in the 3732 process.

Note: The MaxTenuringThreshold parameter value in the 3732 process fails in windows.

 

5. jmap

Purpose: generate a heap dump snapshot and view the most memory-occupied elements to Analyze memory leakage issues.

Format: jmap-dump: format = B, file = file name PID

Note: generate the heap dump file myfile of the 3732 process.

Format (view the most memory-occupied element): jmap-histo PID

Note: there are too many results to see.

 

6. jhat

Role: Analyze heap dump snapshots (in combination with jmap)

Format: jhat file name

Note: After executing the preceding command, open localhost: 7000 and find the following red box to open it. Here is what we are most interested in.

Note: This tool is a last resort.

Run "ctrl + c"

 

7. jstack

Purpose: generate a thread snapshot to locate the cause of slow threads for a long time (long waits caused by deadlocks between threads, endless loops, and requests for external resources)

Format: jstack-l PID

Views the stack information of all threads in the 3732 process.

The author of "deep understanding of Java Virtual Machine" provides a tool jsp page that allows us to view the thread stack information by running the jsp page at any time when the program is running. The Code is as follows:

1 <% @ page language = "java" contentType = "text/html; charset = UTF-8" 2 pageEncoding = "UTF-8" import = "java. util. map "%> 3 <! DOCTYPE html> 4 Note: I have commented out a section in the code because I want to also find the stack information of the current thread. The author does not have this comment.

 

Summary:

  • Six common JDK commands related to JVM Performance
    • Jps: Query all processes in the JVM and find the PID to be operated. It is the basis of all commands.
    • Jstat: displays the gc and class loading/unloading information of the JVM process. It is the first choice to view JVM running data without a GUI.
    • Jinfo: View and dynamically modify JVM configuration parameters at runtime
    • Jmap: Generate heap dump snapshots and compare memory objects
    • Jhat: used with jmap to analyze heap dump logs. This tool is not used unless there are no other tools to do this.
    • Jstack: generate a thread snapshot to locate the cause of slow threads for a long time (long waits caused by deadlocks between threads, endless loops, and requests for external resources)
  • Output gc information to the console
    • -XX: + PrintGCDetails: Output GC details
    • -XX: + PrintGCTimeStamps: Output GC time information
    • -XX: + PrintGCApplicatonStoppedTime: the time when the application is paused due to GC.
  • Output gc information to the file
    • The above three parameters still apply here
    • -Xloggc: file path/gc. log: output to file

 

Related Article

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.