jvm arguments detailed

For example, heap size common configuration settings
JVM heap size of the largest of three limitations: the data model related to the operating system (32-bt or 64-bit) limits; system available virtual memory limit; system available physical memory limit .32-bit system, generally limited to 1.5G ~ 2G; 64 for the operating system memory limit. I Windows Server 2003 systems, 3.5G physical memory, JDK5.0 tested, the maximum can be set to 1478m.
Typical settings:
-Xmx3550m: set the maximum JVM memory available for the 3550M.
-Xms3550m: Set JVM memory prompted 3550m. This value can be set with-Xmx the same, to avoid garbage collection after each JVM re-allocate memory.
-Xmn2g: set the size of the young generation of 2G. Younger generation of the heap size = size + size + lasting on behalf of the elderly on behalf of the size. Persistence on behalf of the general fixed size of 64m, so increasing the young generations, will reduce the size of the elderly on behalf of the . This value greater impact on system performance, Sun officially recommended configuration for the whole heap of 3 / 8.
-Xss128k: Set each thread stack size. JDK5.0 after each thread stack size 1M, before each thread stack size is 256K. More application memory size required to adjust the thread. In the same physical memory, the reduce this value to generate more threads. but the operating system on the number of threads within a process is limited, not infinite generation, the experience value is about 3000 ~ 5000.

java-Xmx3550m-Xms3550m-Xss128k-XX: NewRatio = 4-XX: SurvivorRatio = 4-XX: MaxPermSize = 16m-XX: MaxTenuringThreshold = 0
-XX: NewRatio = 4: set the younger generation (including Eden and two Survivor District) and the ratio of older generation (except sustained generation). Is set to 4, then the younger generation and old generation of the share ratio of 1:4, Young on behalf of the whole stack of 1 / 5
-XX: SurvivorRatio = 4: set the younger generation of the Eden area the size of the area and the ratio of Survivor. Is set to 4, the two Survivor Eden district area and a ratio of 2:4, a Survivor region and the younger generation 1 / 6
-XX: MaxPermSize = 16m: Set Persistent generation of size 16m.
-XX: MaxTenuringThreshold = 0: Set the maximum age of garbage. If set to 0, then the younger generation of the object without Survivor areas, directly into the old generation of. For the old generation of more and more applications can improve efficiency. If this value set to a large value, the young generation of the object will be copied many times in the Survivor areas, such objects can increase survival time and then the young generation, increasing recycling in the younger generation of Jibei Introduction.
Collector choice
JVM given three choices: serial collector, parallel collector, concurrent collector, but the serial collector is only applicable to the case of small amounts of data, so the choice here, the main collector for parallel and concurrent collectors. By default Next, JDK5.0 ago are using the serial collector, if you want to use other collectors need to start adding the appropriate parameters. JDK5.0 later, JVM will be judged according to the current system configuration.
Priority throughput parallel collector noted above, the parallel collector main to reach a certain target throughput for science and technology and back-office processing.
Typical configuration:
java-Xmx3800m-Xms3800m-Xmn2g-Xss128k-XX: + UseParallelGC-XX: ParallelGCThreads = 20
-XX: + UseParallelGC: Select garbage collector for the concurrent collector. This configuration only for the young generation of effective. That the above configuration, the younger generation of concurrent collection to use, while still using the old generation of the serial collection.
-XX: ParallelGCThreads = 20: Configure the parallel collector threads, namely: the number of threads together at the same time garbage collection. This value is equal to the best configuration with the number of processors.

java-Xmx3550m-Xms3550m-Xmn2g-Xss128k-XX: + UseParallelGC-XX: ParallelGCThreads = 20-XX: + UseParallelOldGC
-XX: + UseParallelOldGC: Configure the elderly on behalf of the garbage collection method for parallel collection. JDK6.0 support for the elderly on behalf of the parallel collection.

java-Xmx3550m-Xms3550m-Xmn2g-Xss128k-XX: + UseParallelGC-XX: MaxGCPauseMillis = 100
-XX: MaxGCPauseMillis = 100: set the garbage collection every time the young generation of the most time, if you can not meet this time, JVM will automatically adjust the younger generation of size, to meet this value.

