Linux/centos solves Tomcat memory overflow, centostomcat

Source: Internet
Author: User

Linux/centos solves Tomcat memory overflow, centostomcat
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 does not clean the PermGen space when the program is running) It is common 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. For example
-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)
TOMCAT memory overflow error

First try this:
-Xms64m
-Xmx256m
-XX: PermSize = 128 M
-XX: MaxNewSize = 256 m
-XX: MaxPermSize = 256 m

Below are two articles

Answer 1
Set the initial memory for Tomcat startup
The initial space (-Xms) is 1/64 of the physical memory, and the maximum space (-Xmx) is 1/4 of the physical memory. You can use options such as-Xmn-Xms-Xmx provided by JVM.
Set
Iii. Example:
JAVA_OPTS = "-server-Xms800m-Xmx800m-XX: PermSize = 64 M-XX: MaxNewSize = 256 m-XX: MaxPermSize = 128 m-Djava. awt. headless = true"
JAVA_OPTS = "-server-Xms768m-Xmx768m-XX: PermSize = 128 m-XX: MaxPermSize = 256 m-XX:
NewSize = 192 m-XX: MaxNewSize = 384 m"
CATALINA_OPTS = "-server-Xms768m-Xmx768m-XX: PermSize = 128 m-XX: MaxPermSize = 256 m
-XX: NewSize = 192 m-XX: MaxNewSize = 384 m"
Linux:
Catalina. sh in the/usr/local/apache-tomcat-5.5.23/bin directory
Add: JAVA_OPTS = '-Xms512m-xmx1024m'
If "m" is added, it indicates that it is MB. Otherwise, it is KB. When tomcat is started, insufficient memory is reported.
-Xms: Initial Value
-Xmx: Maximum Value
-Xmn: Minimum value
Windows
Add at the beginning of catalina. bat
Set JAVA_OPTS =-Xms128m-Xmx350m
If you start tomcat with startup. bat, the OK setting takes effect. The memory is allocated MB.
However, if you do not execute startup. bat to start tomcat, but use the windows System Service to start the tomcat service, the above settings will not take effect,
That is to say, set JAVA_OPTS =-Xms128m-Xmx350m does not work. The above allocated M memory will become OOM ..
The windows service executes bin \ tomcat.exe. It reads the value in the registry, instead of setting catalina. bat.
Solution:
Modify the Registry HKEY_LOCAL_MACHINE \ SOFTWARE \ Apache Software Foundation \ Tomcat Service Manager \ Tomcat5 \ Parameters \ JavaOptions
Original Value:
-Dcatalina. home = "C: \ ApacheGroup \ Tomcat 5.0"
-Djava. endorsed. dirs = "C: \ ApacheGroup \ Tomcat 5.0 \ common \ endorsed"
-Xrs
Add-Xms300m-Xmx350m
Restart the tomcat service and the settings take effect.

Answer 2
Solution to JVM memory overflow of Tomcat
Keyword: solution to jvm memory overflow in tomcat... full text>

Tomcat prompts memory overflow. How can this problem be solved?

Perm overflow may be caused by the addition of your SSH package and the loading of many things started by default.
The Java Virtual Machine configures two parameters for non-heap memory:
1.-XX: PermSize: indicates the initial memory allocation size for non-heap areas. Its abbreviation is permanent size (persistent memory)
2.-XX: MaxPermSize: indicates the maximum memory size allocated to non-heap areas.

Configure these two startup parameters.

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.