Tomcat JVM performance tuning and simple summary

Tomcat and JVM performance tuning brief summary

table of Contents:

Tomcat Performance Tuning

JVM tuning

§        First, memory tuning

§        Second, garbage collection policy tuning

 

Tomcat Performance Tuning

 

Find the conf directory under the Tomcat root directory, modify the contents of the server.xml file. For this part of the tune, I have learned is nothing more than set about the Tomcat server and the maximum number of concurrent Tomcat set the number of threads that are created during initialization , of course, there are other performance tuning settings, below is my my some parameter values set by the machine's performance, give you a detailed explanation about it:

 

. 1 , the URIEncoding = "UTF-. 8" : Set Tomcat character set . This configuration we generally are not set, because we will convert about garbled specific treatment in specific projects, directly modify the Tomcat character set is too too rigid.

 

2 , maxThreads = "300" : Set the current Tomcat maximum number of concurrent . The default configuration of Tomcat maximum number of requests is 150, that is, at the same time be able to support 150 concurrent. But in practice, the maximum number of concurrent hardware performance and the number of CPU has a great relationship, better hardware, better processor will cause Tomcat to support more concurrent. If the actual development in general, when an application has more than 250 concurrent, will take into account the clustered application server.

 

3 , minSpareThreads = "50" : Set the current Tomcat number of threads created when initializing, default is 25 .

 

. 4 , acceptCount to = "250" : when the number of simultaneous connections reaches maxThreads the value of parameter set number of connections may also receive queue, returns directly over this connection reject the connection . Specifies when the processing request can be used any number of threads are used, the number of requests can be put in the queue process, more than the number of requests will not be processed. The default value is 100. In practice, if you want to increase the number of concurrent Tomcat, and it should also increase the value of acceptCount and maxThreads.

 

5 , enableLookups = "false" : whether to open the reverse lookup domain name , usually set to false to increase processing capacity, as well as its value to true , rarely use.

 

6 , maxKeepAliveRequests = "1" : nginx dynamic transferred tomcat, nginx is not keepalive, but tomcat end keepalive enabled by default, will wait for the keepalive timeout, the default setting is to not use connectionTimeout. It is necessary to set the timeout tomcat and close keepalive tomcat's. Otherwise it will produce socket timewait a lot of tomcat. maxKeepAliveRequests = "1" can avoid a large amount of tomcat TIME_WAIT connection, thereby avoiding tomcat die away to some extent.

 

JVM tuning

Tomcat itself or run on the JVM, JVM parameters by adjusting the Tomcat we can have a better performance. Currently for tuning the JVM has two main aspects: memory tuning and tuning garbage collection policy .

 

A memory tuning

Navigate to the bin directory under the Tomcat root directory, set catalina.sh file in the JAVA_OPTS variable can be, because the startup parameters will back JAVA_OPTS as a startup parameter to the JVM process.

Java virtual machine memory structure is somewhat complex, it is divided into the heap, stack, and garbage collection system, method area several parts and other components;

 

Memory tuning piece of it, nothing more than by modifying the size of their own memory space, so that the application can use more reasonable, below is based on the parameters (parameter meaning) personal host performance settings:

 

 

1 , -Xmx512m : Set Java maximum available memory size of the heap of the virtual machine, the unit: trillion (m) , the whole heap size = the young generation size + tenured generation size + permanent generation size .

Permanent generation is generally a fixed size 64m. Different distribution of the heap, it will have some impact on the system. As far as possible to reserve objects in the new generation, to reduce the number of old GC's (usually relatively slow recovery in elderly). In practice, the initial value is typically set equal to the maximum value and the stack, thus reducing the number of garbage collection and the spatial spreading performed by the program is running, thus improving the performance of the program.

 

2 , -Xms512m : Set Java initial value of the size of the heap memory of the virtual machine, the unit: MB (m) , the same value can be set -Xmx, to avoid memory reallocation JVM after each garbage collection is completed.

 

