Tomcat JVM settings and connection number settings

Time:2021-5-7
  • Modifying Tomcat in Windows_ Add the following settings at the beginning of the file:

set JAVA_OPTS=-Xms256m -Xmx512m

  • Modifying Tomcat in Linux_ Add the following settings at the beginning of the file: “home% \ bin / Catalina. Sh”

JAVA_OPTS=’-Xms256m -Xmx512m’

Where – XMS sets the size of initialization memory and – Xmx sets the maximum memory that can be used.

————————————–

1、 Tomcat’s JVM prompts for memory overflow

View% Tomcat_ Does the log file have a memory overflow error in the home% \ logs folder

2、 Modifying Tomcat’s JVM

1. Error prompt: java.lang.outofmemoryerror: Java heap space

Tomcat can use 128MB of memory by default. In larger application projects, this memory is not enough, which may cause the system to fail to run. The common problem is to report the Tomcat memory overflow error and the out of memory exception, which leads to the client display 500 error. Generally, the problem can be solved by adjusting the memory usage of Tomcat.  

Modifying Tomcat in Windows_ Add the following settings at the beginning of the file: set Java_ OPTS=-Xms256m -Xmx512m  

Modifying Tomcat in Linux_ Add the following settings at the beginning of the file: Java_ OPTS=’-Xms256m -Xmx512m’  

Where – XMS sets the size of initialization memory and – Xmx sets the maximum memory that can be used.

 

2. Error prompt: java.lang.outofmemoryerror: permgen space

reason:
The full name of permgen space is permanent generation space, which refers to the permanent storage area of memory. This memory is mainly stored by the JVM
If class and meta information are put, class will be put into permgen space when it is loaded. It is the same as the class that stores instance
Different from the heap area, GC (garbage collection) does not clean up permgen space during the main program run time, so if your application
Permgen space error is likely to occur if there is a very high class in JSP. This kind of error is common when the web server pre compiles the JSP
Time. If a large number of third-party jars are used in your web app, and their size exceeds the default size of the JVM (4m), this error message will be generated
It’s over.

resolvent:

In the first line of catalina.bat, add:
set JAVA_OPTS=-Xms64m -Xmx256m -XX:PermSize=128M -XX:MaxNewSize=256m –
XX:MaxPermSize=256m
In the first line of catalina.sh, add:
JAVA_OPTS=-Xms64m -Xmx256m -XX:PermSize=128M -XX:MaxNewSize=256m –
XX:MaxPermSize=256m

 

3. JVM settings

The size of the pile  
-Xmssize in bytes 
    Set the initial size of 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 
    Set the initial Java heap size for the Eden object. The default value is 640K- The server option increases the default size to 2m.)  
-Xmxsize in bytes 
    Set the maximum size of Java heap. The default value is 64M. (the – server option increases the default size to 128M.) The largest heap size is nearly 2GB (2048MB).  

Note that many garbage collector options depend on the heap size setting. Make sure the heap size is set correctly before fine tuning how the garbage collector uses memory space.  

Garbage collection: memory usage  
-XX:MinHeapFreeRatio=percentage as a whole number 
    Modify the minimum percentage of memory available 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 
    Change the maximum percentage of heap memory available after garbage collection and before heap memory shrinks. 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 
    Set the default memory size for the Eden generation in the allocated memory object. The 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 for creating 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, which means that the size of the new space is 1 / 8 of the old space.  
-XX:SurvivorRatio=number 
    Change the size ratio of Eden object space and remnant space. The default value of this ratio is 10, which means that the size of Eden object space is 2 times larger than that of remnant space.  
-XX:TargetSurvivorRatio=percentage 
    Set the percentage of residual space that you expect to be used after space extraction. The default value is 50.  
-XX:MaxPermSize=size in MB 
    The size of permanent generation is 32 (32MB) by default.

 

3、 View Tomcat’s JVM memory

1. No default user is set in Tomcat6, so you need to manually add users to tomcat-users.xml file in the conf folder of Tomcat6.

 

    For example:
         

Note: you need to restart Tomcat6 after adding.

 

2. Visit http://localhost : 8080 / Manager / status, enter the user name and password added above.

 

3. Then you 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

 

4、 Tomcat connection number setting

In Tomcat configuration file server.xmlIn configuration, parameters related to the number of connections are as follows:
Minprocessors: the minimum number of idle connection threads, used to improve the system processing performance, the default value is 10
Maxprocessors: the maximum number of connection threads, that is, the maximum number of concurrent requests. The default value is 75
Acceptcount: the maximum number of connections allowed. It should be greater than or equal to maxprocessors. The default value is 100
Enablelookups: whether to reverse query the domain name. The value is true or false. To improve processing power, it should be set to false
Connectiontimeout: network connection timeout, unit: Ms. Setting it to 0 means that it will never time out. There are hidden dangers in this setting. It can usually be set to 30000 Ms.

The parameters related to the maximum number of connections are maxprocessors and acceptcount. If you want to increase the number of concurrent connections, you should 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 setting of the operating system, which is usually about 2000 for windows and 1000 for Linux. How to set these parameters in UNIX, please refer to UNIX common monitoring and management commands

 

Recommended Today

Looking for frustration 1.0

I believe you have a basic understanding of trust in yesterday’s article. Today we will give a complete introduction to trust. Why choose rust It’s a language that gives everyone the ability to build reliable and efficient software. You can’t write unsafe code here (unsafe block is not in the scope of discussion). Most of […]