A brief introduction: Today we talk about JVM memory tuning
Two basic theories:
1 Basic concepts of JVM heap (heap):
1 for most applications, the Java heap (Java heap) is the largest piece of memory managed by a Java virtual machine. The Java heap is a piece of memory that is shared by all threads and created when the virtual machine is started. The only purpose of this area of memory is to hold object instances where almost all of the object instances are allocated memory.
2 The Java heap is the main area of garbage collector management, so it is often called a "gc heap". In the case of memory recycling, since the collector is basically a generational collection algorithm,
2 constituent Members
1 Cenozoic
2 old age
3 Related parameters
-XMX (JVM allocates heap max memory)-xms (the JVM initially allocates heap memory)
4 Configuration Error Cases
A OutOfMemoryError exception will be thrown.
1 JVM non-heap (NO-HEAP) Basic concepts
The method area, like the Java heap, is an area of memory shared by each thread that stores data such as class information, constants, static variables, and code compiled by the immediate compiler that have been loaded by the virtual machine.
2 constituent Members
1 Permanent Generations
3 Related parameters
PermSize (JVM initialization allocated non-heap size) MaxPermSize (non-heap size of JVM max Shards)
1 JVM Direct Memory mapping Basic concepts
This concept is about the introduction of Java NIO (memory-mapped files), which allocates memory directly in a native way, and is not managed by the JVM. This is done in order to improve the efficiency of the network and file IO and avoid unnecessary memory duplication.
2 Related parameters
Maxdirectmemorysize (Default 64m)
Three related explanations
1 According to the official statement, "Java virtual machines have a heap, the heap is a runtime data region, and all class instances and arrays of memory are allocated from here." The heap is created when the Java virtual machine is started. "" The memory outside the heap in the JVM is called non-heap (non-heap memory) ".
You can see that the JVM primarily manages two types of memory: heap and non-heap. Simply put, the heap is the Java code of memory, is left to developers to use, non-heap is the JVM left to use,
Therefore, the code for the method area, internal processing or optimization of the JVM, such as the JIT-compiled code cache, and each class structure (such as the run-time pool, field, and method data), as well as the methods and construction methods, are in non-heap memory
2 Heap Memory Allocations
The initial allocated heap memory of the JVM is specified by-XMS, and the default is the maximum allocated heap memory for 1/64;JVM of physical memory specified by-XMX, which defaults to 1/4 of the physical memory. When the default free heap memory is less than 40%, the JVM will increase the heap until the maximum limit of-xmx;
When free heap memory is greater than 70%, the JVM will reduce the heap until the minimum limit of-XMS. So the server generally sets-xms,-xmx equal to avoid resizing the heap after each GC.
Description: Application may cause java.lang.OutOfMemory error if-XMX is not specified or is specified as small
3 non-heap memory allocations
The JVM uses-xx:permsize to set the non-heap memory initial value, which defaults to 1/64 of the physical memory, and the maximum non-heap memory by Xx:maxpermsize, which by default is 1/4 of physical memory. Xx:maxpermsize setting too small will cause Java.lang.OutOfMemoryErro
4 Direct Map Assignment
The default size of the Directmemory is 64m and does not accept JVM memory management, preferably setting the maximum memory value
Five MYCAT related recommendations
It is recommended that heap memory be moderately sized, directly mapped to memory as large as possible, and that both occupy the operating system's 1/2-2/3 memory.
The following server 16G memory for example, Mycat heap memory 4G, non-heap memory 64m Direct Memory map 6G,JVM parameters such as
-SERVER-XMS4G–XMX4G xx:maxpermsize=64m-xx:maxdirectmemorysize=6g
This is how I feel about the Java JVM Tuning, not developing really difficult, for reference only
Six JVM common commands
1 jmap-heap PID View GC usage (JDK1.7)
MySQL 31st article ~JVM Knowledge and optimization