Data Daquan-Tomcat Performance Tuning solution Part 2

Source: Internet
Author: User
Tags gz file

Tomcate4

<Connector classname = "org. apache. coyote. tomcat4.coyoteconnector "Port =" 80 "minprocessors =" 5 "maxprocessors =" 75 "enablelookups =" false "redirectport =" 8443 "acceptcount =" 100 "DEBUG =" 0 "connectiontimeout =" 20000 "useurivalidationhack =" false "disableuploadtimeout =" true "/>

Tomcat5

<Connector Port = "80" maxthreads = "150" minsparethreads = "25" maxsparethreads = "75" enablelookups = "false" redirectport = "8443" acceptcount = "100" DEBUG =" 0 "connectiontimeout =" 20000 "disableuploadtimeout =" true "/>
3. Adjust the number of threads
Through the application Program Is the number of threads created to process requests. Tomcat uses the thread pool to accelerate the response speed to process requests. In Java, the thread is the path for running the program, and is independent of other control threads in a program. Code . They share the same address space. Multithreading helps programmers write efficient programs with the maximum CPU utilization, keeping idle time at the lowest level, and thus receiving more requests.
In tomcat4, you can control the number of threads by modifying the values of minprocessors and maxprocessors. These values have been set to the default value after installation and are enough for use, but these values are increased as the site expands. The number of threads created when the minprocessors server is started should be sufficient to process a small amount of load. That is to say, if only five click events occur per second in a day and each request task takes one second to process, it is enough to set the number of threads in advance. However, when your site traffic is large, you need to set a larger number of threads to the value of the maxprocessors parameter. The value of maxprocessors is also limited, so it is necessary to prevent uncontrollable traffic (or malicious service attacks), thus exceeding the memory used by the virtual machine. To increase the number of concurrent connections, increase these two parameters at the same time. The maximum number of connections allowed by the Web server is also subject to the kernel parameter settings of the operating system. Generally, Windows has about 2000 connections, and Linux has about 1000 connections.
These parameters have been adjusted in tomcat5. Please refer to the following attributes:
Maxthreads Tomcat uses threads to process each request received. This value indicates the maximum number of threads that Tomcat can create.
Acceptcount indicates 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. requests exceeding this number are not 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.

Once the thread created by maxsparethreads exceeds this value, Tomcat closes the socket thread that is no longer needed.
The best way is to set multiple times and perform tests to observe the response time and memory usage. Different machines, operating systems, or virtual machines may have different combinations, and not all websites have the same traffic, therefore, there is no one-size-fits-all solution to determine the number of threads.
Vi. Apr database usage
In tomcat, the APR library is used to read files and perform network transmission in Tomcat using JNI. It can greatly improve Tomcat's processing performance on static files. If you use HTTPS transmission, it can also improve the processing performance of SSL.
Generally in Windows, you can directly download the compiled binary version of The dll library file to enable Tomcat Apr, it is recommended to copy the library file tcnative-1.dll to the bin directory of Tomcat. In linux, you can directly decompress and install the tomcat_native.tar.gz file under the bindirectory. Before compiling, make sure that the APR library has been installed.
How can I determine whether the APR library is enabled for Tomcat? The method is to view the Tomcat startup log:
If APR is not enabled, the startup log generally contains the following:
Org. Apache. Coyote. http11.http11protocol start
If APR is enabled, this log is changed:
Org. Apache. Coyote. http11.http11aprprotocol start
Tcnative-1.dll: http://tomcat.heanet.ie/native/
Tuning Overview
Based on the above analysis, If you want tomcat to achieve the optimal effect, you must first strive to optimize the operating system and network resources, and use a later version of JDK. For systems with a large number of static pages, the static pages are handled by Apache by integrating Apache with tomcat, and the dynamic pages are handled by Tomcat, which greatly relieves Tomcat's processing capability. Using the ARP library can also greatly improve Tomcat's ability to process static files. For systems with high concurrency requirements, the Apache and tomcat clusters are used to separately share the load to multiple Tomcat servers, which greatly improves the system performance and makes full use of hardware resources. At the same time, you need to optimize Tomcat itself, including increasing the memory and adjusting the number of concurrent threads.

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.