jvm parameters (transfer)

Reprinted from: http://blog.csdn.net/zsw1986/article/details/5434083
heap settings
-Xmx3550m: Set the maximum heap memory of the JVM to 3550M.
-Xms3550m: Set the JVM initial heap 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.
-Xss128k: Set the stack size for each thread. After JDK5.0, the stack size of each thread is 1M, and the size of each thread stack is 256K before. It should be adjusted according to the amount of memory 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.
-Xmn2g: Set the heap memory young generation size to 2G. The entire heap memory 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.
-XX:PermSize=256M: Set the initial value of the persistent generation of heap memory to 256M. (It seems to be the initialization parameter of IDE such as Eclipse)
-XX:MaxNewSize=size: The maximum memory size that a newly generated object can occupy.
-XX:MaxPermSize=512M: Set the maximum value of persistent generation to 512M.
-XX:NewRatio=4: Set the ratio of the young generation of heap memory (including Eden and two Survivor areas) to the old generation of heap memory (excluding the persistent generation). If it is set to 4, the ratio of the young generation to the old generation is 1:4.
-XX:SurvivorRatio=4: Sets the ratio of the size of the Eden area to the Survivor area in the young generation of the heap memory. If it is set to 4, the ratio of two Survivor areas (there are two Survivor areas in the young generation of JVM heap memory by default) and one Eden area is 2:4, and one Survivor area accounts for 1/6 of the entire young generation.
-XX:MaxTenuringThreshold=7: Indicates that if an object moves in the rescue space (Survivor area) 7 times and has not been reclaimed, it will be put into the old generation.
If it is set to 0, the young generation objects do not pass through the Survivor area and directly enter the old generation. For applications with many old generations, this can improve the efficiency.
If this value is set to a larger value, the young generation objects will be replicated multiple times in the Survivor area, which can increase the survival time of the objects in the young generation and increase the probability of the objects being 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 make intelligent judgments based on the current system configuration.

Serial collector
-XX:+UseSerialGC: Set serial collector
Parallel collector (throughput first)
-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.
-XX:+UseParallelOldGC: Configure the old generation garbage collection method as parallel collection. JDK6.0 supports parallel collection of the old generation.
-XX:MaxGCPauseMillis=100: Set the maximum time (in milliseconds) for each young generation garbage collection. If this time cannot be met, the JVM will automatically adjust the young generation size to meet this value.
-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 response time or collection frequency specified by the target system.
It is recommended to keep this parameter turned on when using the parallel collector.
Concurrent collector (response time priority)
-XX:+UseParNewGC: Set the young generation for concurrent 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.
CMS, the full name of Concurrent Low Pause Collector, is a new gc algorithm introduced in the later version of jdk1.4. It has been further improved in jdk5 and jdk6. It is mainly suitable for scenarios where the importance of response time is greater than the throughput requirement. , can bear the application of garbage collection thread and application thread sharing processor resources, and there are many objects with long life cycle in the application. CMS is used to recycle the tenured generation, that is, the old generation. The goal is to minimize the pause time of the application, reduce the probability of FullGC occurrence, and use the garbage collection thread concurrent with the application thread to mark and clear the old generation.
-XX:+UseConcMarkSweepGC: Set the old generation to concurrent collection. After configuring this in the test, the configuration of -XX:NewRatio=4 is invalid. Therefore, the young generation size is best set with -Xmn at this time.
-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 parameter is set to compress and organize the memory space after running FullGC.
-XX:+UseCMSCompactAtFullCollection: Turn on compression for the old generation. May affect performance, but memory fragmentation can be eliminated.
-XX:+CMSIncrementalMode: Set to incremental collection mode. Generally applicable to a single CPU situation.
-XX:CMSInitiatingOccupancyFraction=70: Indicates that CMS will be executed when the old generation space reaches 70% to ensure that the old generation has enough space to receive objects from the young generation.
Note: If you use both the throughput collector and the concurrent low pause collector, you need an appropriate high memory size to prepare for multithreading.

