Tomcat JVM memory configuration

Source: Internet
Author: User
Tags xms

Original article: http://elf8848.iteye.com/blog/467460

There are two common memory overflow types:

Java. Lang. outofmemoryerror: permgen Space

Java. Lang. outofmemoryerror: Java heap Space


1. java. Lang. outofmemoryerror: permgen Space

Permgen space stands for permanent generation space, which is the permanent storage area of the memory,
This memory is mainly used by JVM to store class and meta information. When the class is loaded, it will be placed in permgen space,
Unlike the heap region of the storage instance, GC (garbage collection) does not
Permgen space is cleaned up. Therefore, if your application contains many classes, the permgen space error may occur,
This error is common when the web server pre-compile the JSP. If your web app uses a large number of third-party jar files
This error message is generated when the default JVM size (4 MB) is exceeded.
Solution: manually set the maxpermsize
Suggestion: Move the same third-party jar files to the tomcat/shared/lib directory to reduce the memory usage of jar files.

 

Ii. java. Lang. outofmemoryerror: Java heap Space
The JVM heap setting refers to the setting of the memory space that JVM can allocate during the Java program running. The JVM automatically sets the heap size value at startup,
Its initial space (-XMS) is1/64 of physical memory, The maximum space (-xmx) is1/4 of physical memory. You can use options such as-xmn-XMS-xmx provided by JVM.
. The heap size is the sum of young generation and tenured generaion.
Tip: if 98% is used for GC and the available heap size is less than 2% in JVM, this exception is thrown.
Tip: the heap size should not exceed 80% of the available physical memory. Generally, you must set the-XMS and-xmx options to the same, and-xmn to the-xmx value of 1/4.
Solution: manually set heap size

 

 

-------------------- Modify the memory size of atatjvm in Linux ----------------------

To add it to Catalina. Sh in the bin of Tomcat, before the position cygwin = false. Note that the quotation marks must be placed, and the red ones are newly added.

# OS specific support. $ VaR _ must _ be set to either true or false.
Java_opts = "-xms256m-xmx512m-xss1024k-XX: permsize = 128 M-XX: maxpermsize = 256 m"
Cygwin = false

 

-------------------- Modify Tomcat JVM memory size in Windows ----------------------

Scenario 1: Decompress TomcatYou must start Tomcat through startup. BAT to load the configuration.

To add it to Catalina. bat in the bin of Tomcat

Rem guess catalina_home if not defined
Set current_dir = % Cd % followed by red.

Set java_opts =-xms256m-xmx512m-XX: permsize = 128 M-XX: maxnewsize = 256 m-XX: maxpermsize = 256 m-djava. AWT. Headless = true

 

Case 2: install Tomcat, No Catalina. bat

 

The installed version of Tomcat does not contain Catalina. bat.
If Tomcat 6 is registered as a Windows Service or the installation version of Tomcat is used in Windows2003,
You can modify it in/bin/tomcat6w.exe.

If Tomcat 5, the Windows service executes bin \ tomcat.exe. It reads the value in the registry, rather than the setting of Catalina. bat.
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.

---------------------------------------------------------
Ratio of each parameter:
The sum of xmx and permsize cannot exceed the total memory available by JVM
Permsize cannot be greater than xmx
For details about other parameters, this article does not discuss the value size of each parameter.

Tomcat JVM memory configuration

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.