Data Daquan-Tomcat Performance Tuning solution Part 1
Source: Internet
Author: User
I. Operating System Optimization
For operating system optimization, it is to increase the available memory capacity as much as possible, increase the CPU frequency, and ensure the read/write rate of the file system. Stress tests show that the CPU processing capability is stronger and the system runs faster when many concurrent connections exist ..
[Applicable scenario] any project.
Ii. Java Virtual Machine Optimization
Sun's JVM should be selected. when meeting the project's needs, we should try to use a JVM with a higher version. In general, higher version products will improve the speed and efficiency compared with lower versions.
Jdk1.4 has improved the performance by nearly 10%-20% over jdk1.3, and jdk1.5 has improved the performance by 25%-75% over jdk1.4.
Therefore, jdk1.6 is recommended for high performance requirements.
[Applicable scenario] any project.
Iii. Integrate Apache with Tomcat
The Web server specifically processes HTTP requests. The application server provides business logic for applications through many protocols. Although Tomcat can also be used as a Web server, its processing speed of static html is inferior to that of Apache, and its function as a web server is far inferior to that of Apache. Therefore, Apache and tomcat are integrated, the division of HTML and JSP functions is clearly defined, so that Tomcat can only process JSP, and other Web servers such as Apache and IIS can process them, thus greatly improving Tomcat running efficiency.
If a project uses a large number of static pages and images, and has a large access volume, we recommend that you use Apache to integrate tomcat to improve the overall system performance.
There are three ways to integrate Apache and tomcat: JK, http_proxy, and ajp_proxy. the JK method is the most common method. JK has two versions: 1 and 2. The latest version of 1 is 1.2.8, and Version 2 has been abandoned. Http_proxy uses the mod_proxy module of Apache to connect to Tomcat Using proxy technology. The ajp_proxy connection method is actually the same as the http_proxy method, and is provided by mod_proxy. You only need to replace http: // In the configuration with AJP: //, and connect to the port of the Tomcat AJP Connector.
Compared with JK's connection method, the last two methods are relatively simple in configuration, and the flexibility is not inferior at all. However, the stability is not as long as JK has been tested, so we recommend using the JK connection method.
Apache + jk + Tomcat configuration:
The two configuration files used are httpd. conf and mod_jk.conf. Httpd. conf is the configuration file of the Apache server. It is used to load the JK module and specify the JK configuration file information. Mod_jk.conf is the connection definition file to the Tomcat server.
[Deployment steps]
1. Install the Apache server
2. Deploy Tomcat
3. Copy mod_jk.so to the modules directory.
4. Modify httpd. conf and mod_jk.conf
[Application Scenario] a large number of static page application systems are used.
4. Apache and tomcat Clusters
For systems with high concurrency requirements, we need to use Server Load balancer to share the pressure on Tomcat servers. There are four load balancing implementations: first, DNS, but it can only be implemented in turn, and fault cannot be handled; second, it is based on ms iis, windows 2003 Server itself carries the Server Load balancer service. The third is the hardware mode, which is implemented through the switch function or a dedicated server Load balancer device. The fourth is the software mode, install software on a server Load balancer instance. Using Apache httpd server for Load balancer, Tomcat cluster nodes can use tomcat to achieve the fourth method above. This method is flexible and the cost is relatively low, another major advantage is that you can make some flexible configuration based on the application and server conditions. Therefore, we recommend using Apache + Tomcat clusters for load balancing.
Tomcat clusters can maximize the performance of servers. You can deploy multiple Tomcat servers on servers with high configurations, or deploy Tomcat on multiple servers separately, apache and tomcat are integrated in JK mode. After verification, the system responds to a large number of users. Apache + 3366cat cluster> Apache + 2tomcat cluster> Apache integrated Tomcat> A single Tomcat cluster. In addition, when you deploy Apache + Multi-Tomcat clusters, if a tomcat instance goes down, the system can continue to use it. Therefore, when the hardware system performance is superior enough, to maximize the performance of the software, you can add a tomcat cluster.
The configuration files used by the Apache + Tomcat cluster include httpd. conf, mod_jk.conf, and workers. properties. Mod_jk.conf is the configuration of JK information, including the JK path. The workers. properties configuration file is the connection definition file for the Tomcat server.
Apache needs to adjust the running parameters to build a web service suitable for the corresponding network environment. The following configuration can be optimized:
1. Set mpm (multi processing modules multi-channel processing module ). Threadperchild: this parameter is used to set the number of threads for each process. In Windows, the default value is 64 and the maximum value is 1920. It is recommended to set it to a value between and. If the server performance is high, the value is larger, and vice versa. Maxrequestperchild indicates the maximum number of requests that each sub-process can process. The value of this parameter depends more on the memory of the server. If the memory is large, it can be set to a large parameter. Otherwise, a smaller value is set. The recommended value is 3000.
2. disable DNS and name resolution hostnamelookups off
3. Open UseCanonicalName module UseCanonicalName on
4. Disable redundant modules. Generally, modules that do not need to be loaded include mod_include.so, mod_autoindex.so, mod_access.so, and mod_auth.so.
5. Enable keepalive support
Keepalive on, keepalivetimeout 15 maxkeepaliverequests 1000
Based on actual experience, the effect of improving system performance through Apache and tomcat clusters is very obvious. This method can maximize the use of hardware resources, the processing of multiple Tomcat servers is used to share the pressure on a single Tomcat server.
[Deployment steps]
1. Install the Apache server
2. Deploy the Tomcat cluster, that is, multiple identical Tomcat servers.
3. Copy mod_jk.so to the modules directory.
4. Modify httpd. conf, mod_jk.conf, and workers. properties.
[Application Scenario] a system with a large number of concurrent users and online users.
V. Tomcat Optimization
1. JVM parameter optimization:-XMS <size> indicates the size of the JVM initialization heap, and-xmx <size> indicates the maximum value of the JVM heap. The size of these two values is generally set as needed. When the application Program When the required memory exceeds the maximum value of the heap, the VM will prompt a memory overflow and cause the application service to crash. Therefore, we recommend that you set the maximum value of the heap to 80% of the maximum available memory. In Catalina. bat, set java_opts = '-xms256m-xmx512m', which indicates that the initial memory is 256 MB and the maximum memory available is 512 MB.
2. disable DNS query
When a web application wants to record information about the client, it also records the IP address of the client or converts the machine name from the Domain Name Server to the IP address. DNS queries require network occupation, and include the process of obtaining the corresponding IP address from many servers that are far away or do not work, which consumes a certain amount of time. To eliminate the impact of DNS queries on performance, we can disable DNS queries by modifying the value of the enablelookups parameter in the server. xml file:
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