JVM tuning experience (not necessarily accurate)
1. Overall thinking:
It is normal for Young GC to occur frequently, but try to make it take less time for a single execution.
The frequency of Full GC should not be too high
two。 Monitoring commands used:
Jps-m-l lists the status information of processes running in JVM (here you can get the pid of a process for use by subsequent commands)
Jstat-gcutil pid 10s 3 performs real-time command line statistics on heap memory usage, gc information, etc.
3. The specific setting parameters are as follows:
-Xms,-Xmx
These two parameters must be set and must be set to be equal, and the default values cannot be used. If not set, there may be frequent Full GC, memory leaks.
Set to equal, mainly to avoid reallocating heap memory after each GC.
In addition, these two values should not be set too high. Although it is recommended that the maximum value of the heap be set to 80% of the maximum available memory (use the command free or cat / proc/meminfo to view the actual available physical memory = free+buffer+cache), after setting 80%, the memory footprint of the server is generally more than 90%, so it can be reduced a little bit.
-Xmn,-XX:SurvivorRatio
It is best not to use-XX:NewRatio, because it will fail when used with CMS GC.
If you do not set this value and CMS GC, then the ratio of the younger generation to the older generation is about 1:2
If you do not set this value and set CMS GC, then the younger generation will become very young and the elder will account for a large proportion.
If the Young Generation size allocation is unreasonable or the space is relatively small, it is easy for the object to enter the Old Generation. For example, if S0 and S1 are too small to hold the surviving objects after the gc, it will directly enter the older generation, while the recovery speed of specific objects in Old Generation is much lower than that of Young Generation.
To consider the ratio of the older generation to the new generation (officially recommended by sun-Xmn is 3 gambit 8 for the entire heap), consider the ratio of Eden to survives (the default is 8:1:1)
If you don't know how much to set, you can first set it according to official requirements, and then adjust it if it is not appropriate.
Whether or not to use CMS GC.
Other parameters are set on a case-by-case basis. Note that performance may not be improved after they are set. Different application systems and different computer hardware conditions may be different.