Method of modifying memory size by Tomcat in Linux and windows

Time:2020-11-18

The initial space (i.e. – XMS) is 1 / 64 of the physical memory, and the maximum space (- Xmx) is 1 / 4 of the physical memory.
It can be set by using the options provided by the JVM, such as – XMN – XMS – Xmx

For example, the parameter setting reference of Java JVM in 1G memory environment is given below:

Copy codeThe code is as follows:
JAVA_OPTS=”-server -Xms800m -Xmx800m -XX:PermSize=64M
-XX:MaxNewSize=256m -XX:MaxPermSize=128m -Djava.awt.headless=true ”
JAVA_OPTS=”-server -Xms768m -Xmx768m -XX:PermSize=128m
-XX:MaxPermSize=256m -XX:NewSize=192m -XX:MaxNewSize=384m”
CATALINA_OPTS=”-server -Xms768m -Xmx768m -XX:PermSize=128m
-XX:MaxPermSize=256m
-XX:NewSize=192m -XX:MaxNewSize=384m”

Linux:

In the / usr / local / apache-tomcat-5.5.23/bin directory catalina.sh
Add: Java_ OPTS=’-Xms512m -Xmx1024m’
If you want to add “m”, it means MB, otherwise it will be KB. When starting tomcat, it will report that there is insufficient memory.
-XMS: initial value
-Xmx: maximum
-XMN: minimum

Windows
stay catalina.bat Top entry

Copy codeThe code is as follows:
set JAVA_OPTS=-Xms128m -Xmx350m

If you use startup.bat Start tomcat, OK settings take effect. Enough successful allocation of 200m memory

But if it’s not execution startup.bat Start tomcat, but use the system service of windows to start Tomcat service,
The above settings will not work,
That is to say, set Java_ Opts = – xms128m – xmx350m did not work
200m of memory is allocated above for oom
The windows service executes bin/ tomcat.exe . he reads the value in the registry instead of catalina.bat Settings for
terms of settlement:

Copy codeThe code is as follows:
Modify registry HKEY_ LOCAL_ MACHINE/SOFTWARE/Apache Software Foundation
/Tomcat Service Manager/Tomcat5/Parameters/JavaOptions

The original value is

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 tomcat5 / parameters / Java of procrun 2.0 under Apache Software Foundation
Set the value of jvmms and jvmmx. Change the value of decimal system.)

However, the OS also has memory limitations

Attachment: how to get the maximum available memory of the JVM

In the command line, use the Java – xmxxxxm – version command to test, and then gradually increase the value of XXX. If the execution is normal, it means that the specified memory size is available. Otherwise, an error message will be printed.

It is found that the maximum allowable memory values of JDK with slight differences in versions are not the same. Therefore, in practical applications, we still need to test ourselves to see what kind of value the memory can achieve.

What I want to illustrate from this table is that if your machine has too much memory, you can only run a few more instances to provide the utilization of the machine. For example, if you run tomcat, you can install more Tomcat and cluster, and so on.

I’ll quote the results of other people’s tests here

Company JVM version maximum memory (megabytes) client maximum memory (megabytes) server

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/A
BEA JRockit 1.5 (U3) 1909 1902

So it has a lot to do with the OS system version and JDK version. If you want to make the most of memory, consider using clusters.

1、 At Tomcat catalina.bat Add- Dcom.sun.management . jmxremote parameter

Copy codeThe code is as follows:
set JAVA_OPTS=%JAVA_OPTS% -Dcom.sun.management.jmxremote

2、 You need to use jdk5.0 or above to open the jconsole.exe To connect and track the memory usage of Tomcat

Recommended Today

Regular expression sharing for checking primes

This regular expression is shown as follows: Regular expressions for checking prime numbers or not To use this positive regular expression, you need to convert the natural number into multiple 1 strings. For example, 2 should be written as “11”, 3 should be written as “111”, 17 should be written as “11111111111”. This kind of […]