This time to share some of the Java command line troubleshooting tools, mainly to troubleshoot OOM, thread congestion and other multi-threaded high concurrency scenarios brought about by some problems. Which involves some of the basic knowledge of JVM, no contact with the relevant knowledge of students, you can first look at JVM memory model diagram, probably do an understanding
JVM memory model diagram
JPS is the tool provided by JDK to view the Java process, and the whole process is JavaVirtual Machine Process Status Tool
The direct command line input JPS allows you to view the current Java process
One of the tools to view the current process is to see whether the current process is running, ending, whether it’s a zombie process, how much resources it takes, and so on
Used in conjunction with the grep pipeline process to view information about the current Java process
This bunch of things looks messy and doesn’t seem to be able to read
That’s OK. Let’s remove the plumbing command and the title bar will be read
removes the effect after grep
PS tools for detailed use, you can refer to: http://blog.csdn.net/lsbhjshyn/article/details/18549869
Focus on this line in the red box, and by asking the degree, we can see:
• USER: does that process belong to that user account?
• PID: the process’s progress ID number.
•%CPU: percentage of CPU resources used by this process;
•%MEM: the percentage of physical memory occupied by this process;
• VSZ: the amount of virtual memory used by the process (Kbytes)
• RSS: the amount of memory (Kbytes) that the process occupies
TTY: the process is in the terminal operation above, if the terminal independent display, in addition, tty1-tty6?, is the machine above the login program, if the pts/0 and so on, are represented by network connection into the host program.
• STAT: the current state of the program, the main state has:
R: the program is currently in operation, or may be operational;
S: the program is sleeping right now (idle state is said! ) but may be awakened by certain signals (signal).
T: the program is currently being detected or stopped;
Z: the program should have been terminated, but its parent program failed to terminate him properly, resulting in a zombie program
• START: the process is triggered by the time it starts;
• TIME: the process actually uses the CPU operation time.
• COMMAND: what are the actual instructions for this program?
The corresponding Java process in the picture, we can know that the process of Java PID is 32727, accounting for 0.3% of CPU, accounting for 34.6% of the physical memory, using 8372988kb virtual memory, a fixed amount of memory is 2797004kb, and the terminal is independent of the current process in sleep, is a multi thread process
Followed by the string is the JVM parameter, with the previous knowledge of JVM related, it is not difficult to understand
Xms4g:JVM initial allocation of heap memory, here is 4G
Xmx4g:JVM maximum allowed allocation of heap memory, here is 4G
That is because XMS = = Xmx, avoid dynamic memory allocation performance
PermSize=96M:JVM initial allocation of non heap memory 96M
MaxPermSize=256m:JVM maximum allowed allocation of non heap memory 256M
The perm section mainly stores information about Class, which is written mainly during the JIT and during the classload. If the program will be load many class, and the perm area is allocated too small, it will cause OOM when classload
Xmn2g:JVM allocated young memory 2G
SurvivorRatio=10 E area than S0, the ratio of S1, here is 10, said E S0, accounting for 10/12, S1 each accounted for 1/12, adjust this value can change E the size of the area, so as to change the frequency of youngGC
Young zone: you can use plain or parallel garbage collection algorithms, controlled by the parameter -XX:+UseParNewGC
Old zone: use Concurrent Mark Sweep only
UseCMSCompactAtFullCollection means compression after FGC because CMS does not compress space by default
CMSMaxAbortablePrecleanTime: this will only end when the abortable-preclean phase executes at this time. Modifying this parameter can reduce the CMS-concurrent-abortable-preclean phase
CMSClassUnloadingEnabled: with the parallel collector, the CMS collector defaults not to garbage generation for the permanent generation. If you want to recycle the permanent generation, you can use the settings flag
CMSInitiatingOccupancyFraction=80: this value represents the utilization rate of older generations of heap space. For example, value=75 means that the first CMS garbage collection will be triggered when the older generation is taken up 75%
DisableExplicitGC: this flag will tell JVM to completely ignore the GC call of the system (regardless of what type of collector it uses)
UseCMSInitiatingOccupancyOnly: flags to order that JVM does not start the CMS garbage collection cycle based on data collected at run time. Instead, when the flag is opened, JVM collects each CMS collection through the value of the CMSInitiatingOccupancyFraction, not just for the first time.
HeapDumpOnOutOfMemoryError:JVM will shoot a heap dump snapshot when it encounters OutOfMemoryError and save it in a file
The location of the HeapDumpPath=/home/mapp/logs/java.hprof:dump snapshot
MaxDirectMemorySize: this parameter specifies the limit of the space that DirectByteBuffer can allocate. If this parameter is not specified, the JVM is started, and the default value is the value corresponding to xmx.
Like the first example above the -XX:+DisableExplicitGC, these two parameters are used to change the default behavior (System.gc) with different; the two parameters can only be used with the CMS (-XX:+UseConcMarkSweepGC), and System.gc (or GC) will trigger, but not trigger a complete stop-the-world full GC, but a concurrent GC cycle (liuinsect note: a concurrent cycle is actually a GC, under CMS CMS can only be used in full GC, therefore, is also a full GC but the efficiency is relatively high.).
CMS GC will also do reference processing in the cycle. So if you use one of these two parameters instead of -XX:+DisableExplicitGC, you’ll avoid the long GC pause brought by full GC, and the NIO direct memory’s OOM won’t be that easy.
Basically JVM is commonly used in these parameters, the current development is not related to the change of JVM parameter, put the principle of a clear understanding of the concept, sort out the record, when used after more convenient view.
Jstat, -gcutil, PID, time,
Use your own jstat command to see the GC status of the current Java process
Among them, E, S0, and S1 are JVM memory in the new generation, the initial object is placed in E, and when E is full, trigger Young GC
Moving the surviving objects in the E zone to one of the S areas and clearing the area. The surviving copies will be copied into another s area, where many GC survivors will move into the old area
has an young GC
When the old zone is full and new objects are promoted, the Major GC is triggered.
Major GC is full GC, old area is used to clean up the tag, compression algorithm will cause stop-the-world
The number of jstat in FGC is the number of stop-the-world
Note that CMS is not equal to Full GC, we can see that CMS is divided into several periods, only stop the world phase was calculated to the frequency and time of Full and GC, and the number and time of service thread GC is not considered to be Full GC
GC related reference: http://blog.csdn.net/doc_sgl/article/details/46594975
Jstat related reference: http://blog.csdn.net/zhaozheng7758/article/details/8623535/
In addition to jstat, jstack is a very common tool for probing the running of Java processes. In particular, the service is running slowly, inexplicably, no response, etc. very effective
In general, the JPS is used in conjunction with the first Java corresponding to the PID
The Java thread running cycle has the following states:
NEW: status means that the thread has just been created and has not started yet
The RUNNABLE state is the thread is in normal operation, there may be a time-consuming operation /CPU time slice switch /IO wait, this condition is generally for other system resources, rather than lock, Sleep etc.
BLOCKED is in this state, the synchronous operation of multiple threads in the scene, such as waiting for another thread synchronized block execution release, or reentrant synchronized block others call wait () method, is also here is the threads waiting to enter the critical region
WAITING this condition refers to the thread owns a lock, calling his wait method, other threads waiting for the lock owner / call notify / notifyAll over the thread can continue to the next step, the difference here to distinguish between BLOCKED and WATING, is a critical point in the outside waiting to enter, one is in understand the point inside the wait notify thread to wait for others, call the join method join when another thread, will enter the WAITING state, waiting for his join thread end
TIMED_WAITING this state is limited (time limited) WAITING, generally appear in the call wait (long), join (long) and so on, the other thread sleep, will also enter the TIMED_WAITING state
The TERMINATED in this state indicates that the run method of the thread has been executed and is essentially dead (when the thread was persisted for a long time and might not be recycled)
Observe the status of the user process, and if most are in the BLOCKED state, it is likely that the program has been locked into a deadlock, and that it is good to use it to troubleshoot the problem
You need the top command when you need performance tuning or you need to know the consumption of resources within the current process
The top command will sort it in the case of CPU consumption
converted into 16 hexadecimal
Use the printf command to convert it into 16
searches for related processes using jstack
Then jstack search, you can find the specific consumption of CPU.
Of course, because of the lack of consumption of resources for what happens in the code, so do not see what, if it is because of a method or class that consumes a lot of resources through CPU, this method can be targeted to the specific code.
Specific use reference: http://www.open-open.com/lib/view/open1390916852007.html