java-Xmx3550m-Xms3550m-Xmn2g-Xss128k-XX: + UseParallelGC-XX: MaxGCPauseMillis = 100-XX: + UseAdaptiveSizePolicy
-XX: + UseAdaptiveSizePolicy: Setting this option will automatically select the parallel collection of the young generation of district size and the corresponding ratio of Survivor areas in order to achieve the minimum target system or a collection frequency of the corresponding time, this value is recommended to use the parallel collector when left open.

Priority response time of concurrent collector noted above, concurrent collector is mainly to ensure the system response time, reduce garbage collection pause time when. Applicable to the application server, telecommunications and other fields.
Typical configuration:
java-Xmx3550m-Xms3550m-Xmn2g-Xss128k-XX: ParallelGCThreads = 20-XX: + UseConcMarkSweepGC-XX: + UseParNewGC
-XX: + UseConcMarkSweepGC: set the old, took the concurrent collection. Test configure this later,-XX: NewRatio = 4 configuration fails, for unknown reasons. So, this time with the young generation of the size of the best set-Xmn.
-XX: + UseParNewGC: Set Young took the parallel collection. Can be used in conjunction with the CMS to collect. JDK5.0 or above, JVM itself according to system configuration settings, so no need to set this value.
java-Xmx3550m-Xms3550m-Xmn2g-Xss128k-XX: + UseConcMarkSweepGC-XX: CMSFullGCsBeforeCompaction = 5-XX: + UseCMSCompactAtFullCollection
-XX: CMSFullGCsBeforeCompaction: As the concurrent collector does not compress memory, sorting, and so run over time will have a "debris", makes the efficiency lower. How many times this value is set to run the GC after the compression of memory space, sorting.
-XX: + UseCMSCompactAtFullCollection: Open to the old generation of compression. May affect performance, but you can remove debris

Supplementary information
JVM provides a large number of command line arguments, print the information for debugging. Mainly the following:
-XX: + PrintGC
Output format: [GC 118250K-> 113543K (130112K), 0.0094143 secs]
[Full GC 121376K-> 10414K (130112K), 0.0650971 secs]

-XX: + PrintGCDetails
Output format: [GC [DefNew: 8614K-> 781K (9088K), 0.0123035 secs] 118250K-> 113543K (130112K), 0.0124633 secs]
[GC [DefNew: 8614K-> 8614K (9088K), 0.0000665 secs] [Tenured: 112761K-> 10414K (121024K), 0.0433488 secs] 121376K-> 10414K (130112K), 0.0436268 secs]

-XX: + PrintGCTimeStamps-XX: + PrintGC: PrintGCTimeStamps can be mixed with the output of the above two forms: 11.851: [GC 98328K-> 93620K (130112K), 0.0082960 secs]

-XX: + PrintGCApplicationConcurrentTime: print before every garbage collection, the program does not interrupt the execution time. Can be mixed with the above output forms: Application time: 0.5291524 seconds

-XX: + PrintGCApplicationStoppedTime: printing garbage collection pause time during the procedure. Can be mixed with the above output format: Total time for which application threads were stopped: 0.0468229 seconds

