JVM Performance Tuning monitoring Tools JPS, Jstack, Jmap, Jhat, Jstat, hprof use detailed

Source: Internet
Author: User


1. JPS (Java Virtual machine Process Status Tool)

JPS is primarily used to output process state information running in the JVM

-Q does not output the class name, jar name, and parameters passed in the Main method

-m output parameters that pass in the Main method

-L OUTPUT The full name of the main class or Jar

-V Output parameters for incoming JVM

2. Jstack

Jstack is used primarily to view thread stack information within a Java process

The command line parameter options are described below:

-L long listings, will print out additional lock information, in the event of a deadlock can use the Jstack-l PID to observe the lock holding situation

-M mixed mode not only outputs the Java stack information, but also outputs C/+ + stack information (such as the native method)

Jstack can navigate to the thread stack, and depending on the stack information we can navigate to the specific code, so it is used very much in JVM performance tuning. Let's take a look at the most CPU-consuming Java threads in a Java process and locate the stack information, with the commands PS, top, printf, Jstack, grep.

The first step is to find out the Java process ID, and the Java application name I deployed on the server is mrf-center:

[Email protected]:/# ps-ef | grep Mrf-center | Grep-v grep

Root 21711 1 1 14:47 pts/3 00:02:10 Java-jarmrf-center.jar

Get the process ID 21711, the second step to find the process CPU-consuming threads, you can use PS-LFP pid or ps-mp pid-o thread, tid, time or top-hp pid, I use a third, the output is as follows:

The time column is the CPU for each Java thread, and the longest CPU time is a thread with a thread ID of 21742.

printf "%x\n" 21742

The next step is finally Jstack, which is used to output the stack information for process 21711 and then grep based on the thread ID's hexadecimal value, as follows:

[Email protected]:/#jstack 21711 | grep 54ee

"Pollintervalretryschedulerthread" prio=10 tid=0x00007f950043e000 Nid=0x54ee in object.wait () [0x00007f94c6eda000]

Can see CPU consumption in Pollintervalretryschedulerthread this class of object.wait (), I looked under my code, navigate to the following code

It is the idle wait code for the polling task, and the above siglock.wait (timeuntilcontinue) corresponds to the previous object.wait ().

3. Jmap (Memory Map) and Jhat (Java Heap analysis Tool)

Jmap is used to view heap memory usage, typically combined with jhat.

The JMAP syntax format is as follows:

jmap [option] pid

jmap [option] executable core

jmap [option] [[Email Protected]]remote-hostname-or-ip

If you are running on a 64-bit JVM, you may need to specify the-J-D64 command option parameter.

Jmap-permstat PID

The print process's class loader and ClassLoader load the persisted object information, Output: Class loader name, whether the object is alive (unreliable), object address, parent ClassLoader, loaded class size, and so on, such as:

Jmap-heap 8588

Using thread-localobject allocation.

Mark Sweep COMPACTGC

Heapconfiguration:

Minheapfreeratio = 40

Maxheapfreeratio = 70

Maxheapsize = 536870912 (512.0MB)

NewSize = 1048576 (1.0MB)

Maxnewsize = 4294901760 (4095.9375MB)

Oldsize = 4194304 (4.0MB)

Newratio = 2

Survivorratio = 8

PermSize = 268435456 (256.0MB)

MaxPermSize = 268435456 (256.0MB)

Heap Usage:

New Generation (Eden + 1 Survivor Space):

Capacity = 161021952 (153.5625MB)

used = 11450624 (10.920166015625MB)

Free = 149571328 (142.642333984375MB)

7.11121922059422% used

Eden Space:

Capacity = 143130624 (136.5MB)

used = 11450624 (10.920166015625MB)

Free = 131680000 (125.579833984375MB)

8.000121623168498% used

From Space:

Capacity = 17891328 (17.0625MB)

Used = 0 (0.0MB)

Free = 17891328 (17.0625MB)

0.0% used

To Space:

Capacity = 17891328 (17.0625MB)

Used = 0 (0.0MB)

Free = 17891328 (17.0625MB)

0.0% used

Tenuredgeneration:

Capacity = 357957632 (341.375MB)

Used = 0 (0.0MB)

Free = 357957632 (341.375MB)

0.0% used

Perm Generation:

Capacity = 268435456 (256.0MB)

used = 396896 (0.378509521484375MB)

Free = 268038560 (255.62149047851562MB)

0.14785528182983398% used

Use jmap-histo[:live] PID to view the number of objects in heap memory, size statistics histogram, if you bring live, only live objects, as follows:

Jmap-histo:live 8588

Num #instances #bytes class name

----------------------------------------------

1:987 203008 [C

2:792 172768 <symbolKlass>

3:28 28120 [B

4:1160 27840 java.lang.String

5:758 24256 Java.util.treemap$entry

6:45 23448 [I

7:90 18744 <constMethodKlass>

8:311 13192 [Ljava.lang.Object;

9:21 12240 <constantPoolKlass>

10:34 11152 <objArrayKlassKlass>

11:21 8008 <instanceKlassKlass>

12:90 7200 <methodKlass>

13:179 5776 [Ljava.lang.String;

14:55 5280 Java.lang.Class

15:21 4248 <constantPoolCacheKlass>

16:121 3872 Java.util.linkedhashmap$entry

17:65 3640 Java.net.URL

Class name is the object type, as described below:

B byte

C Char

D Double

F float

I int

J Long

Z Boolean

[Array, such as [i = int[]

[L + Class name other objects

Another common scenario is using JMAP to dump process memory usage into a file, and then use the Jhat analysis to view it. Jmap the dump command format as follows:

Jmap-dump:format=b,file=dumpfilename PID

I dump the above process ID 21711 as well:

[Email protected]:/# jmap-dump:format=b,file=/tmp/dump.dat 21711

Dumping Heap To/tmp/dump.dat ...

Heap dump file created

The dump file can be viewed with tools such as Mat, VISUALVM, and Jhat:

[Email protected]:/# jhat-port 9998/tmp/dump.dat

Reading From/tmp/dump.dat ...

Dump file created Tue Jan 17:46:14 CST 2014

Snapshot Read, resolving ...

Resolving 132207 objects ...

Chasing references, expect, dots .................

Eliminating duplicate references ......... ..........

Snapshot resolved.

Started HTTP Server on port 9998

Server is ready.

Note If the dump file is too large, you may need to add-j-xmx512m This parameter specifies the maximum heap memory, which is jhat-j-xmx512m-port9998/tmp/dump.dat. Then you can enter the host address in the browser: 9998 viewed:

4. Jstat (JVM Statistical monitoring tool)

Jstat [generaloption | outputoptions vmid[interval[s|ms] [count]]

Vmid is the Java Virtual machine ID, which is generally the process ID on the Linux/unix system. Interval is the sampling time interval. Count is the number of samples. For example, the following output is GC information, sampling time interval is 250ms, sample number is 4:

jstat -gc 21711 250 4

To understand the meaning of the above columns, first look at the JVM heap memory layout:

JVM Performance Tuning monitoring Tools JPS, Jstack, Jmap, Jhat, Jstat, hprof use detailed

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.