Reprint: Tomcat's JVM settings and number of connections settings

Source: Internet
Author: User
Tags xms

In the Windows environment, modify the "%tomcat_home%\bin\catalina.bat" file to add the following settings at the beginning of the file:
Set java_opts=-xms256m-xmx512m

To modify the "%tomcat_home%\bin\catalina.sh" file in the Linux environment, add the following settings at the beginning of the file:
java_opts= '-xms256m-xmx512m '

Where-XMS sets the initial memory size,-XMX sets the maximum memory that can be used.

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

One, Tomcat's JVM Prompts for memory overflow

See if the log file has a memory overflow error under the%tomcat_home%\logs folder

Second, modify the Tomcat JVM

1. Error tip: Java.lang.OutOfMemoryError:Java heap Space

Tomcat can use 128MB of memory by default, and in larger applications, this memory is not enough and may cause the system to fail to run. A common problem is to report a Tomcat memory overflow error, an out of memory (system-out-of-RAM) exception, which causes the client to display a 500 error, and generally adjusts Tomcat's use of memory to resolve the issue.

In the Windows environment, modify the "%tomcat_home%\bin\catalina.bat" file and add the following settings at the beginning of the file:set java_opts=-xms256m-xmx512m

The Linux environment modifies the "%tomcat_home%\bin\catalina.sh" file, adding the following settings at the beginning of the file:java_opts= '-xms256m-xmx512m '

Where-XMS sets the initial memory size,-XMX sets the maximum memory that can be used.

2. Error tip: Java.lang.OutOfMemoryError:PermGen space

Reason:
The full name of PermGen space is permanent Generation space, which is the permanent storage area of memory, which is primarily stored by the JVM
class and meta information, class is loader when it is placed in PermGen space, and the storage class instance (Instance)
Unlike the heap area, GC (garbage Collection) does not clean up permgen space during the main program run time, so if your app
The PermGen space error is most likely to occur when the Web server has pre-compile the JSP
When If you have a large number of third-party jars under your web app that are larger than the JVM's default size (4M), this error message will be generated
The rest.


Workaround:

The first line in Catalina.bat is incremented:
Set java_opts=-xms64m-xmx256m-xx:permsize=128m-xx:maxnewsize=256m-
xx:maxpermsize=256m
The first line in catalina.sh is incremented:
java_opts=-xms64m-xmx256m-xx:permsize=128m-xx:maxnewsize=256m-
xx:maxpermsize=256m

3. JVM Settings

The size of the heap
-xmssize in bytes
Sets the initial size of the Java heap, the default size is 2097152 (2MB). This value must be a multiple of 1024 bytes (1KB) and larger than it. (The-server option increases the default size to 32M.) )
-xmnsize in bytes
Sets the initial Java heap size for the Eden object, with a default value of 640K. (The-server option increases the default size to 2M.) )
-xmxsize in bytes
Set the maximum size of the Java heap, the default value is 64M, (the-server option increases the default size to 128M.) The maximum heap size is approximately 2GB (2048MB).

Note: Many options for the garbage collector depend on the heap size setting. Before you fine-tune the way the garbage collector uses memory space, verify that the heap size is set correctly.

Garbage collection: Use of memory
-xx:minheapfreeratio=percentage as a whole number
Modifies the minimum percentage of available memory in the heap after garbage collection, the default value is 40. If at least 40% of the heap memory is not released after garbage collection, the system will increase the size of the heap.
-xx:maxheapfreeratio=percentage as a whole number
The maximum percentage of heap memory that can be used after the garbage collection is changed and the heap memory shrinks before the default value is 70. This means that if there is more than 70% heap memory after garbage collection, the system will reduce the size of the heap.
-xx:newsize=size in bytes
Sets the default memory size for the Eden generation in the allocated memory object. Its default value is 640K. (The-server option increases the default size to 2M.) )
-xx:maxnewsize=size in bytes
Allows you to change the upper limit of the initial object space, the memory required to create a new object is allocated from this space, the default value of this option is 640K. (The-server option increases the default size to 2M.) )
-xx:newratio=value
Change the size ratio of the old and new space, the default value of this ratio is 8, meaning that the new space size is 1/8 of the old space.
-xx:survivorratio=number
Changing the size ratio of the Eden object space and the remaining space, the default value of this ratio is 10, meaning that the size of the Eden object space is survivorratio+2 times larger than the remaining space.
-xx:targetsurvivorratio=percentage
Sets the percentage of remaining space to be used after the space extraction you expect, the default value is 50.
-xx:maxpermsize=size in MB
The size of the long generation (permanent generation), the default value is (32MB).

Third, view Tomcat's JVM memory

1. No default user is set in Tomcat6, so users need to be manually added to the Tomcat-users.xml file under Tomcat6 conf folder.

such as: <role rolename= "manager"/>
<user username= "Tomcat" password= "Tomcat" roles= "manager"/>

Note: You need to restart TOMCAT6 after adding.

2. Access Http://localhost:8080/manager/status, enter the user name and password added above.

3. The memory usage can then be seen under the JVM below.

Jvm

Free memory:2.50 MB Total memory:15.53 mb Max memory:63.56 mb

Four, tomcat connection number settings

In the <connector .../> configuration in the Tomcat configuration file Server.xml, the parameters related to the number of connections are:
Minprocessors: Minimum number of idle connection threads for improved system processing performance with a default value of 10
Maxprocessors: Maximum number of connection threads, which is the maximum number of requests concurrently processed, with a default value of 75
Acceptcount: Maximum number of connections allowed, should be greater than or equal to Maxprocessors, default value is 100
Enablelookups: Whether to reverse the domain name, the value is: TRUE or false. To improve processing power, set to False
ConnectionTimeout: Network connection time-out, unit: milliseconds. Set to 0 to never time out, so the setting is hidden. It can usually be set to 30000 milliseconds.

The parameters associated with the maximum number of connections are maxprocessors and Acceptcount. If you want to increase the number of concurrent connections, both parameters should be increased.


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

Reprint: Tomcat's JVM settings and number of connections settings

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.