4. The establishment of standalone operating environment -- CentOS-6.4 optimization tomcat7

Source: Internet
Author: User

Link.

Everyone has heard that Apache Tomcat 6 supports the Java language NiO (New I/O), no matter whether you are familiar with NiO technology, but you can imagine NiO is a good thing. Indeed, using NiO can provide better performance on the server side and enhance the performance of concurrent processing on the server side. Note: Sorry, the NIO function is not enabled in the default configuration option of Tomcat 6. So many friends who are using Tomcat 6 thought they could use NiO happily.

cd /usr/local/tomcat1/confvi server.xml
1. Set the Tomcat Connector pool.

Yellow Sea added the following configuration in the configuration file:

<Executor name="tomcatThreadPool" namePrefix="catalina-exec-" maxThreads="1000" minSpareThreads="350" />
II , Linux Modify the JVM memory size.

To add it to Catalina. Sh in the bin of Tomcat, before the position cygwin = false. Note that the quotation marks must be placed, and the red ones are newly added.

# OS specific support. $var _must_ be set to either true or false.JAVA_OPTS="-server -Xms512M -Xmx512M -Xss256K -Djava.awt.headless=true -Dfile.encoding=utf-8 -XX:PermSize=64M -XX:MaxPermSize=128m"cygwin=false
3. view the default values of open files in the current system:

Ulimit-

It's 1024.

Maximum number of files that can be opened in the file system:CAT/proc/sys/fs/file-max

My machine is 396399

Modify the maximum number of opened files in the file system:Echo 396399>/proc/sys/fs/file-max

 

This value can only be smaller than the limit value.

1.VI/etc/security/limits. confAdd the maximum number of opened files in the file:

* Soft nofile 65535

* Hard nofile 65535

Finally, restart ulimit-a to view the value of open files again. If it is changed, the value will take effect.

 

IV, Install Tomcat's APR to improve performance

It is found that Tomcat can use Apache Portable Runtime to provide better performance and improve the processing capability of Web static pages. Dedicated web servers are no longer needed to process static pages. APR and tomcat-native provide better scalability, performance, and integration to local server technologies.

 

If the APR technology is not available, the following prompt is displayed when Tomcat is started:

 

Information: The APR based Apache Tomcat native library which allows optimal performance in production environments was not found on the java. library. path:/usr/Java/jdk1.6.0 _ 06/JRE/lib/i386/client:/usr/Java/jdk1.6.0 _ 06/JRE/lib/i386: /usr/Java/jdk1.6.0 _ 06/
JRE/../lib/i386:/usr/Java/packages/lib/i386:/lib:/usr/lib

According to official instructions:

APR Library

OpenSSL Libraries

OpenSSL is available

yum install -y openssl-devel

Download *. GZ to install Apr.

(1) install APR

mkdir  /root/softwarecd /root/softwarewget http://mirror.bit.edu.cn/apache/apr/apr-1.4.6.tar.gztar zxvf apr-1.4.6.tar.gz  cd apr-1.4.6 ./configure --prefix=/usr/local/apr make make install  

When installing Apr

./Configure -- prefix =/usr/local/APR

RM: cannot remove 'libtoolt': no such file or directory

Solution:

Vim configure

Add # comment out before line 1 # $ RM "$ comment file"

In re-./configure

 

(2) install Apr-iconv

cd /root/softwarewget http://mirror.bit.edu.cn/apache/apr/apr-iconv-1.2.1.tar.gztar -zxvf apr-iconv-1.2.1.tar.gz cd apr-iconv-1.2.1 ./configure --prefix=/usr/local/apr-iconv --with-apr=/usr/local/apr  make make install

(3) install Apr-util

cd /root/softwarewget http://mirror.bit.edu.cn/apache/apr/apr-util-1.4.1.tar.gztar zxvf apr-util-1.4.1.tar.gzcd apr-util-1.4.1 ./configure --prefix=/usr/local/apr-util  --with-apr=/usr/local/apr  --with-apr-iconv=/usr/local/apr-iconv/bin/apriconv  make make install

PS: I have experienced two different APR installations. For the first time, my centos has not been upgraded. After one upgrade, there will be some errors before the upgrade, you just need to update yum. It is recommended that you install it after upgrade. It will be a little bit more normal ~~

(4) install Tomcat-native

// Tomcat-native-1.1.27-src.tar.gz I installed Tomcat inside with his own, in the bin directory, if you do not find, go to the next online on the line .. I don't know where to find out.

cd /usr/local/tomcat1/bin    tar zxvf tomcat-native.tar.gz  cd tomcat-native-1.1.27-src/jni/native    ./configure --with-apr=/usr/local/apr make   make install

(5) set APR Environment Variables

 

cd /usr/local/tomcat1/binvi catalina.sh

In the file #! Add the following content under/bin/sh:

 

#!/bin/shLD_LIBRARY_PATH=$LD_LIBRARY_PATH:/usr/local/apr/libexport LD_LIBRARY_PATH

In this case, we just added the Tomcat APR and did not destroy the configuration information of other Tomcat servers.

 

After Tomcat is started, check the log:

bin/startup.sh

head logs/catalina.out

You can see the following results:

Okay, you can run it, but you have not tested the performance improvement.

High concurrency will significantly improve the performance. After the installation is complete, restart the system to take effect. For example, if the default protocal is Apr, it is better to change protocol to org. Apache. Coyote. http11.http11aprprotocol to be clearer.

cd /usr/local/tomcat1/confvi server.xml

Replace ctor with the following content:

<Connector port="8080"        protocol="org.apache.coyote.http11.Http11AprProtocol"        executor="tomcatThreadPool"        compression="on"        compressionMinSize="2048"        maxThreads="30000"        minSpareThreads="512"        maxSpareThreads="2048"        enableLookups="false"        redirectPort="8443"        acceptCount="35000"        debug="0"        connectionTimeout="40000"        disableUploadTimeout="true" URIEncoding="UTF-8" useBodyEncodingForURI="true" />

 

Next we will start to test the pressure of the two Protocols:

 

Install AB on centos

yum install httpd-tools

After preparation, we can test it.

ab -kc 1000 -n 10000 http://localhost:8080/

This command uses 1000 concurrent connections for 10000 times. The result is as follows:

The fastest Nio:

The fastest time for APR:

The gap is about 50%. We strongly recommend that you use the APR protocol !!! Do not use NiO protocol + APR library support behavior !!!!!!!! If you cannot install APR or you cannot enable it, use the following alternative solution:
<Connector port="8080"        protocol="org.apache.coyote.http11.Http11NioProtocol"        executor="tomcatThreadPool"        compression="on"        compressionMinSize="2048"        maxThreads="30000"        minSpareThreads="512"        maxSpareThreads="2048"        enableLookups="false"        redirectPort="8443"        acceptCount="35000"        debug="0"        connectionTimeout="40000"        disableUploadTimeout="true" URIEncoding="UTF-8" useBodyEncodingForURI="true" />
Related Article

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.