Tomcat startup memory settings

Source: Internet
Author: User
Tags xms

 

 

Tomcat startup memory settings

 


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 ..
In Windows, bin/tomcat.exe is executed. 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.

 

========================================================== ======================================

**************************************** **********************************

========================================================== ======================================

 

Tomcat is used as a parameter configuration for Windows Services, especially for permsize settings.

When Tomcat is started with startup. bat, the parameter settings are described more on the Internet and will not be described here.

When Tomcat is used as a Windows system service, I found a lot of related articles on the Internet and did not have a comprehensive parameter setting method. Generally, I will explain the settings of XMS and xmx, other parameters are not provided, which is not practical enough. After research on procrun under Apache and multiple trials, we finally learned how to set general parameters. In fact, tomcat5.exehas been included in the procrunfunction, so many people cannot find the reason for downloading the procrun.exe file online.
Procrun can refer to: http://commons.apache.org/daemon/procrun.html
Note: Tomcat 5 is used as an example here. It should also apply to Tomcat 6.

The Registry is not used here. We use the GUI tool provided by Tomcat to set it.
1. Run tomcat5w.exe // es // tomcatservice in the command line.
The tomcatservice is the name of the Windows service you added. In this way, a tomcat Service Manager will appear in the Windows taskbar. the icon is as follows: .
2. Open the Java page of Tomcat Service Manager, as shown in figure



Enter the parameters to be set in Java options, such as setting the permsize memory.
-XX: permsize = 64 m
-XX: maxpermsize = 192 m
-XX: reservedcodecachesize = 48 m
-Duser. timezone = GMT + 08
Note: Each row cannot be followed by spaces.
We can also modify the HKEY_LOCAL_MACHINE/software/Apache Software in the registry.
Foundation, procrun 2.0, testservice, parameters, and Java

 

========================================================== ======================================

**************************************** **********************************

========================================================== ======================================

 

Open tomcathome/bin/tomcat5w.exe, click the Java tab, and you will find two items:
Initial memory pool and maximum memory pool.
Initial memory pool: memory size set for initialization.
Maximum memory pool: The maximum memory size.
Set the initial memory pool to 64 MB.

After the settings are complete, press OK. Then restart Tomcat and you will find that the JVM available memory in Tomcat has changed.

 

 

========================================================== ======================================

**************************************** **********************************

========================================================== ======================================

 

In the bin directory of Tomcat, locate the Catalina. BAT file, open it, and add the following sentence at the top:
Set java_opts =-xms256m
-Xmx512m.

OK, the JVM memory has been changed to total memory: 256 MB, Max
Memory: 512 MB.

Modify Tomcat JVM memory in eclipse and run Tomcat configured in eclipse.

In server configuration, tomcat5.x-> JDK, add the following in Java VM arguments:
-Xms256m-xmx512m-XX: maxpermsize = 64 m
Achieve the same effect.

However, if you do not modify it like this, and run Tomcat configured in eclipse, the previously modified memory in Catalina. bat won't work. I don't know why.

After the memory is changed, you can log on to Tomcat --> status to view the JVM.

To view the memory in the program, you can use the following statements:

Java code

  1. System. Out. println ("totalmemory:" + (runtime. getruntime (). totalmemory ()/(1024*1024) + "M "));
  2. System. Out. println ("Max memory:" + (runtime. getruntime (). maxmemory ()/(1024*1024) + "M "));
  3. System. Out. println ("free memory:" + (runtime. getruntime (). freememory ()/(1024*1024) + "M "));

System. Out. println ("totalmemory
: "+ (Runtime. getruntime (). totalmemory ()/(1024*1024) +
"M "));

System. Out. println ("Max
Memory: "+ (runtime. getruntime (). maxmemory ()/(1024*1024) +
"M "));

System. Out. println ("free
Memory: "+ (runtime. getruntime (). freememory ()/(1024*1024) +
"M "));

 

 


 

========================================================== ======================================

**************************************** **********************************

========================================================== ======================================

 

By default, Tomcat can use a small amount of memory. In a large application project, the memory is insufficient, and the system may fail to run. A common problem is the error of Tomcat memory overflow. the out of memory (insufficient system memory) causes the client to display the Error 500. Generally, the problem can be solved by adjusting the memory usage of Tomcat.

 

Modify the "% tomcat_home %/bin/Catalina. Bat" file in windows,

 

Add the following settings at the beginning of the file: Set java_opts =-xms256m-xmx512m

 

 

Modify the "% tomcat_home %/bin/Catalina. Sh" file in Linux,

 

Add the following settings at the beginning of the file: java_opts = '-xms256m-xmx512m'

 

Here,-XMS sets the initial memory size and-xmx sets the maximum memory that can be used.

  

Tomcat 6 has no Catalina. BAT file in some versions.

At this time, we need to run the % tomcat_home %/bin/tomcat6w.exe file,

Modify the values of initial memory pool and maximum memory pool, which are 256 and 512 respectively.


However, when Tomcat is started in the eclipse environment, it seems that the memory is still small because it is not affected by the parameters set above. Therefore, you need to reset it in eclipse.

Such as: http://nxzhaoning.blog.sohu.com/95873512.html

 

 

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.