Tomcat and JVM performance tuning summary

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 setting the number of threads created during initialization and the maximum number of concurrent Tomcat Tomcat server, 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, URIEncoding = "UTF-8": Set the 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": Sets the maximum number of concurrent current Tomcat. 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 number of threads that are created when the current Tomcat initialization, the default value is 25.

4, acceptCount = "250": When the number of simultaneous connections maxThreads reaches the value of the parameter set, the 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, its value also 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 garbage collection policy tuning.

A: memory tuning to find the bin directory under the root directory Tomcat provided to variable JAVA_OPTS catalina.sh file, as the latter will start parameters JAVA_OPTS as a startup parameter to the JVM process. Besides the Java virtual machine memory structure is somewhat complex, I believe many people in understanding are very abstract, it is divided into several parts of the heap, stack, and garbage collection methods zone system and so, here is my chops from the Internet FIG memory structures:

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 my parameters according to the performance of my machine settings, to give you a detailed explanation of the meaning of each parameter, right :

1, -Xmx512m: set the maximum available memory size of the heap of the Java virtual machine, unit: trillion (m), the young generation throughout the heap size = size + size + old generation of 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: setting the initial value of the size of the heap memory of a Java 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 areas) 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 size of the area ratio of Eden Survivor young generation area. 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 = 16m: setting the size of the 16m permanent generation, 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.

II: garbage collection policy tuning to find the bin directory under the Tomcat root directory is set catalina.sh file JAVA_OPTS variable. We all know that the Java virtual machine has a default garbage collection, but the efficiency of different garbage collection mechanism is different, precisely because of this we often garbage collection policy Java virtual machine be adjusted accordingly. Here is some of my strategies by garbage collection needs 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: garbage collection policy on behalf of a 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.

好了,到此我对虚拟机的垃圾回收策略总结就这么多,还是这句话:优化的学习一直在路上,下面还有一张从其他博客中偷到的图,据说以上三种GC机制是需要配合使用的。

Guess you like

Origin www.cnblogs.com/jackyu888/p/11572534.html