Performance testing Troubleshooting location problems, analysis tuning process, will encounter to analyze GC logs, human flesh Analysis GC log is sometimes difficult, related graphical or command-line tools can effectively help assist analysis.
GC Log Parameters
generate GC logs by adding related parameters in the Tomcat startup script
The -verbose.gc switch Displays the operation contents of the GC. Open it to show when the busiest and most idle collection behavior occurred, the amount of memory before and after collection, the time it took to collect, and so on.
Open the -xx:+ printgcdetails Switch to learn more about the changes in the GC.
Open the -xx: + printgctimestamps switch to see when these garbage collections occur, measured in seconds since the JVM started.
Finally, more detailed information about the heap is learned through the -xx: + PRINTHEAPATGC switch.
To understand the situation of the new domain, you can use the -xx:=printtenuringdistribution switch to understand the object rights for the usage period.
-XLOGGC: $CATALINA _base/logs/gc.log the path generated by the GC log
Xx:+printgcapplicationstoppedtime //Output GC to cause application pause time
-xx:+printgcdatestamps //GC time information occurred
GC Log
The log shows the timing of the GC, the recovery situation in young, the overall recycling situation, the FULLGC situation, the time spent in recycling, etc.
Common JVM Parameters
after analyzing GC logs, it is often necessary to adjust the JVM memory-related parameters, commonly used parameters are as follows
-XMS: The initial heap size, default is the physical memory of 1/64 (<1GB), the default (minheapfreeratio parameter can be adjusted ) when the free heap memory is less than 40%, theJVM will increase the heap until maximum limit of-xmx
-xmx: Maximum heap size, default (maxheapfreeratio parameter can be adjusted ) when free heap memory is greater than 70%, theJVM will reduce the heap until the minimum limit of-XMS
-xmn: The size of the new generation of memory space, note: The size here is (eden+ 2 survivor space). is different from the New gen shown in Jmap-heap . Entire Heap Size = Cenozoic Size + laosheng Generation size + permanent generation size.
If the size of the heap is not changed, the Laosheng will be reduced after the new generation is enlarged . This value has a large impact on system performance , and Sun's official recommendation is 3/8 for the entire heap .
-xx:survivorratio: The capacity ratio of the Eden region to the survivor region in the Cenozoic , with a default value of 8. the ratio of two survivor to one Eden area was 2:8, and one survivor area accounted for 1/10 of the entire young generation .
-XSS: The stack size of each thread. after JDK5.0, each thread has a stack size of 1M, before each thread has a stack size of 256K. Appropriate adjustments should be made to the size of the memory required by the application's thread. In the same physical memory , reducing this value can generate more threads. However, the operating system of the number of threads within a process is still limited, can not be generated indefinitely, the empirical value of 3000~5000 around. General small application, if the stack is not very deep, should be 128k enough, large applications recommend the use of 256k. This option has a large impact on performance and requires rigorous testing. similar to the threadstacksize option interpretation, the official documentation does not seem to explain the phrase in the Forum : "-XSS is translated in a VM flag named Threadstacksize "General Setting this value is OK.
-xx:permsize: Sets the permanent generation (Perm gen) initial value. The default value is 1/64 of physical memory .
-xx:maxpermsize: Sets the maximum number of persistent generations. 1/4 of physical memory .
GC Log Analysis Tool
(1) Gchisto
Http://Java.net/projects/gchisto
Directly click Gchisto.jar to run, click Add to load gc.log
Total GC counts, YOUNGGC times, FULLGC times, percentage of times,GC consumed time, percentage, average time consumed, minimum time consumed, etc.
Graphical representation of statistics
YOUNGGC,FULLGC the distribution of different time-consuming times, check to show the individual distribution of YOUNGGC or FULLGC
Detailed GC situation throughout the time process to dissect the entire process
(2) Gclogviewer
http://code.google.com/p/gclogviewer/
Click run.bat to run
a trend graph of GC scenarios throughout the process, also showing GC type, throughput, average GC frequency, memory change trend, etc.
Tools can also compare different GC logs
(3) Hpjmeter
Get address Http://www.hp.com/go/java
Reference Document http://www.javaperformancetuning.com/tools/hpjtune/index.shtml
The tool is powerful, but only the GC log generated by the following parameters can be opened, -verbose:gc-xloggc:gc.log, and the gc.log generated by adding additional parameters cannot be opened.
(4) Gcviewer
Http://www.tagtraum.com/gcviewer.html
This tool has a lot of use, but only in the JDK1.5 of the following version of the run,after 1.6 does not correspond.
(5) Garbagecat
Http://code.google.com/a/eclipselabs.org/p/garbagecat/wiki/Documentation
Other monitoring methods
JVISUALVM dynamic analysis of JVM memory and GC conditions, Plugins:visualgc
JVISUALVM can also heapdump out the corresponding hprof file (default storage path: Monitored server/ tmp), using relevant tools, such as Hpjmeter can analyze it
grep full Gc.log cursory observation of FULLGC occurrence frequency
Jstat–gcutil [PID] [intervel] [count]
Jmap-histo PID can observe the number of objects and occupy space
Jmap-heap PID can observe JVM configuration parameters, heap memory area usage
Jprofiler,jmap dump out with Mat analysis
If the dump file you want to analyze is large, you need a lot of memory and it's easy to crash.
So at startup, we should add some parameters: java–xms512m–xmx1024m–xss8m
"Go" GC Log analysis tool