other
-XX:+ScavengeBeforeFullGC: The new generation GC takes precedence over the Full GC.
-XX:-DisableExplicitGC: Disable calling System.gc(), but the JVM's gc is still valid.
-XX:+MaxFDLimit: Maximize the limit on the number of file descriptors.
-XX:+UseThreadPriorities: Enables the native thread priority API, even if java.lang.Thread.setPriority() takes effect, and vice versa.
-XX:SoftRefLRUPolicyMSPerMB=0: "soft referenced" objects live for 0 milliseconds (default 1 second) after they were last accessed.
-XX:TargetSurvivorRatio=90: Allow 90% of Survivor space to be occupied (default is 50%). Increase the usage of Survivor - more than that will try garbage collection.
Supplementary information
-XX:-CITime: print time spent in JIT compilation
-XX:ErrorFile=./hs_err_pid.log: save the error log or data to the specified file
-XX:-ExtendedDTraceProbes: Enable solaris-specific dtrace probes
-XX:HeapDumpPath=./java_pid.hprof: Specify the path or file name when exporting heap information
-XX:-HeapDumpOnOutOfMemoryError: Export the relevant information in the heap when the memory overflow is encountered for the first time
-XX:OnError=";": run custom command after fatal ERROR
-XX:OnOutOfMemoryError=";": Execute a custom command when the memory overflow is encountered for the first time
-XX:-PrintClassHistogram: Print the columnar information of the class instance after encountering Ctrl-Break, the same function as jmap -histo
-XX:-PrintConcurrentLocks: Print information about concurrent locks after encountering Ctrl-Break, the same function as jstack -l
-XX:-PrintCommandLineFlags: Print the flags that appear on the command line
-XX:-PrintCompilation: print information when a method is compiled
-XX:-PrintGC: Print relevant information for each GC
-XX:-PrintGC Details: Print details on every GC
-XX:-PrintGCTimeStamps: Print the timestamp of each GC
-XX:-TraceClassLoading: Trace class loading information
-XX:-TraceClassLoadingPreorder: Trace the loading information of all classes that are referenced
-XX:-TraceClassResolution: trace constant pool
-XX:-TraceClassUnloading: Trace class unloading information
-XX:-TraceLoaderConstraints: Trace information about class loader constraints
JVM service tuning practice
Server: 8 cup, 8G mem

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

Tuning plan:

-Xmx5g: Set the maximum available memory of the JVM to 5G.
-Xms5g: Set the JVM initial memory to 5G. 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. The entire heap memory 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.
-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.
-XX:ParallelGCThreads=8: 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.
-XX:SurvivorRatio=6: Set the size ratio of the Eden area and the Survivor area in the young generation. According to experience, if it is set to 6, the ratio of two Survivor areas to one Eden area is 2:6, and one Survivor area accounts for 1/8 of the entire young generation.
-XX:MaxTenuringThreshold=30: Set the maximum age (number of times) of garbage. If set to 0, the young generation objects directly enter the old generation without going 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 probability of being recycled in the young generation. A setting of 30 means that an object will be placed in the old generation if it has not been collected after 30 moves in the Survivor space.
-XX:+UseConcMarkSweepGC: Set the old generation to concurrent collection. After testing and configuring this parameter, the parameter -XX:NewRatio=4 will be invalid. Therefore, it is best to use -Xmn to set the size of the young generation at this time, so this parameter is not recommended.
References - Generation of JVM heap memory
The heap memory of the virtual machine is divided into three generations: Young Generation, Old Generation, and Permanent Generation. The persistent generation mainly stores the class information of Java classes, which has little to do with the Java objects to be collected by the garbage collector. Therefore, the division between the young generation and the old generation has a greater impact on garbage collection.

young generation
All newly generated objects are placed in the young generation first. The goal of the young generation is to collect short-lived objects as quickly as possible. The young generation is divided into three districts. One Eden area, two Survivor areas (in general).

Most objects spawn in the Eden area. When the Eden area is full, the surviving objects will be copied to the Survivor area (one of the two), when one Survivor area is full, the surviving objects in this area will be copied to another Survivor area, when the other Survivor area When it is also full, the objects copied from the previous Survivor area and still alive at this time will be copied to the "Tenured" area.

It should be noted that the two Survivor areas are symmetrical and have no relationship, so there may be objects copied from the Eden area and objects copied from another Survivor area in the same Survivor area. An object from the Survivor area (relative). Also, one of the Survivor areas is always empty. In special cases, according to the needs of the program, the Survivor area can be configured as multiple (more than two), which can increase the existence time of objects in the young generation and reduce the possibility of being placed in the old generation.

old generation
Objects that survive N (configurable) garbage collections in the young generation are placed in the old generation. Therefore, it can be considered that some objects with a long life cycle are stored in the old generation.

Endurance
Used to store static data, such as Java Class, Method, etc. Persistent generation has no significant impact on garbage collection, but some applications may dynamically generate or call some classes, such as hibernate, etc. In this case, a relatively large persistent generation space needs to be set to store these dynamically increased types during operation. The persistent generation size is set with -XX:MaxPermSize=.

 

 

Guess you like

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