Tomcat JVM settings and connection settings

Source: Internet
Author: User
Tags xms

WindowsModify the "% tomcat_home % \ bin \ Catalina. Bat" file in the environment and add the following settings at the beginning of the file:
Set java_opts =-xms256m-xmx512m

LinuxModify the "% tomcat_home % \ bin \ Catalina. Sh" file in the environment and 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.

 

--------------------------------------

1. Tomcat JVM prompts memory overflow

Check whether the log file has a memory overflow error in the % atat_home % \ logs folder.

2. Modify Tomcat's JVM

1. error message: Java. Lang. outofmemoryerror: Java heap Space

By default, Tomcat can use 128 MB of memory. In larger application projects, the memory is insufficient, which may cause the system to fail. 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 and add the following settings at the beginning of the file:Set java_opts =-xms256m-xmx512m 

In Linux, modify the "% tomcat_home % \ bin \ Catalina. Sh" file and 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.

 

2. error message: Java. Lang. outofmemoryerror: permgen Space

Cause:
The full name of permgen space is permanent generation space, which refers to the permanent storage area of the memory. This memory is mainly stored by JVM.
If the class and meta information are put, the class will be put into the permgen space when it is loaded.
Different heap regions, GC (garbage collection) will not clean up the permgen space during the main program running, so if your application
If there is a class, it is likely that the permgen space error will occur. This error is common in the web server pre-compile JSP
. If your web app uses a large number of third-party jar files and the size exceeds the default JVM size (4 MB), this error message is generated.
.

Solution:

Add the following in the first line of Catalina. BAT:
Set java_opts =-xms64m-xmx256m-XX: permsize = 128 M-XX: maxnewsize = 256 m-
XX: maxpermsize = 256 m
Add the following in the first line of Catalina. sh:
Java_opts =-xms64m-xmx256m-XX: permsize = 128 M-XX: maxnewsize = 256 m-
XX: maxpermsize = 256 m

 

3. JVM settings

Heap size
-Xmssize in bytes
Set the initial size of the Java heap. The default size is 2097152 (2 MB ). This value must be a multiple of 1024 bytes (1 kb) and greater than it. (The-server option increases the default size to 32 MB .)
-Xmnsize in bytes
Set the initial Java heap size for the Eden object. The default value is 640 kb. (The-server option increases the default size to 2 MB .)
-Xmxsize in bytes
Set the maximum size of the Java heap. The default value is 64 mb. (The-server option increases the default size to 128 MB .) The maximum heap size is nearly 2 GB (2048 MB ).

Note: many options of the garbage collector depend on the heap size setting. Check whether the heap size has been set correctly before fine-tuning the way the Garbage Collector uses the memory space.

Garbage Collection: memory usage
-XX: minheapfreeratio = percentage as a whole number
Modify the minimum percentage of available memory in the heap after garbage collection. The default value is 40. If at least 40% heap memory is not released after garbage collection, the system will increase the heap size.
-XX: maxheapfreeratio = percentage as a whole number
Change the maximum percentage of available heap memory after garbage collection and before the heap memory is reduced. The default value is 70. This means that if there is more than 70% heap memory after garbage collection, the system will reduce the heap size.
-XX: newsize = size in bytes
Set the default memory size for the Eden generation in the allocated memory objects. The default value is 640 kb. (The-server option increases the default size to 2 MB .)
-XX: maxnewsize = size in bytes
You can change the upper limit of the initial object space. The memory required for creating a new object is allocated from this space. The default value of this option is 640 kb. (The-server option increases the default size to 2 MB .)
-XX: newratio = Value
Change the size ratio of the New and Old spaces. The default value is 8, which means that the size of the new space is 1/8 of the old space.
-XX: Required vorratio = Number
Change the size ratio of the Eden object space to the residual space. The default value of this ratio is 10, which means that the size of the Eden object space is twice that of the remaining space.
-XX: target1_vorratio = Percentage
Set the percentage of remaining space that you want to extract. The default value is 50.
-XX: maxpermsize = size in MB
The size of the permanent generation. The default value is 32 (32 MB ).

 

Iii. View Tomcat JVM memory

1. tomcat6 does not set any default users, so you need to manually add users to the tomcat-users.xml file under the conf folder of tomcat6.

 

For example: <role rolename = "manager"/>
<User Username = "Tomcat" Password = "Tomcat" roles = "manager"/>

Note: restart Tomcat 6 after adding it.

 

2. Access http: // localhost: 8080/manager/status and enter the username and password added above.

 

3. Then we can see the memory usage in the following JVM.


JVM

Free memory: 2.50 MB total memory: 15.53 MB Max memory: 63.56 MB

 

Iv. Tomcat connection count settings

In the <connector.../> configuration in the tomcat configuration file server. XML, the parameters related to the number of connections include:
Minprocessors: Minimum number of idle connection threads to improve system processing performance. The default value is 10.
Maxprocessors: Maximum number of connection threads, that is, the maximum number of concurrent requests. The default value is 75.
Acceptcount: Maximum number of connections allowed. It must be greater than or equal to maxprocessors. The default value is 100.
Enablelookups: whether to check the domain name. The value is true or false. Set to false to improve processing capability.
Connectiontimeout: the network connection times out. Unit: milliseconds. If it is set to 0, it indicates that the request Never times out. This setting has potential risks. Generally, it can be set to 30000 ms.

The parameters related to the maximum number of connections are maxprocessors and acceptcount. To increase the number of concurrent connections, increase these two parameters at the same time.

The maximum number of connections allowed by the Web server is also subject to the kernel parameter settings of the operating system. Generally, Windows has about 2000 connections, and Linux has about 1000 connections. For more information about how to set these parameters in UNIX, see Common Unix monitoring and management commands.

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.