tuning needs to focus on several aspects of memory tuning CPU using tuning lock competitive tuning I/O Tuning Fundamentals:
The number of objects to be transferred to the old age is minimized. Reduce the execution time of full GC. The goal is to minor GC time within 100MS and full gc time within 1s.
Main tuning Parameters:
Set the heap memory size, which is the most basic. -XMS: Heap memory space When the JVM is started. -XMX: Maximum heap memory limit.
Sets the Cenozoic size.
The new generation should not be too small, otherwise there will be a large number of objects pouring into the old age. -xx:newratio: The proportion of the new generation and the old age. -xx:newsize: Cenozoic space. -xx:survivorratio: The proportion of Eden space and survivor space. -xx:maxtenuringthreshold: Age threshold for objects entering the old age.
Setting up the garbage collector
Young generation:-XX:+USEPARNEWGC.
Old age:-XX:+USECONCMARKSWEEPGC.
CMS can minimize STW time, but does not compress memory, there is a possibility of "parallel mode failure". For example, the old age space has 300MB space, but some 10MB objects cannot be stored sequentially. Compression processing is triggered, but the compression processing time in CMS GC mode is much longer than the parallel GC.
G1 uses the "mark-and-organize" algorithm to solve the memory fragmentation problem and establish a predictable pause-time type, which allows the user to specify a time period of M milliseconds to consume less than n milliseconds for garbage collection.
Memory usage Tuning
OutOfMemoryError exception Reason: May be true data volume is too large, may want to display too much data, possible memory leaks
Data volume is too large to observe and solve: Look at the GC log, see memory changes before and after full GC, changes do not indicate that the amount of data is too large to try to increase the JVM's memory usage consider whether the data really needs to be in memory. can be considered using: LRU algorithm swap out and so on, weak references (Soft References)