Tomcat Memory and Optimization Chapter

Source: Internet
Author: User
Tags xms gc overhead limit exceeded

Tomcat Memory and optimization
Introduction of TOMCAT Operating environment
The 1.Tomcat itself cannot run directly on the computer and relies on the hardware-based operating system and the Java Virtual machine;
2.Java when the program starts, the JVM allocates an initial memory and maximum memory to the application;
3. When the application uses the maximum memory time, it will trigger the JVM to do garbage collection (GC) action, release the occupied memory;
4. Therefore, to adjust the initial memory and maximum memory when the Java program starts, you need to apply to the JVM;
5. If the initial memory size setting is too small and the application object is initialized too much at this time, the virtual machine must load memory repeatedly to satisfy the usage;
6. For the above reasons, it is best to set the initial memory size (XMS) and the maximum memory (XMX) to the same;
All objects on the 7.JVM allocate memory on the heap (heap) "" (also with memory allocated on "stack")
8. The size of the heap can be dynamically extended, but the size of "heap" "is limited by the physical memory used by the system, and when the application needs more memory than the maximum value of the heap, the JVM VM throws a memory overflow exception and causes the application to crash;
9. For the above reasons, it is recommended that the size of "heap" be set to 80% of physical memory

Two, Tomcat memory settings (for Linux)
1.<catalina_home>/bin/catalina.sh #路径以及修改内存的文件
2.java_opts= "-xms256m-xmx512m-xss1024k-xx:permsize=256m-xx:maxpermsize=512m" #内存参数以及值
3.-XMS: Initial Memory size
4.-XMX: Max Memory
5.-XSS: The amount of memory consumed by each thread (such as-xss15120, which consumes 15M of memory per additional thread), preferably 128K, and the default value is 512K
6.-xx:permsize: Set the initial size of the memory permanent save area, default is 64M (permanent refers to the method area, permanent generation, as well as young generation, old generation)
7.-xx:maxpermsize: Set the maximum size of the memory permanent save area, the default is 64M
8. Other parameters:
A)-xx:survivorratio=2: #生还者池的大小, default is 2, if garbage collection becomes a bottleneck, you can try customizing the Survivor pool settings
b)-xx:newsize: #新生成的池的初始大小, default is 2M
c)-xx:maxnewsize: #新生成的池的最大大小, default is 32M
d) +xx:aggressiveheap #该参数会使得Xms没有意义, this parameter allows the parameter JVM to ignore the XMX parameter, crazy to eat a g of physical memory, and then crazy to eat a G swap
e)-VERBOSE:GC #实现垃圾收集信息
f)-xloggc:gc.log #指定来及收集日志文件
g)-xmn: #年轻代的堆区大小, generally set to Xmx of 3, 4 points of one
h)-XX:+USEPARNEWGC #缩短minor收集时间 (minor GC refers to GC garbage collection actions triggered in younger generations)
I)-XX:+USECONCMARKSWEEPGC #缩短major收集的时间 (major collection refers to triggering full GC garbage collection actions in older generations), this option is in the heap size Relatively large and major collection time is more suitable for the use of the case
j)-XX:USERPARNEWGC #可用来并行收集 (multi-CPU)
k)-xx:parallergcthreads #可用来增加并行度 (multi-CPU)
L)-XX:USEPARALLERGC #设置后可以使用并行清理收集器 (multi-CPU)
m) if the JVM's heap size is larger than 1G, the following configuration should be used:
-xx:newsize=640m-xx:maxnewsize=640m-xx:survivorratio=16
or allocate 50% to 60% of the total size of the heap to the newly generated pool, and adjust the new object area to reduce the number of full GC times.
9. Note:
A) the "heap size" of the virtual machine determines the time and frequency at which the virtual machine spends collecting garbage;
b) If the "heap size" is large, then performing full GC garbage collection is slow, but the frequency is reduced;
c) If the "size of the heap" is smaller, performing full GC garbage recovery will be quick, but will be more frequent;
D) It is recommended to set the "heap size" to about 80% of physical memory
e) It is recommended to narrow the difference between the highest and lowest values of memory. Otherwise it will waste a lot of memory;
f) The minimum value increases, then the maximum value can be arbitrarily set;
g) But to be set based on actual physical memory and larger than physical memory, Tomcat will not start and may cause memory to be recovered by the system, terminating the process

III. TOMCAT memory Overflow and tuning
1. Java.lang.OutOfMemoryError:Java heap Space----JVM heap (heap) overflow
A) Interpretation:
1.JVM will automatically set the JVM heap value at boot time, its initial space (that is,-XMS) is 1/64 of physical memory, the maximum space (-XMX) can not exceed the physical memory;
2. You can use the-XMN-XMS-XMX provided by the JVM and other options to set up;
The size of the 3.heap is the sum of young Generation and old generation (tenured generaion);
4. This exception information is thrown in the JVM if 98% of the time is used for GC and the available heap size is less than 2%;

b) Resolve:
1. Manually set the size of the MaxPermSize
2.java_opts= "-server-xms256m-xmx512m-xx:permsize=64m-xx:maxpermsize=128m"

2. Java.lang.OutOfMemoryError:PermGen space----permgen space Overflow
A) Interpretation:
1.PermGen space is permanent Generation space, which means the permanent storage area of memory;
2. The reason for the memory overflow here is that this memory is primarily stored by the JVM with class and meta information, and class is placed in the PermGen space area at the moment of load;
The 3.PermGen space area differs from the heap area where the instance is stored, and GC does not clean up permgen space while the main program is running;
4. For the above reasons, if your app will load a lot of classes, it will likely appear permgen space overflow;

b) Resolve:
1. Manually set the MaxPermSize size

3.java.lang.stackoverflowerror----Stack Overflow
A) Interpretation:
1.JVM is a stack of virtual machines, the function of the call process is reflected in the stack and back stack;
2. Call the constructor "layer" too much, so that the stack area overflow;

b) Resolve:
1. Modify the program

4.AVA.LANG.OUTOFMEMORYERROR:GC Overhead limit exceeded

  A) This means that the JVM overflows

b) Add parameters,-xx:-usegcoverheadlimit, turn off this feature, and increase the heap size,-xmx1024m

Tomcat Memory and Optimization Chapter

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.