How to modify the memory size of tomcat in Linux and Windows

Source: Internet
Author: User
Tags xms

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 to set

Example:
Copy codeThe Code is as follows:
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 = 384m"
CATALINA_OPTS = "-server-Xms768m-Xmx768m-XX: PermSize = 128 m
-XX: MaxPermSize = 256 m
-XX: NewSize = 192 m-XX: MaxNewSize = 384m"

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
Copy codeThe Code is as follows:
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 do not take effect,
That is to say, set JAVA_OPTS =-Xms128m-Xmx350m does not work.
The above MB memory is allocated to OOM.
In windows, bin/tomcat.exe is executed. It reads the value in the registry, instead of setting catalina. bat.
Solution:
Copy codeThe Code is as follows:
Modify the Registry HKEY_LOCAL_MACHINE/SOFTWARE/Apache Software Foundation
/Tomcat Service Manager/Tomcat5/Parameters/JavaOptions

Original Value:
Copy codeThe Code is as follows:
-Dcatalina. home = "C:/ApacheGroup/Tomcat 5.0 ″
-Djava. endorsed. dirs = "C:/ApacheGroup/Tomcat 5.0/common/endorsed"
-Xrs

Join
Copy codeThe Code is as follows:
-Xms300m-Xmx350m

Restart the tomcat service and the settings take effect.
(For Tomcat 5.5, there is a Procrun 2.0 Tomcat5/Parameters/Java under Apache Software Foundation.
Set the value of JvmMs and JvmMx. You need to modify the value in decimal format)

However, the OS has limits on memory.

Appendix: how to obtain the maximum available memory of JVM

Run the java-XmxXXXXM-version command on the command line to test the function. Then, the XXXX value is gradually increased. If the execution is normal, the specified memory size is available. Otherwise, the error message is printed.

The JDK has different maximum allowable memory values in different versions. Therefore, you need to test the memory value in actual applications.

This table shows that if your machine has too much memory, you can only run several more instances to provide machine utilization, such as running Tomcat, you can install a few more Tomcat servers and build clusters.

I will reference the results of this others' tests here.

Maximum memory (MB) client Maximum memory (MB) server of the company's JVM version
Copy codeThe Code is as follows:
SUN 1.5.x 1492 1520
SUN 1.5.5 (Linux) 2634 2660
SUN 1.4.2 1564 1564
SUN 1.4.2 (Linux) 1900 1260
IBM 1.4.2 (Linux) 2047 N/
BEA JRockit 1.5 (U3) 1909 1902

So it has a lot to do with the OS and jdk versions. If you want to make full use of the memory, consider using the cluster.

1. in tomcat's catalina. bat, add the-Dcom. sun. management. jmxremote parameter.
Copy codeThe Code is as follows:
Set JAVA_OPTS = % JAVA_OPTS %-Dcom. sun. management. jmxremote

Use JDK to access the jconsole.exe directory in the bincatalog to track tomcat memory usage.

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.