3 , -Xmn170m : Set the young generation of memory size, unit: trillion (m) , this value greater impact on system performance, Sun official recommended configuration for the entire heap of 3/8. After general increases in the young generation of memory, it will also reduce the size of the old generation.

 

4 , -Xss128k : Sets the stack size for each thread . JDK5.0 after each thread stack size is 1M , before each thread stack size is 256K. Thread more application memory size of the required adjustment.

At the same physical memory, reducing this value can generate more threads. However, the number of operating system threads within a process still limited, not unlimited generation, experience in 3000 and 5000.

 

. 5 , -XX: = NewRatio. 4 : Set the young generation (including Eden and two Survivor regions) and the old generation ratio (removal permanent generation) . Is set to 4, the share of the young generation and the old generation ratio of 1: 4, the young generation accounts for 1/5 of the entire stack.

 

. 6 , -XX: = SurvivorRatio. 4 : Set the young generation Eden region Survivor size of area ratio . Is set to 4, the ratio of the two regions with a Survivor Eden zone is 2: 4, the total area Survivor a young generation 1/6.

 

. 7 , -XX: = MaxPermSize the 16m : setting a size of the persistent generation of the 16m , said above, the permanent generation is generally a fixed size memory 64M .

 

8 , -XX: MaxTenuringThreshold = 0 : set the maximum age of garbage.

If set to 0, then the younger generation of the object without Survivor areas, directly into the old generation. For more of the old generation of applications that can improve efficiency.

If this value is set to a large value, then the young generation objects will be copied many times in Survivor areas, which can increase the object and then the young generation of survival time, an increase in the introduction to the young generation namely recycling.

 

Second, the garbage collection policy tuning

Navigate to the bin directory under the Tomcat root directory is set catalina.sh file JAVA_OPTS variable. Java virtual machine has a default garbage collection mechanism, it is because of the efficiency of different garbage collection mechanism is different , so it often Java garbage collection policy of the virtual machine be adjusted accordingly . Here is some of the demand by garbage collection strategy to configure:

 

Java Virtual Machine garbage collection policy is generally divided into: the serial collector, the collector parallel and concurrent collector .

 

Serial collector:

1 , -XX: + UseSerialGC : on behalf of the garbage collection policy for the serial collector , that is, the entire process of scanning and copying single-threaded approach to be applied to a single CPU, the new generation of smaller and space to pause time requirements are not very high application, the default is the client level GC methods, mainly before JDK1.5 form of garbage collection.

 

Concurrent Collector:

. 1 , -XX: + UseParallelGC : garbage collection policy on behalf of parallel collector (priority throughput), i.e., scanning is performed over the entire replication process and multi-threaded manner, the CPU for multi, shorter pause time requirements of the application on the server level is the default GC methods used. This configuration is valid only for the young generation. This configuration can allow the young generation to use concurrent collection, while still using the old generation of the serial collector.

 

2 , -XX: = ParallelGCThreads. 4 : number of threads parallel collector configuration, namely: simultaneously with many garbage collection threads. This configuration value is preferably equal to the number of processors.

 

. 3 , -XX: + UseParallelOldGC: Configure old generation garbage collection is collected in parallel. JDK6.0 support for the old generation of parallel collector.

 

4 , -XX: MaxGCPauseMillis = 100 : Set the young generation garbage collection every time the maximum time, if you can not meet this time, JVM will automatically adjust the size of the young generation to meet this value.

 

. 5 , -XX: + UseAdaptiveSizePolicy : this option is set, the parallel collector will automatically select the young generation area size and the corresponding rate Survivor areas, predetermined time corresponding to the lowest target frequency or collect system, this value is recommended to use the parallel collector when the device has been opened.

 

Concurrent Collector:

1 , -XX: + UseConcMarkSweepGC : concurrent garbage collection policy on behalf of a collector.

 

It is said that these three mechanisms is needed in conjunction with GC's.

 

Guess you like

Origin www.cnblogs.com/w-hao/p/11519483.html