Parameter settings of jvm

The following configuration is mainly for the generational garbage collection algorithm.

 

heap size setting

The setting of the young generation is critical

The maximum heap size in the JVM is limited in three aspects: the data model (32-bit or 64-bit) limit of the relevant operating system; the system's available virtual memory limit; the system's available physical memory limit. Under the 32-bit system, it is generally limited to 1.5G~2G; 64 means that the operating system has no limit on the memory. In Windows Server 2003 system, 3.5G physical memory, tested under JDK5.0, the maximum can be set to 1478m.

Typical setup:

java-Xmx3550m -Xms3550m -Xmn2g–Xss128k  

-Xmx3550m: Set the maximum available memory of the JVM to 3550M.

-Xms3550m: Set the JVM to promote memory to 3550m. This value can be set the same as -Xmx to avoid reallocation of memory by the JVM after each garbage collection is complete.

-Xmn2g: Set the young generation size to 2G. Whole heap size = young generation size + old generation size + persistent generation size. The persistent generation is generally fixed at 64m, so after increasing the young generation, the size of the old generation will be reduced. This value has a great impact on system performance, and Sun officially recommends setting it to 3/8 of the entire heap.

-Xss128k: Set the stack size per thread. After JDK5.0, the stack size of each thread is 1M, and the previous stack size of each thread is 256K. Adjust the memory size required by the threads of the application. In the same physical memory, reducing this value can generate more threads. However, the operating system still has a limit on the number of threads in a process, which cannot be generated indefinitely, and the experience value is around 3000~5000.

 

java -Xmx3550m -Xms3550m -Xss128k-XX:NewRatio=4 -XX:SurvivorRatio=4 -XX:MaxPermSize=16m -XX:MaxTenuringThreshold=0 

-XX:NewRatio=4 : Set the ratio of young generation (including Eden and two Survivor areas) to old generation (excluding persistent generation). If it is set to 4, the ratio between the young generation and the old generation is 1:4, and the young generation accounts for 1/5 of the entire stack.

-XX:SurvivorRatio=4 : Set the size ratio of the Eden area to the Survivor area in the young generation. If set to 4, the ratio of two Survivor areas to one Eden area is 2:4, and one Survivor area accounts for 1/6 of the entire young generation.

-XX:MaxPermSize=16m: Set the persistent generation size to 16m.

-XX:MaxTenuringThreshold=0: Set the maximum age of garbage. If it is set to 0, the young generation objects directly enter the old generation without passing through the Survivor area. For applications with a large number of old generations, the efficiency can be improved. If this value is set to a larger value, the young generation object will be replicated multiple times in the Survivor area, which can increase the survival time of the object in the young generation and increase the generalization that it will be recycled in the young generation.

 

Recycler selection

JVM gives three choices: serial collector, parallel collector, concurrent collector , but serial collector is only suitable for small data volume, so the choices here are mainly for parallel collector and concurrent collector. By default, JDK5.0 used to use serial collectors. If you want to use other collectors, you need to add corresponding parameters at startup. After JDK5.0, the JVM will judge according to the current system configuration .

Throughput-first parallel collector

As mentioned above, the parallel collector mainly aims to achieve 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 a parallel collector. This configuration is only valid for the young generation. That is, under the above configuration, the young generation uses concurrent collection, while the old generation still uses serial collection.

-XX:ParallelGCThreads=20: Configure the number of threads for the parallel collector, that is, how many threads perform garbage collection together at the same time. 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 as parallel collection. JDK6.0 supports parallel collection of the old generation.

java -Xmx3550m -Xms3550m -Xmn2g -Xss128k -XX:+UseParallelGC -XX:MaxGCPauseMillis=100 

-XX:MaxGCPauseMillis=100 : Set the maximum time for each young generation garbage collection. If this time cannot be met, the JVM will automatically adjust the size of the young generation to meet this value.

n java -Xmx3550m -Xms3550m -Xmn2g -Xss128k -XX:+UseParallelGC  -XX:MaxGCPauseMillis=100-XX:+UseAdaptiveSizePolicy 

-XX:+UseAdaptiveSizePolicy : After setting this option, the parallel collector will automatically select the young generation area size and the corresponding Survivor area ratio to achieve the minimum corresponding time or collection frequency specified by the target system, etc. This value is recommended when using the parallel collector , always open.

 

Response time priority concurrent collector

As mentioned above, the concurrent collector is mainly to ensure the response time of the system and reduce the pause time during garbage collection. Applicable to application servers, telecommunication fields, etc.

Typical configuration:

java -Xmx3550m -Xms3550m -Xmn2g -Xss128k -XX:ParallelGCThreads=20-XX:+UseConcMarkSweepGC -XX:+UseParNewGC 

-XX:+UseConcMarkSweepGC: Set the old generation to concurrent collection. After configuring this in the test, the configuration of -XX:NewRatio=4 is invalid for unknown reasons. Therefore, the young generation size is best set with -Xmn at this time.

-XX:+UseParNewGC:  Set the young generation for parallel collection. Can be used concurrently with CMS collection. Above JDK5.0, the JVM will set itself according to the system configuration, so there is no need to set this value.

java -Xmx3550m -Xms3550m -Xmn2g -Xss128k -XX:+UseConcMarkSweepGC-XX:CMSFullGCsBeforeCompaction=5 -XX:+UseCMSCompactAtFullCollection 

-XX:CMSFullGCsBeforeCompaction: Since the concurrent collector does not compress and organize the memory space, it will generate "fragmentation" after running for a period of time, which reduces the running efficiency. This value sets how many times to compress and organize the memory space after running GC.

-XX:+UseCMSCompactAtFullCollection: Turn on compression for the old generation. May affect performance, but can eliminate fragmentation

 

Supplementary information

The JVM provides a large number of command-line parameters and print information for debugging. There are 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.0124630 secs] [GC [DefNew: 8614K->8614K(9088K), 0.0000 secs][Tenured: 112761K->10414K(121024K), 0.0433488 secs] 121376K->10414K(130112K), 0.0436268 secs]

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

-XX:+PrintGCApplicationConcurrentTime: Print the uninterrupted execution time of the program before each garbage collection. Can be mixed with the above. Output form: Application time: 0.5291524 seconds

-XX:+PrintGCApplicationStoppedTime: Prints the time the program was paused during garbage collection. Can be mixed with the above. Output form: Total time for which application threads were stopped: 0.0468229 seconds

-XX:PrintHeapAtGC:  Print detailed stack information before and after GC. Output form:

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: is used in conjunction with the above to record relevant log information to a file for analysis.

 

For example, the log of the jvm is written to the specified file: (to create such a file first)

/usr/java/jdk1.6.0_27/bin/java -XX:+PrintGCDetails -Xloggc:/var/log/java/jvm_attImport.log -Xms128m -Xmx512m -classpath ...

 

For example, write the error log of jvm to the specified file: (create such a file first)

/usr/java/jdk1.6.0_27/bin/java -Xms128m -Xmx512m -Xss64m -XX:PermSize=64m -XX:MaxPermSize=128m -XX:ErrorFile=/var/log/java/jvm_attImport_error.log -classpath ...

Guess you like

Origin http://10.200.1.11:23101/article/api/json?id=326942085&siteId=291194637