Tomcat memory, connections, and other performance parameter settings

Source: Internet
Author: User

From: http://blog.sina.com.cn/s/blog_4f9e8fa70100g4o5.html

Keywords: Tomcat Performance Tuning middleware server

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 ):

Run the J2EE project on TomcatCodeMemory 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
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"
Connectiontimeout = "60000"
Keepalivetimeout = "15000"
Maxkeepaliverequests = "1"
Redirectport = "443"
.../>

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. JMX remote. 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, and null indicates the root path.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.