Tuning Tomcat 8 in the windows

1. JDK path and specify parameters vm

  Modify the bin file catalina.bat, above about 95 setlocal add the following line:

  set JAVA_OPTS = -Xms1024m -Xmx1024m -XX: PermSize = 256M -XX: MaxPermSize = 512M // vm configuration parameters, according to the actual system configuration
  set JAVA_HOME = ... \ jdk1.8.0_92 // specified path corresponding version jdk
  set JRE_HOME = ... \ jdk1.8.0_92 \ jre

    Heap memory allocation

  -Xms <size> indicates the initialization JVM heap size, -Xmx <size> indicates the maximum JVM stack. Stack generally recommended maximum set at 80% of maximum available memory, and -Xms and -Xmx option is set to the same, which are designed to be able to completely clean the java garbage collection heap does not need to re-calculate the stack spacer the size of the area and the waste of resources.

  JVM initial allocation specified by the memory -Xms, default physical memory 1/64; JVM is specified by the maximum memory allocated -Xmx, 1/4 default physical memory. Default heap spare memory is less than 40%, JVM stack will increase up to a maximum limit of -Xmx; spare time is greater than the heap memory 70%, JVM will reduce the minimum limit of the stack until -Xms. Thus servers generally disposed -Xms, -Xmx equal to refrain from adjusting the size of the heap after each GC.
    Persistent memory state of the memory allocation
  used by the JVM -XX: PermSize initial value setting non-heap memory, physical memory default 1/64; manufactured by XX: MaxPermSize size of the largest non-heap memory is provided, the default is 1/4 of the physical memory.

 

2. Modify the server.xml

server.xml under conf modified path,

<!--

<Executor name="tomcatThreadPool" namePrefix="catalina-exec-"

    maxThreads="150" minSpareThreads="4"/>

-->

change into

<Executor

    name="tomcatThreadPool"

    namePrefix="catalina-exec-"

    maxThreads = "500" // maximum number of concurrent, 200 default settings is generally recommended 500 to 800, depending on the hardware facilities and operations to determine

    minSpareThreads = "100" // number of threads created during initialization of Tomcat, the default settings 25

    prestartminSpareThreads = "true" // initialize parameter values ​​at the time of minSpareThreads Tomcat initialization, if not equal to true, the invalid value minSpareThreads

    maxQueueSize = "100" // maximum number of queue, exceeds the request is rejected

/>

3. Modify the default configuration parameters link

The <Connector 
    port="8080" 
    protocol="HTTP/1.1" 
    connectionTimeout="20000" 
    redirectPort="8443" 
/>

change into

<Connector 
   executor="tomcatThreadPool"
   port="8080" 
   protocol = "org.apache.coyote.http11.Http11Nio2Protocol" // Tomcat 8 disposed nio2 better, Tomcat 6,7 nio provided better: org.apache.coyote.http11.Http11NioProtocol
   connectionTimeout="20000" 
   maxConnections="10000" 
   redirectPort="8443" 
   enableLookups = "false" // disable DNS queries
   acceptCount = "100" // all specified when the number of threads that can be used to process the request are used, the number of requests may be placed in the queue process, more than the number of the request will not be processed, default settings 100
   maxPostSize = "10485760" // POST FORM URL parameter to the way of submission, submission limit the maximum size, the default is 2097152 (2 MB), the unit uses a byte. 10485760 to 10M. If you want to disable the limit, you can set to -1.
   compression="on" 
   disableUploadTimeout="true" 
   compressionMinSize="2048" 
   acceptorThreadCount = "2" // number of threads for receiving connection, the default value is 1. This generally means when the change is needed because the server is a multi-core CPU, if it is configured as a generally multicore CPU 2.
   compressableMimeType="text/html,text/xml,text/plain,text/css,text/javascript,application/javascript" 
   URIEncoding="utf-8"
/>

4. Tomcat from time to time on issues of excessive close_wait

The following problem occurs after a period of time the server is started:

 

Solution: What close_wait, this state has some similarities with time_wait, will maintain that connection and hold a certain time . We know that almost all of the operating system handle the number of individual processes (connections) have limitations, such as the majority of linux system default is 1024. Because the connection too many of those in wait, resulting in an available connection overwhelmed. Disabled wait, so that the connection is closed immediately after returning to become one of the available connections.
Tomcat with an example:

<Connector port="8080" protocol="org.apache.coyote.http11.Http11NioProtocol"
           = connectionTimeout "20000" the maxThreads = "1000" the URIEncoding = "UTF-. 8" KeepAliveTimeout = "0" /> 
Note keepAliveTimeout = "0" is the key

Guess you like

Origin www.cnblogs.com/zt2710/p/12112436.html