Tomcat memory overflow in Linux

Source: Internet
Author: User
Tags xms

Tomcat memory overflow in Linux

Tomcat itself cannot run directly on a computer. It depends on the operating system and a Java virtual machine. When the JAVA program starts, the JVM allocates an initial memory and the maximum memory to the APP. When the memory required by the APP exceeds the maximum memory size, the VM will prompt a memory overflow and cause the application service to crash.

I. There are three common Java memory overflow types:
1. java. lang. OutOfMemoryError: Java heap space (JVM Heap Overflow)
Explanation: The JVM Heap value is automatically set at startup. The JVM Heap setting refers to the setting of memory space that can be provisioned by JVM during java program running. The initial space is 1/64 of the physical memory by default, and the maximum space cannot exceed the physical memory. JVM provides options such as-Xmn-Xms-Xmx for configuration.

Error scenario: In JVM, if 98% of the time is used for GC and the available Heap size is less than 2%, JVM Heap overflow will occur.
Solution: Modify the JVM Heap size.

2. java. lang. OutOfMemoryError: PermGen space, that is, PermGen space overflow.
Explanation: PermGen space refers to the permanent storage area of the memory. This area mainly stores Class and Meta information. When a Class is loaded, it is placed in PermGen space.

Error scenario: If the APP loads many classes, PermGen space overflow may occur. (Because sun's GC will not clean up PermGen space when the program is running ). When the web server pre-compile the JSP
Solution: Modify the MaxPermSize.

3. java. lang. StackOverflowError indicates stack overflow.
Explanation: The JVM uses a stack-type virtual machine. The call process of functions is reflected in the stack and rollback.

Error scenario: the stack size is usually 1-2 MB. If too many "layers" are called for constructor, Stack Overflow may occur.
Solution: modify the program

Ii. Tomcat JVM memory overflow Solution
In the production environment, if tomcat memory is not properly configured, JVM memory overflow may easily occur. The solution is to modify the catalina. sh file in Tomcat.

In the catalina. sh file, locate cygwin = false and add parameters before this line, as shown below:
# Vi TOMCAT_HOME/bin/catalina. sh
JAVA_OPTS = "-server-Xms800m-Xmx800m-XX: PermSize = 256 m-XX: MaxPermSize = 512 m-XX: MaxNewSize = 512 m"

Other Instructions:
1. "m" indicates that the Unit is MB. Otherwise, the default value is KB.
2. Generally, 80% of the physical memory is used as the heap size.
3. Set-Xms to the same size as-Xmx.
4. Set-Xmn to 1/4 of the-Xmx value.
5. allocate 50% to 60% of the total heap size to the newly generated pool.

Iii. jvm parameter description:

-The server must be the first parameter to enable the JDK server version. It has good performance when multiple CPUs exist.
-The initial size of Xms java Heap. The default value is 1/64 of the physical memory.
-Maximum value of Xmx java heap. We recommend that you set the value to 80% of the physical memory. The physical memory cannot exceed.
-The minimum value of Xmn java heap is generally set to one of the 3 and 4 points of Xmx.
-XX: PermSize: Set the initial size of the permanent memory storage area. The default value is 64 MB.
-XX: MaxPermSize sets the maximum permanent memory size. The default value is 64 MB.
-XX: Required vorratio = 2. The default value is 2. If garbage collection becomes a bottleneck, you can customize the pool settings.
-XX: the initial size of the newly generated pool in NewSize. The default value is 2 MB.
-XX: the maximum size of the newly generated pool in MaxNewSize. The default value is 32 MB.
+ XX: AggressiveHeap allows the jvm to ignore the Xmx parameter, frantically eat a G physical memory, and then eat a G swap.
-Stack size of each Xss thread
-Verbose: gc real-time garbage collection information
-Xloggc: gc. log specifies the garbage collection log File
-XX: + UseParNewGC: shorten the minor collection time
-XX: + UseConcMarkSweepGC to shorten the major collection time
-XX: userParNewGC can be used to set parallel collection (multiple CPUs)
-XX: ParallelGCThreads can be used to increase the degree of parallelism (multiple CPUs)
-XX: After UseParallelGC is set, you can use parallel clearing collector (multiple CPUs)

Install JDK + Tomcat in RedHat Linux 5.5 and deploy Java Projects

Tomcat authoritative guide (second edition) (Chinese/English hd pdf + bookmarks)

Tomcat Security Configuration and Performance Optimization

How to Use Xshell to view Tomcat real-time logs with Chinese garbled characters in Linux

Install JDK and Tomcat in CentOS 64-bit and set the Tomcat Startup Procedure

Install Tomcat in CentOS 6.5

Tomcat details: click here
Tomcat: click here

This article permanently updates the link address:

Related Article

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.