And a Tomcat JVM tuning experience summary! Xie not take away

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

The figure is based on some parameters I value my machine performance settings, to give you a detailed explanation about it:

And a Tomcat JVM tuning experience summary!  Xie not take away


. 1, the 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.

Generally in the actual development, 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 to = "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

Found Tomcat bin directory under the root directory, catalina.sh wen member disposed to JAVA_OPTS variable, because 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:

And a Tomcat JVM tuning experience summary!  Xie not take away


Memory tuning piece of it, nothing more than by modifying the size of their own memory space, enabling applications to more rational use of

The figure is based on my performance of my machine parameter settings give you a detailed explanation about the meaning of the various parameters of it:

And a Tomcat JVM tuning experience summary!  Xie not take away


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.

持久代一般固定大小为64m。堆的不同分布情况,对系统会产生一定的影响。尽可能将对象预留在新生代,减少老年代GC的次数(通常老年回收起来比较慢)。

实际工作中,通常将堆的初始值和最大值设置相等,这样可以减少程序运行时进行的垃圾回收次数和空间扩展,从而提高程序性能。

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根目录下的bin目录,也是设置catalina.sh wen件中JAVA_OPTS变量即可。

我们都知道Java虚拟机都有默认的垃圾回收机制,但是不同的垃圾回收机制的效率是不同的,正是因为这点我们才经常对Java虚拟机的垃圾回收策略进行相应的调整。

下面也是通过我的一些需求来配置的垃圾回收策略:

And a Tomcat JVM tuning experience summary!  Xie not take away


Java虚拟机的垃圾回收策略一般分为:串行收集器、并行收集器和并发收集器。

串行收集器:

1、-XX:+UseSerialGC:代表垃圾回收策略为串行收集器,即在整个扫描和复制过程采用单线程的方式来进行,适用于单CPU、新生代空间较小及对暂停时间要求不是非常高的应用上,是client级别默认的GC方式,主要在JDK1.5之前的垃圾回收方式。

并发收集器:

1、-XX:+UseParallelGC:代表垃圾回收策略为并行收集器(吞吐量优先),即在整个扫描和复制过程采用多线程的方式来进行,适用于多CPU、对暂停时间要求较短的应用上,是server级别默认采用的GC方式。

此配置仅对年轻代有效。该配置只能让年轻代使用并发收集,而年老代仍旧使用串行收集

2、-XX:ParallelGCThreads=4:配置并行收集器的线程数,即:同时多少个线程一起进行垃圾回收。此值最好配置与处理器数目相等。

. 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.

Well, so much for me this garbage collection policy summary virtual machine, or is this sentence: optimized learning has been on the road, the following are a steal from another blog in the Figure, it is said these three mechanisms is GC We need to meet to use.

And a Tomcat JVM tuning experience summary!  Xie not take away


Guess you like

Origin blog.51cto.com/14480698/2438284