To understand the role of GC in performance, first understand the corresponding parameters:
JVM Options for GC
1:heap Size
A:-xmx
Specifies the maximum heap size for the JVM, such as:-xmx2g
B:-xms
Specifies the minimum heap size for the JVM, such as:-xms1g
C:-xmn
Specifies the size of the new generation in the JVM, such as:-xmn256m
D:-xx:permsize
Specifies the minimum value of perm generation in the JVM, such as:-xx:permsize=32m
E:-xx:maxpermsize
Specifies the maximum value of the perm generation, such as:-xx:maxpermsize=64m
F:-XSS
Specifies the thread buyers size, such as:-xss128k
G:-xx:newratio
Specifies the ratio of the old Generation heap size to the new Generation in the JVM, which fails with the CMS GC, such as:-xx:newratio=2
H:-xx:survivorratio
Specify the heap size ratio for Eden Space and a survivor space in new generation,-xx:survivorratio=8, in the case of a total of new generation 10m, Eden Space is 8m
I:-xx:minheapfreeratio
Specifies that the heap shrinks in the case of a JVM heap that is less than N, XMX==XMS, such as:-xx:minheapfreeratio=30
J:-xx:maxheapfreeratio
Specifies that the heap expands in the case of a JVM heap with a usage greater than N, XMX==XMS, such as:-xx:maxheapfreeratio=70
K:-xx:largepagesizeinbytes
Specifies the paging page size for Java heap, such as:-xx:largepagesizeinbytes=128m
2:garbage Collector
A:-XX:+USEPARALLELGC
Specifies that the new generation uses parallel collector, which collects concurrently, initiates multiple garbage collection thread at the same time, and cannot be used with the CMS GC. System ton of spit priority, but there will be a long time app pause, Background system tasks can use this GC
B:-xx:parallelgcthreads
Specifies the number of thread launches when parallel collection, by default the number of physical processor, such as:-xx:parallelgcthreads=8
C:-XX:+USEPARALLELOLDGC
Specify to use parallel collector in old generation
D:-XX:+USEPARNEWGC
Specifies that the parallel collector is used in new generation, is an upgraded version of the USEPARALLELGC GC, has better performance or benefits and can be used with the CMS GC
E:-xx:+cmsparallelremarkenabled
Minimize Mark's time when using USEPARNEWGC
F:-XX:+USECONCMARKSWEEPGC
Specifies that the concurrent Cmark sweep GC,GC thread and the app thread are used in the old generation, so it is called Concurrent.app pause for a short time and is suitable for highly interactive systems such as web Server
G:-xx:+usecmscompactatfullcollection
Prevents memory Fragmention, organizes live object, and reduces memory fragmentation when using concurrent GC
H:-xx:cmsinitiatingoccupancyfraction=n
Indicates that the concurrent collector is started after the old generation scale is used n%, the default value is 68, such as:-xx:cmsinitiatingoccupancyfraction=70
There is a bug that appears on the lower version of the JVM, http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=6486089
I:-xx:+usecmsinitiatingoccupancyonly
Indicates that only the old generation concurrent collector start collection after using the initialized scale
3:others
A:-xx:maxtenuringthreshold
Specifies that an object is transferred to the old generation zone after the N-Times of the young GC, and that the default value is 15 under Linux64 java6, which is not valid for throughput collector, such as:-xx: Maxtenuringthreshold=31
B:-XX:+DISABLEEXPLICITGC
Disables the invocation of full GC in Java programs, such as System.GC ()
C:-xx:+usefastaccessormethods
Optimization of the original type Get,set method
D:-xx:+printgcdetails
The situation of garbage collection should be as follows:
[GC 15610.466: [parnew:229689k->20221k (235968K), 0.0194460 secs] 1159829k->953935k (2070976K), 0.0196420 secs]
E:-xx:+printgctimestamps
The time of the garbage collection, such as:
[times:user=0.09 sys=0.00, real=0.02 secs]
F:-xx:+printgcapplicationstoppedtime
When playing garbage collection, the system's pause time, such as:
Total time for which application threads were stopped:0.0225920 seconds
The JVM gives three choices: the serial collector, the parallel collector, the concurrent collector, but the serial collector is only available for small amounts of data, so the choice here is primarily for the parallel collector and the concurrency collector. By default, JDK5.0 used a serial collector before, if you want to use theotherThe collector needs to add the appropriate parameters at startup. After JDK5.0, the JVM is judged based on the current system configuration.
1. Throughput-First parallel collector
As mentioned above, the parallel collector is mainly aimed at reaching a certain throughput, and is suitable for science and technology and background processing.
Typical configuration:
*Java-xmx3800m-xms3800m-xmn2g-xss128k-xx:+useparallelgc-xx:parallelgcthreads=20
-XX:+USEPARALLELGC: Select the garbage collector as the parallel collector. This configuration is only valid for younger generations. In this configuration, the younger generation uses concurrent collection, while the older generation still uses serial collection.
-XX:PARALLELGCTHREADS=20: Configures the number of threads for a parallel collector, that is, how many threads are garbage collected together. This value is best configured to be equal to the number of processors.
* JAVA-XMX3550M-XMS3550M-XMN2G-XSS128K-XX:+USEPARALLELGC-XX:PARALLELGCTHREADS=20-XX:+USEPARALLELOLDGC
-XX:+USEPARALLELOLDGC: Configure the old Generation garbage collection method for parallel collection. JDK6.0 supports parallel collection of older generations.
* java-xmx3550m-xms3550m-xmn2g-xss128k-xx:+useparallelgc-xx:maxgcpausemillis=100
-XX:MAXGCPAUSEMILLIS=100: Sets the maximum time for each young generation of garbage collection, and if this time is not met, the JVM automatically adjusts the younger generation size to meet this value.
* Java-xmx3550m-xms3550m-xmn2g-xss128k-xx:+useparallelgc-xx:maxgcpausemillis=100-xx:+useadaptivesizepolicy
-xx:+useadaptivesizepolicy: When this option is set, the parallel collector automatically selects the size of the younger generation and the corresponding Survivor area scale to achieve the minimum corresponding time specified by the target system or the collection frequency, etc., which is recommended to be turned on when using the parallel collector.
2. Concurrency collector with response time preference
As mentioned above, the concurrency collector is mainly to ensure the response time of the system, reduce the time of the garbage collection downtime. It is suitable for application server, telecom field and so on.
Typical configuration:
* JAVA-XMX3550M-XMS3550M-XMN2G-XSS128K-XX:PARALLELGCTHREADS=20-XX:+USECONCMARKSWEEPGC-XX:+USEPARNEWGC
-XX:+USECONCMARKSWEEPGC: Set old age on behalf of concurrent collection.TestAfter configuring this, the configuration of the-xx:newratio=4 is invalid for unknown reasons. Therefore, at this time the younger generation size is best set with-XMN.
-XX:+USEPARNEWGC: Set Young on behalf of the parallel collection. Can be used concurrently with CMS collection. JDK5.0 above, the JVM will set itself according to the system configuration, so it is no longer necessary to set this value.
* java-xmx3550m-xms3550m-xmn2g-xss128k-xx:+useconcmarksweepgc-xx:cmsfullgcsbeforecompaction=5-xx:+ Usecmscompactatfullcollection
-xx:cmsfullgcsbeforecompaction: Because the concurrent collector does not compress and defragment the memory space, it can produce "fragmentation" after a period of time, which makes the operation less efficient. This value sets how many times a GC is run to compress and defragment the memory space.
-xx:+usecmscompactatfullcollection: Turn on compression for older generations. Performance may be affected, but fragmentation can be eliminated
Http://www.51testing.com/html/77/268377-216345.html
GC Configuration Help for performance