Tomcat performance optimization summary

Level optimization! ( The JAVA_OPTS parameter optimization and major elements)

Tomcat roughly elements of architecture: Server ---> Service -> Engine -> Host -> Context

Tomcat There are three protocols : HTTP , AJP , HTTPS

tomcat default model used BIO

tomcat There are three operating modes : Bio, NiO, On Apr ( additional installation ) , for example:

protocol="org.apache.coyote.http11.Http11Nio2Protocol"

Tomcat each element which has listener listener, by a Service connector layers connector by a thread pool ( the Thread Pool call effector () the Executor ), the role of the Connector receives the connection request, Request and Response objects for creating requester and exchange data; then assign threads to carry Engine of the request and response to bind to, at last, the request response treated and returned to the client.

tomcat on startup, will be a web project WEB-INF / web.xml and their conf / web.xml to merge, and then configureContext under ContextConfig class () UNIFIED content

So, you want to remove unnecessary configuration to reduce the Tomcat analytical costs.

Like in conf / web.xml of DefaultServlet or JspServlet, jspmap, mime, welcome to configure on-demand page.

In the conf / server.xml the Listener listener, VersionLoggerListener role is to display the version and JDK environment, can be deleted; AprLifecycleListener role: APR library is loaded, this configuration is only 1.3 connector is useful when the protocol is set to AJP /, if the non-AJP /1.3 can be removed.

GlobalResourcesLifecycleListener role in global resource

GlobalNamingResources can define global resource, it can be seen, the default configuration tomcat this is by reading the $ TOMCAT_HOME conf / tomcat-users.xml achieve / a. tomcat tomcat-user.xml used to define the configuration management page, if you do not login administration interface can be deleted.

When only needs to be integrated into the Apache server tomcat using this <connector protocol = "AJP / 1.3 " />

Server elements of the port listens for requests shut down services

Connector

port: Port number to specify the server you want to create, and requests from clients in this fracture listening

The number of threads handling requests created when the server starts: minProcessors

The maximum number of threads processing requests that can be created: maxProcessors

enableLookups: If true, it can be done by calling request.getRemoteHost () DNS query to get the actual host name of the remote client, if it is not false DNS queries, but return to their ip address

redirectPort: Upon receipt of a transmission request SSL server is processing the specified port number http request redirection

acceptCount: Specifies the number of threads when the processing of all requests that can be used are used, the number of requests may be placed in the queue process, more than the number of the request will not be processed

maxConnections: After reaching this value, will continue to accept connections, but does not deal with, according to how much value can continue to receive acceptCount

minSpareThreads: Minimum number of idle threads

connectionTimeout: number specified timeout period (in milliseconds)

tomcat default connection pool is limited, you can configure your own connection pool for the connector, such as:

<Connector executor="tomcatThreadPool"port="8080" protocol="HTTP/1.1"

jvm parameter optimization

tomcat is written in Java, and will run on the jvm, jvm waste disposal methods would have to follow the way. tomcat jvm parameters set in catalina.sh (Linux) and catalina.bat (windows), to JAVA_OPTS variable storage.

Detailed parameters:

-Xms: Initial setting JVM memory size (default physical memory 1/64)

-Xmx: JVM may be used provided the maximum memory (1/4 default physical memory, is recommended: physical memory 80%)

- Xmn: set the minimum memory JVM (128-256m enough, generally do not set)

 

-XX: PermSize: when to start the JVM Perm memory size

-XX: MaxPermSize: Perm is the maximum that can be consumed memory size (the default is 32M)

-XX: MaxNewSize, the default is 16M

-XX: NewSize: The default is 2M, this value is set large adjustable Daxin target area, Full reducing
the number of GC

-XX: NewRatio: change the ratio of old and new space, meaning that the new space is 1/8 the size of the old space (default is. 8)

-XX: SurvivorRatio: changing the ratio of the size of the remaining space and object space Eden, meaning empty Eden target

size than the remaining space between the large survivorRatio + 2 times (default is 10)