-XX: PrintHeapAtGC: GC before and after printing out a detailed form of the stack information:
34.702: [GC (Heap before gc invocations = 7:
def new generation total 55296K, used 52568K [0x1ebd0000, 0x227d0000, 0x227d0000)
eden space 49152K, 99% used [0x1ebd0000, 0x21bce430, 0x21bd0000)
from space 6144K, 55% used [0x221d0000, 0x22527e10, 0x227d0000)
to space 6144K, 0% used [0x21bd0000, 0x21bd0000, 0x221d0000)
tenured generation total 69632K, used 2696K [0x227d0000, 0x26bd0000, 0x26bd0000)
the space 69632K, 3% used [0x227d0000, 0x22a720f8, 0x22a72200, 0x26bd0000)
compacting perm gen total 8192K, used 2898K [0x26bd0000, 0x273d0000, 0x2abd0000)
the space 8192K, 35% used [0x26bd0000, 0x26ea4ba8, 0x26ea4c00, 0x273d0000)
ro space 8192K, 66% used [0x2abd0000, 0x2b12bcc0, 0x2b12be00, 0x2b3d0000)
rw space 12288K, 46% used [0x2b3d0000, 0x2b972060, 0x2b972200, 0x2bfd0000)
34.735: [DefNew: 52568K-> 3433K (55296K), 0.0072126 secs] 55264K-> 6615K (124928K) Heap after gc invocations = 8:
def new generation total 55296K, used 3433K [0x1ebd0000, 0x227d0000, 0x227d0000)
eden space 49152K, 0% used [0x1ebd0000, 0x1ebd0000, 0x21bd0000)
from space 6144K, 55% used [0x21bd0000, 0x21f2a5e8, 0x221d0000)
to space 6144K, 0% used [0x221d0000, 0x221d0000, 0x227d0000)
tenured generation total 69632K, used 3182K [0x227d0000, 0x26bd0000, 0x26bd0000)
the space 69632K, 4% used [0x227d0000, 0x22aeb958, 0x22aeba00, 0x26bd0000)
compacting perm gen total 8192K, used 2898K [0x26bd0000, 0x273d0000, 0x2abd0000)
the space 8192K, 35% used [0x26bd0000, 0x26ea4ba8, 0x26ea4c00, 0x273d0000)
ro space 8192K, 66% used [0x2abd0000, 0x2b12bcc0, 0x2b12be00, 0x2b3d0000)
rw space 12288K, 46% used [0x2b3d0000, 0x2b972060, 0x2b972200, 0x2bfd0000)
, 0.0757599 secs]

-Xloggc: filename: used in conjunction with several above, the relevant information recorded in the log file for analysis.
Summary heap common configuration settings
-Xms: Initial heap size
-Xmx: maximum heap size
-XX: NewSize = n: Set the size of the young generation of
-XX: NewRatio = n: Set the young generation and old generation ratio. Such as: 3, that the young generation and old generation of the ratio of 1:3, the younger generation of accounting for the younger generation of old generation and the 1 / 4
-XX: SurvivorRatio = n: the young generation of Eden district area and the ratio of the two Survivor. NOTE Survivor District has two. Such as: 3, said Eden: Survivor = 3:2, a Survivor region and the younger generation 1 / 5
-XX: MaxPermSize = n: set up a lasting collection of settings on behalf of the size of
-XX: + UseSerialGC: Set the serial collector
-XX: + UseParallelGC: Set the parallel collector
-XX: + UseParalledlOldGC: Set the parallel old generation of collectors
-XX: + UseConcMarkSweepGC: set the concurrent garbage collector statistics
-XX: + PrintGC
-XX: + PrintGCDetails
-XX: + PrintGCTimeStamps
-Xloggc: filename
Parallel collector set
-XX: ParallelGCThreads = n: Set the parallel collector to collect the number of CPU used. Parallel collection of threads.
-XX: MaxGCPauseMillis = n: set the maximum suspension time concurrent collection
-XX: GCTimeRatio = n: set the garbage collection time, the percentage of total run time. Formula is 1 / (1 + n)
Concurrent collector set
-XX: + CMSIncrementalMode: set to increment mode. For single CPU case.
-XX: ParallelGCThreads = n: set the concurrent collector to collect the young generation of methods for the parallel collection, use the CPU number. Parallel collection of threads.

Summary tuning the size of the young generation of selection
Xiang Ying Time priority application : Make the best were great towards the close System Minimum response time limit (Genjushiji situation Xuanze). Zai such cases, the frequency of occurrence of the young Dai Shouji is Zuixiao's. Meanwhile, on behalf of reaching the Nianlao object.
Throughput priority of application: as much as possible to set up large, may reach a degree of Gbit. Because there is no response time requirements, garbage collection can be carried out in parallel, the general application of the above for 8CPU.
Select the size of the elderly on behalf of the priority application response time: the elderly on behalf of the use of concurrent collector, so need to be careful to set the size of the general session to consider the concurrent rate and session duration time of some parameters. If you set a small heap, and can cause memory debris, high recovery frequency, and application to suspend the use of traditional markers clear the way; if the big stack, you need a longer collection time. optimization program, the general need to refer to the following data obtained:
Concurrent garbage collection information persistence on behalf of the concurrent collection of information on the number of traditional GC spent on behalf of the young generation and old to reduce the proportion of time the recovery of the young generation and old generation of the time, usually to improve the efficiency of application

Application priority throughput: throughput of the priority application of the general have a great young generation and old generation of a smaller. The reason is that it can recover as much as possible out most of the short-term target to reduce the medium-term targets, while in long-term survival of the old store on behalf of every object.
Small heap of debris caused because the old generation concurrent collector uses tags, clear algorithm, so it will not compress heap. When the collector recovery, he will merge the adjacent space, this can be allocated to more large objects. However, when the heap space is small, the run for some time, there will be "debris" if concurrent collector can not find enough space, then the concurrent collector will stop, and then use the traditional labeling, clear approach to recovery. If a "debris", may require the following configuration:
-XX: + UseCMSCompactAtFullCollection: use the concurrent collector, the opening of the old generation of compression.
-XX: CMSFullGCsBeforeCompaction = 0: The above configuration to open the case, where the number of Full GC after setting on the old generation of compressed

Under the same project, there are two classes, two classes only a few changes, and the most relevant point health of FOR did not change, but when I run these two programs, respectively, when they see a very serious problem, a program cycle faster, a cycle of slow. This is how the matter in the end it ~??? hard to find for a long time had no idea why, because the procedure to change the part of the root does not affect the speed of my cycle, but the results is very different, one about a minute it can within the complete cycle, but it takes another 67 minutes, this is simply not a reasonable level of anesthesia data. two exactly the same cycle, from code on fundamentally do not see any problem. it may not help my colleagues, but my colleagues also feel weird seeing two people in that set with the code and looking at more than an hour, finally I come to a clean and colleagues point, shutdown restart. I also listen to on the meaning of my colleagues went down, this time of shutdown may suddenly said he was not a memory problem, I thought of an empty course, really the problem may be memory, Because fast that before I can run the program before had 1G of memory ah, but then I seem to have this memory set too, ah, the machine up, go in at once with this idea, the results hit the nail, is really a slow memory that does not open, the program runs only open the default JVM memory. My initial analysis is that the memory is too small, and my program with the memory card has just opened in the JVM memory by side, and will not overflow. When program runs would cost to most of the time to call GC, thus leading to the same cycle of why the efficiency of two different ~!
Incidentally, the memory usage of the method is also posted:
public static String getMemUsage () (
long free = java.lang.Runtime.getRuntime (). freeMemory ();
long total = java.lang.Runtime.getRuntime (). totalMemory ();
StringBuffer buf = new StringBuffer ();
buf.append ("[Mem: used"). append ((total-free)>> 20)
. Append ("M free"). Append (free>> 20)
. Append ("M total"). Append (total>> 20). Append ("M]");
return buf.toString ();

google what probably say this is to operate the JVM memory:
Heap (Heap) and non-heap (Non-heap) memory according to the official statement: "Java virtual machine has a heap, the heap is the runtime data area, all class instances and arrays of memory are allocated from here. Heap in the Java Virtual created when the machine starts. "" outside the JVM heap memory in the heap memory as non-(Non-heap memory) ". JVM key management can be seen two types of memory: heap and non-heap. short stack is the Java code and the memory is reserved for developers to use; non-JVM heap is left to their own use, so methods that, JVM internal processing or optimization of memory required (such as JIT compiled code cache), each a class structure (such as the number of pool running times, fields and methods of data) as well as methods and constructor code in non-heap memory.
Heap memory allocation
Initial allocation of memory from the JVM-Xms specified, the default is the physical memory of 1 / 64; JVM maximum memory allocated by the-Xmx specified, the default is the physical memory of 1 / 4. Default heap memory is less than 40% spare time, JVM will increase until the-Xmx maximum heap limit; spare more than 70% of heap memory, JVM heap will be reduced until the minimum-Xms restrictions. so the server generally set-Xms,-Xmx equal to avoid adjustments after each GC heap size.
Non-heap memory allocation
JVM using the-XX: PermSize set the initial value of non-heap memory, the default is the physical memory of 1 / 64; by the XX: MaxPermSize set the maximum size of non-heap memory, the default is the physical memory of 1 / 4.
JVM memory limit (max)
First of all, first of all JVM memory is limited by the actual maximum physical memory, assuming that physical memory is infinite, then, JVM maximum memory relationship with a great operating system. Simply put, the 32-bit processors, although the control memory space of 4GB, but give a specific operating system restrictions, the restrictions generally 2GB-3GB (generally Windows systems for the 1.5G-2G, Linux systems for the 2G-3G), while the 64bit processor would not have more than limited
JVM memory tuning
1. Heap garbage collection Java Heap settings and is divided into three areas, Young, Old and Permanent.Young save just instantiate the object. When the area is filled, GC will move objects Old District. Permanent area is responsible for keeping reflective object, this article does not discuss the area. JVM's Heap allocation can use the-X parameter settings,
Initial Heap Size
java heap max
young generation of the heap size
There are 2 JVM GC thread. The first thread is responsible for recovery of the Young area Heap. The second thread in the Heap insufficient, traversing Heap, will be Young, upgrade Older area. Older zone size is equal to-Xmx minus the-Xmn, can not the value of the-Xms set too large, because the second thread was forced to run will reduce the performance of JVM.
Why do some programs frequent GC? The following reasons:
l protocol calls System.gc () or Runtime.gc ().
l Some middleware GC method calls itself, then need to set parameters against these GC.
l Java's Heap too small, the Heap general default values are very small.
l frequent instances of objects, Release the object. then save and reuse as much as possible targets, such as the use StringBuffer () and String ().
If you find that after each GC, Heap the remaining space will be 50% of the total space, which means that your Heap is healthy. Many Server-side Java programs preferably after each GC, 65% of the remaining space. Experience Discussion:
1. Server-side JVM is best to set-Xms and-Xmx the same value. To optimize the GC, the best so-Xmn-Xmx value is approximately equal to 1 / 3 [2].
2. A GUI program is best to every 10 to 20 seconds to run a GC, each time half a second to complete [2].
1. Heap size of the increase will reduce the GC, although the frequency, but also increases the time for each GC. And the GC runs, all user threads will be suspended, that is, during the GC, Java applications do not do any work.
2. Heap size does not determine the memory usage of the process. The process of memory usage is greater than the value of-Xmx defined as Java to allocate memory for other tasks, such as Stack and so on for each thread.
2. Stack set for each thread has his own Stack.
Stack size per thread
Stack size limits the number of threads. If too much like Stack cause memory leakage .- Xss parameter determines Stack size, for example-Xss1024K. If the Stack is too small, can lead to Stack spills.
3. Hardware environment also affects the GC hardware environment of efficiency, such as machine type, memory, swap space, and the number of CPU.
If your program needs often create a lot of transient objects will lead to frequent JVM GC. This can increase your machine's memory, to reduce the use of Swap space [2].
4.4 kinds of GC
The first one is single-threaded GC, is the default GC., The GC for single CPU machines.
The second is Throughput GC, is a multi-threaded GC, for multi-CPU, a large number of threads to use the procedure. The second and the first GC GC similar to the difference between a GC Young area in the collection is multi-threaded, but in the Old area and the first, still use single-threaded .- XX: + UseParallelGC Start up the GC.
Third for the Concurrent Low Pause GC, similar to the first one, suitable for multi-CPU, and to lessen the resulting procedures GC stagnation due to the time. This GC can be recovered in the Old District, at the same time, run the application .- XX: + UseConcMarkSweepGC Start up the GC.
Fourth for the Incremental Low Pause GC, for applications that require shorter procedures because of stagnation caused by the time GC. This GC can be recovered in the Young area, while recovery of part of the Old District objects .- Xincgc Start up the GC.
4 GC specific description, see [3].

分类:Java 时间:2010-06-09 人气:304
blog comments powered by Disqus


iOS 开发

Android 开发

Python 开发



PHP 开发

Ruby 开发






Javascript 开发

.NET 开发



Copyright (C) codeweblog.com, All Rights Reserved.

CodeWeblog.com 版权所有 闽ICP备15018612号

processed in 0.222 (s). 12 q(s)