Performance Optimization | 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:

Tomcat and JVM performance tuning summary

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 should also increase the value of acceptCount and maxThreads

Tomcat and JVM performance tuning summary

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.

Tomcat and JVM performance tuning summary

A memory tuning

Navigate to the bin directory under the Tomcat root directory, set the JAVA_OPTS variable to catalina.sh file, because the startup parameters will back 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:

Tomcat and JVM performance tuning summary

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 :设置Java虚拟机的堆的初始值内存大小,单位:兆(m),此值可以设置与-Xmx相同,以避免每次垃圾回收完成后JVM重新分配内存。

3、 -Xmn170m :设置年轻代内存大小,单位:兆(m),此值对系统性能影响较大,Sun官方推荐配置为整个堆的3/8。一般在增大年轻代内存后,也会将会减小年老代大小。

4、 -Xss128k :设置每个线程的栈大小。JDK5.0以后每个线程栈大小为1M,以前每个线程栈大小为256K。更具应用的线程所需内存大小进行调整。

在相同物理内存下,减小这个值能生成更多的线程。但是操作系统对一个进程内的线程数还是有限制的,不能无限生成,经验值在3000~5000左右。

5、 -XX:NewRatio=4 :设置年轻代(包括Eden和两个Survivor区)与年老代的比值(除去持久代)。设置为4,则年轻代与年老代所占比值为1:4,年轻代占整个堆栈的1/5 。

6、 -XX:SurvivorRatio=4 :设置年轻代中Eden区与Survivor区的大小比值。设置为4,则两个Survivor区与一个Eden区的比值为2:4,一个Survivor区占整个年轻代的1/6。

7、 -XX:MaxPermSize=16m :设置持久代大小为16m,上面也说了,持久代一般固定的内存大小为64m。

8、 -XX:MaxTenuringThreshold=0 :设置垃圾最大年龄。

如果设置为0的话,则年轻代对象不经过Survivor区,直接进入年老代。对于年老代比较多的应用,可以提高效率。

如果将此值设置为一个较大值,则年轻代对象会在Survivor区进行多次复制,这样可以增加对象再年轻代的存活时间,增加在年轻代即被回收的概论。

Tomcat and JVM performance tuning summary

二、垃圾回收策略调优

Navigate to 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:

Tomcat and JVM performance tuning summary

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.

Guess you like

Origin www.cnblogs.com/wyf0518/p/11456858.html