Solve the memory overflow problem ---- Tomcat parameter settings, ---- tomcat parameter settings
The default parameters are not suitable for the production environment, so you need to modify some parameters.
1. Modify the memory parameters at startup and specify the JVM Time Zone (eight hours earlier than windows server 2008 ):
When running j2ee project code on Tomcat, memory overflow often occurs. The solution is to add the system parameters to the system parameters:
In the window, at the top of catalina. bat:
Set JAVA_OPTS =-XX: PermSize = 64 M-XX: MaxPermSize = 128 m-Xms512m-Xmx1024m;-Duser. timezone = GMT + 08;
It must be added at the top of catalina. bat.
In linux, add the following at the beginning of catalina. sh:
JAVA_OPTS = "-XX: PermSize = 64 M-XX: MaxPermSize = 128 m-Xms512m-Xmx1024m-Duser. timezone = Asia/Shanghai"
Note: There is no set or double quotation marks.
2. Thread Pool configuration (under Tomcat 6)
Using a thread pool to process more requests with fewer threads can improve tomcat's ability to process requests. Usage:
First. Open/conf/server. xml and add
<Executor name = "tomcatThreadPool" namePrefix = "catalina-exec -"
MaxThreads = "500" minSpareThreads = "20" maxIdleTime = "60000"/>
The maximum number of threads is 500 (generally enough on the server), the minimum number of Idle threads is 20, and the maximum idle time of the thread is 60 seconds.
Then, modify the <Connector...> node and add the executor attribute, for example:
<ConnectorExecutor = "tomcatThreadPool"
Port = "80"
Protocol = "HTTP/1.1"
MaxThreads = "600"
MinSpareThreads = "100"
MaxSpareThreads = "300"
ConnectionTimeout = "60000"
KeepAliveTimeout = "15000"
MaxKeepAliveRequests = "1"
RedirectPort = "443"
.../>
MaxThreads: the maximum number of threads that can be created by Tomcat. Each thread processes a request;
MinSpareThreads: Minimum number of backup threads and number of initialization threads at tomcat startup;
MaxSpareThreads: Maximum number of standby threads. Once the created thread exceeds this value, Tomcat will close socket threads that are no longer needed;
AcceptCount: specifies the number of requests that can be placed in the processing queue when the number of threads that can be used to process requests is used, if the number of requests exceeds this limit, the connection will be rejected.
ConnnectionTimeout: the network connection times out. Unit: milliseconds. If it is set to 0, it indicates that the request Never times out. This setting has potential risks. Generally, it can be set to 30000 ms.
EnableLookups: whether DNS queries are allowed
Note: Multiple ctor s can share one thread pool.
3. Adjust the connection-related ctor parameters:
<Connector executor = "tomcatThreadPool"
Port = "80" protocol = "HTTP/1.1"
ConnectionTimeout = "60000"
KeepAliveTimeout = "15000"
MaxKeepAliveRequests = "1"
RedirectPort = "443"
MaxHttpHeaderSize = "8192" URIEncoding = "UTF-8" enableLookups = "false" acceptCount = "100" disableUploadTimeout = "true"/>
Parameter description:
- ConnectionTimeout-Network connection timeout, in milliseconds. If it is set to 0, it indicates that the request Never times out. This setting has potential risks. Generally, it can be set to 30000 ms.
- KeepAliveTimeout-Maximum persistence time for persistent connections (MS ). This is 15 seconds.
- MaxKeepAliveRequests-Maximum number of persistent connections (1 indicates disabled, and-1 indicates no limit. The default value is 100. It is generally set to 100 ~ Between 200) the maximum number of HTTP requests that can be held in the pipeline until the connection is closed by the server. setting this attribute to 1 disables HTTP/1.0 keep-alive, as well as HTTP/1.1 keep-alive and pipelining. setting this to-1 allows an unlimited number of pipelined or keep-alive HTTP requests. if not specified, this attribute is set to 100.
- MaxHttpHeaderSize-The maximum length of the http request header information. Parts exceeding this length are not processed. Generally 8 K.
- URIEncoding-Specify the URL encoding format of the Tomcat container.
- AcceptCount-When the number of threads that can be used to process requests is used, the number of requests that can be placed in the processing queue will not be processed. The default value is 10. Defines the maximum queue length for incoming connection requests when all possible request processing threads are in use. Any requests requested ed when the queue is full are refused. The default value is 10.
- DisableUploadTimeout-Whether to use the timeout Mechanism During upload
- EnableLookups-Whether to reverse query the domain name; values: true or false. Set to false to improve processing capability.
- BufferSize-Defines the size (in bytes) of the buffer to be provided for input streams created by this connector. By default, buffers of 2048 bytes are provided.
- MaxSpareThreads-Number of idle connections. Once the created thread exceeds this value, tomcat will close the socket thread the maximum number of unused request processing threads that are allowed to exist until the thread pool starts stopping the unnecessary threads. the default value is 50.
- MaxThreads-The maximum number of connections simultaneously processed. Tomcat uses a thread to process each received request. This value indicates the maximum number of threads that Tomcat can create .. The maximum number of request processing threads to be created by this Connector ctor, which therefore determines the maximum number of simultaneous requests that can be handled. If not specified, this attribute is set to 200.
- MinSpareThreads-Minimum number of Idle threads, number of threads created during Tomcat initialization the number of request processing threads that are created when this Connector Ctor is first started. the connector will also make sure it has the specified number of idle processing threads available. this attribute shoshould be set to a value smaller than that set for maxThreads. the default value is 4.
- MinProcessors-The minimum number of idle connection threads to improve system processing performance. The default value is 10. (Used in Tomcat 4)
- MaxProcessors-Maximum number of connection threads, that is, the maximum number of concurrent requests. The default value is 75. (Used in Tomcat 4)
Note:
In Tomcat4, you can control the number of threads by modifying the values of minProcessors and maxProcessors.
In Tomcat5 +, the following parameters are adjusted:
MaxThreads
Tomcat uses a thread to process each received request. This value indicates the maximum number of threads that Tomcat can create.
AcceptCount
Specify the number of threads that can be used to process requests, and the number of requests that can be placed in the processing queue. Requests that exceed this number will not be processed.
ConnnectionTimeout
Network Connection timeout, in milliseconds. If it is set to 0, it indicates that the request Never times out. This setting has potential risks. Generally, it can be set to 30000 ms.
MinSpareThreads
The number of threads created during Tomcat initialization.
MaxSpareThreads
Once the created thread exceeds this value, Tomcat closes the socket thread that is no longer needed.
4. Server Load balancer and cluster configuration
Tomcat6 supports distributed deployment to implement cluster functions and improve response capabilities.
5,
To monitor Tomcat running status using JMX, You need to manually adjust the startup parameters as follows:
Open cataline. bat and add a row
Set JAVA_OPTS = % JAVA_OPTS %-Dcom. sun. management. jmxremote. port = 10090-Dcom. sun. management. jmxremote. ssl = false-Dcom. sun. management. jmxremote. authenticate = false-Djava. util. logging. manager = org. apache. juli. classLoaderLogManager-Djava. util. logging. config. file = "% CATALINA_BASE % \ conf \ logging. properties"
Modify cataline. sh in linux:
JAVA_OPTS = "-Dcom. sun. management. jmxremote. port = 10090-Dcom. sun. management. jmxremote. ssl = false-Dcom. sun. management. jmxremote. authenticate = false-Djava. util. logging. manager = org. apache. juli. classLoaderLogManager-Djava. util. logging. config. file = % CATALINA_BASE \ conf \ logging. properties"
Note that the JDK \ jre \ lib \ management. properties file must exist.
Restart the tomcat node and use jconsole to connect to the node (Port wei10090)
6. Add an application to Tomcat
Add rows to the Host tag of server. xml.
<Context displayName = "OA" docBase = "/app/web-apps/GACWP" path = ""/>
Path indicates the context name. null indicates the root path.