Tomcat performance optimization and cluster Solution

Source: Internet
Author: User
Tags dedicated server
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

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. Apache integrationMcAt

The Web server specifically processes HTTP requests. The application server provides business logic for applications through many protocols. Although TomCatIt can also be used as a web server, but 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.

Www. linuxIdThe latter two types of C. com 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 moDuUnder the les directory

4. Modify httpd. conf and mod_jk.conf

[Application Scenario] a large number of static page application systems are used.

4. Apache and TomcatCluster

For systems with high concurrency requirements, we need to adoptServer Load balancerTo share the pressure on the Tomcat server. 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, the modules that do not need to be loaded are mod_ I.NcLude. so, mod_autoindEx. So, mod_access.so, 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.

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.