-XX: used to set up a parallel userParNewGC [CPU] multi collected

-XX: ParallelGCThreads be used to increase the degree of parallelism] Chiefly CPU

after -XXUseParallelGC disposed parallel sweep collector can be used multiple CPU []

1. conf / server.xml corresponding parameters in Executor

<-! Connection pool settings ->
<Executor 
name = "tomcatThreadPool" - the name of the thread pool
namePrefix = "catalina-exec-" - namePrefix + threaNumber thread name prefix
maxThreads = "1000" - the maximum number of threads in the pool
minSpareThreads = "100" - the number of active threads will always exist
maxIdleTime = "60000" - thread idle time, this time is exceeded, the thread will be destroyed MS
maxQueueSize = "Integer.MAX_VALUE" - the number of threads to be executed before queuing
prestartminSpareThreads = "false" - start thread pool, minSpareThreads thread portion is enabled
threadPriority = "5" - priority thread pool 10 ~. 1
className = "org.apache.catalina.core.StandardThreadExecutor" - implementation class thread the time required for custom thread class org.apache.catalina.Executor
/>
<! - when the connection pool configuration, the need to configure the connector ->
<connector 
Executor = "tomcatThreadPool" - thread pool name
port = "8080 "  
protocol="org.apache.coyote.http11.Http11AprProtocol"
connectionTimeout="20000"
redirectPort="8443" />

2.conf / server.xml Connector corresponding parameters in


<Connector 
Port = "8080" 
Protocol = "org.apache.coyote.http11.Http11AprProtocol" - a protocol type 
disableUploadTimeout = "to true"
KeepAliveTimeout = "20000"
connectionTimeout = "20000" - has been accepted, but not processing a request the wait timeout MS
redirectPort = "8443" - forwarding port for secure communication 
URIEncoding = "UTF-8" - URL coded character set
minSpareThreads = "100" - the default initialization and remain idle threads
enableLookups = "false" - Close a reverse DNS lookup
useURIValidationHack = "false" - off unnecessary tests
maxThreads = "1000" - the maximum number of processing requests of threads 200 is not configured for this attribute is ignored
acceptCount = "1000" - may be used threads are incoming connection requests when the maximum length
disableUploadTimeout = "true" - connector arrangement allows a longer time
maxConnections = "1000"- maximum number of connections to receive and process (NiO / NiO2 1000, On Apr 8192)
maxHttpHeaderSize = "8192" - http request and response header maximum size of 8K
as tcpNoDelay = "to true" is not delayed --tcp
compression = "on" - whether to enable compression OFF Force ON 
compressionMinSize = "2048" - the minimum pre-compression data byte 2K
noCompressionUserAgents = "GoZilla, Traviata" - Which browser settings are not compressed
compressableMimeType = "text / html, text / xml, text / css, application / javascript, text / plain "- set the compression file type
/>

3. Information JAVA_OPTS

the JAVA_OPTS = SET
-server 
-Xms1000M 
-Xmx1000m # -Xms -Xmx set to the same value, to avoid the JVM GC result in performance because of frequent fluctuations
-Xss512k 
-XX: + AggressiveOpts 
-XX: + UseBiasedLocking 
-XX: + DisableExplicitGC 
-XX: = 15 MaxTenuringThreshold 
-XX: + UseConcMarkSweepGC 
-XX: + UseParNewGC 
-XX: + CMSParallelRemarkEnabled 
-XX: + UseCMSCompactAtFullCollection 
-XX: 128M LargePageSizeInBytes = 
-XX: + UseFastAccessorMethods 
-XX: + UseCMSInitiatingOccupancyOnly

-Djava.awt.headless=true

4. Disable the 8005 port

telnet localhost 8005 and enter SHUTDOWN can close the Tomcat, for security we want to disable this feature

Default value :

<Server port = "8005" shutdown = "SHUTDOWN">
revised as :

<Server port="-1" shutdown="SHUTDOWN">
---------------------

Guess you like

Origin www.cnblogs.com/Haihong72H/p/11008625.html