Linux/centos solves Tomcat memory overflow

  
Tomcat itself can not run directly on the computer, it depends on the operating system and a JAVA virtual machine. When the JAVA program starts, the JVM allocates an initial memory and maximum memory to the APP. When the memory required by the APP exceeds the maximum memory, the virtual machine will prompt for memory overflow and cause the application service to crash. First, the common Java memory overflow has the following three:

1. java.lang.OutOfMemoryError: Java heap space JVM Heap overflow
Explanation: JVM will automatically set the value of JVM Heap when starting, JVM The heap setting refers to the setting of the memory space that the JVM can use during the running of the java program. The initial space defaults to 1/64 of physical memory, and the maximum space cannot exceed physical memory. The JVM provides options such as -Xmn -Xms -Xmx for setting. Error scenario: In the JVM, if 98% of the time is for GC and the available Heap size is less than 2%, the JVM Heap overflow resolution will occur: modify the size of the JVM Heap. 2. java.lang.OutOfMemoryError: PermGen space ie PermGen space overflow

Explanation: PermGen space refers to the permanent storage area of ​​memory. This area mainly stores Class and Meta information, and Class will be put into PermGen space when it is loaded.
Error scenario: If the app loads a lot of CLASS, PermGen space overflow may occur. (Because sun's GC does not clean up PermGen space while the program is running) Commonly when the web server precompiles the JSP Solution: Modify the MaxPermSize size

3. java.lang.StackOverflowError stack overflow
Explanation: The JVM uses a stack of virtual machines, and the calling process of functions is reflected on the stack and the unstack. Error scenario: Usually the size of the stack is 1-2MB. If the constructor's "layer" is too much, there will be a stack overflow solution: modify the program 2. Tomcat's JVM memory overflow solution is in the production environment. Tomcat memory settings are not easy to appear JVM memory overflow, the solution is to modify the catalina.sh file in Tomcat.

In the catalina.sh file, find cygwin=false, add the parameters in front of this line, as follows
# vi TOMCAT_HOME/bin/catalina.shJAVA_OPTS="-server -Xms800m -Xmx800m -XX:PermSize =256m -XX:MaxPermSize=512m -XX:MaxNewSize=512m"Other notes: 1.<quo;m” indicates that the unit is MB, otherwise the default is KB2. Generally use 80% of physical memory as the heap size 3. Generally put -Xms It is set to be as large as -Xmx. 4. Generally set -Xmn to 1/45 of -Xmx value. Generally, allocate 50% to 60% of the total size of the heap to the newly generated pool. 3. jvm Parameter Description: -server To be the first parameter, enable the JDK server version, which performs well on multiple CPUs - the initial size of the Xms java Heap. The default is 1/64 of physical memory. -Xmx java heap maximum. The recommendations are set to 80% of physical memory. Do not exceed physical memory. -Xmn java heap minimum, generally set to 3 or 4 of Xmx. -XX:PermSize Sets the initial size of the permanent storage area of ​​the memory. The default value is 64M. -XX:MaxPermSize Sets the maximum size of the permanent save area of ​​the memory. The default value is 64M. -XX:SurvivorRatio=2 The size of the survivor pool. The default is 2. For example, -XX:NewSize the initial size of the newly generated pool. The default is 2M. -XX:MaxNewSize The maximum size of the newly generated pool. The default is 32M. +XX: AggressiveHeap Let jvm ignore the Xmx parameter, frantically eat a G physical memory, and then eat a G swap. -Xss Stack size per thread - verbose:gc Real garbage collection information - Xloggc:gc.log Specify garbage collection log file -XX:+UseParNewGC Reduce minor collection time -XX:+UseConcMarkSweepGC Reduce major collection time -XX: userParNewGC can be used to set parallel collection (multiple CPU) - XX: ParallelGCThreads can be used to increase parallelism (multiple CPU) - XX: UseParallelGC can be set to use parallel cleanup collector (multiple CPU)

Copyright © Windows knowledge All Rights Reserved