CentOS-6.5 optimization Tomcat7

Source: Internet
Author: User
Tags apache tomcat


Everyone has heard of the Java language features supported in Apache Tomcat6 NIO (New I/O), regardless of whether you are familiar with NIO technology, but you can certainly imagine that nio is a good thing.  Indeed, the use of NiO on the server side will have better performance to enhance the server-side performance of concurrent processing. Please note: I am sorry that the NIO feature is not turned on in Tomcat6 in the default configuration options. So many of the friends who are using Tomcat6 thought they would be happy to use NIO.

cd/usr/local/tomcat1/confvi server.xml
One, set up the Tomcat connector pool.

Yellow Sea in the configuration file, the following configuration is added:

<executor name="tomcatthreadpool" nameprefix="catalina-exec-  " maxthreads= " "minsparethreads=" />
Two , Linux To Modify the JVM memory size

To add the catalina.sh under Tomcat's bin, position cygwin=false before. Note the quotation marks to be taken, red for the newly added.

# OS specific support. $varsettruefalse. Java_opts="-server-xms512m-xmx512m-xss256k-djava.awt.headless=true-dfile.encoding=utf-8-XX: permsize=64m-xx:maxpermsize=128m"  cygwin=false
Third, view the default values for the current system open files:

Ulimit-a

No, it's 1024.

File system maximum number of open files:cat/proc/sys/fs/file-max

my machine is 396399.

Modify file system maximum open files:echo 396399 >/proc/sys/fs/file-max

This value can only be set to a small setting that cannot exceed the limit value.

1. Set the maximum number of open files in the vi/etc/security/limits.conf file add:

* Soft Nofile 65535

* Hard Nofile 65535

finally with restart Ulimit-a again, open files value, if changed, then take effect.

Four, install Tomcat's APR to improve performance

Discover that Tomcat can use Apache portable Runtime to provide stronger performance, improve the processing power of Web static pages, and no longer require dedicated Web server to handle static pages. Apr and tomcat-native provide better scalability, performance, and integration into local server technology.

If you do not have APR technology, the following prompt appears when you start Tomcat:

Info: The APR based Apache Tomcat Native Library which allows optimal performance in production environments is not found O n 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

As required by official instructions:

APR Library

OpenSSL Libraries

OpenSSL can be used

Yum Install-y openssl-devel

Apr or download *.gz to install.

(1) Install Apr

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



appears when installing APR

./configure--PREFIX=/USR/LOCAL/APR

Rm:cannot remove ' Libtoolt ': No such file or directory

Workaround:

Vim Configure

in line 30206 # $RM "$cfgfile" preceded by # comment out

Ps:1, Linux can use Find character mode: Command mode--input/the string to find; 2, jump directly to the line: Command mode--input line number

In the RE./configure

(2) Installation 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 do  install




(3) Installation Apr-util


Cd/root/softwarewget Http://mirror.bit.edu.cn/apache/apr/apr-util-1.5.4.tar.gztar ZXVF APR-UTIL-1.5.4.TAR.GZCD Apr-util-1.5.4./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 installed APR, the first time is my CentOS did not upgrade, an upgrade, before the upgrade will have some assorted error said no, generally are less package what, you give it yum update on the line, recommended upgrade after reloading, will be more normal a little ~ ~

(4) Installation tomcat-native

Tomcat-native-1.1.33-src.tar.gz This I installed Tomcat inside himself, in the bin directory, if you do not find, go online next on the line. Specifically, I don't know. ⊙﹏⊙ b Khan, find Apache's official Internet café


Cd/usr/local/tomcat1/bin    tar zxvf tomcat-native.tar.gz  cd tomcat-native-1.1.33-src/jni/native    ./configure--with-apr=/usr/local/aprmake make   Install

(5) Set Apr the environment Variables

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

under #!/bin/sh of the file, add the following:

#!/bin/Shld_library_path= $LD _library_path:/usr/local/apr/libexport ld_library_path

In this case, we just added the Tomcat APR, without destroying other Tomcat configuration information.

after starting Tomcat , look at the log:

Head Logs/catalina.out

You can see the following results:

Okay, can run, but not test how much its performance has improved.

performance can be significantly improved with high concurrency. reboot will take effect when the installation is complete . If you use the default protocal is APR, but it is better to change the protocol to Org.apache.coyote.http11.Http11AprProtocol, will be more explicit .

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

Replace the connector content as follows:

<connector port= "8080"        protocol= "Org.apache.coyote.http11.Http11AprProtocol"        executor= " Tomcatthreadpool "        compression=" on "        compressionminsize=" 2048 "        maxthreads=" 30000 "        minsparethreads= "maxsparethreads=" "        2048"        enablelookups= "false"        redirectport= "8443        " Acceptcount= "35000"        debug= "0"        connectiontimeout= "40000"        disableuploadtimeout= "true" uriencoding= "UTF-8" usebodyencodingforuri= "true"/>

Here we begin to test the pressure of the two protocols:

CentOS Installation AB

Yum Install Httpd-tools

When we're ready, we can test it.

 + 10000 http://localhost:8080/

This command uses 1000 concurrent connections to connect 10000 times. The results are as follows:

The quickest time for NIO:

The fastest time of Apr:

The gap is around 50%, it is highly recommended to use APR protocol!!! Do not use the NIO protocol +APR Library supported behavior!!!!!!!!If you do not install APR or if you do not have the option to enable APR, use the following alternatives:
<connector port="8080"Protocol="Org.apache.coyote.http11.Http11NioProtocol"Executor="Tomcatthreadpool"Compression=" on"compressionminsize="2048"MaxThreads="30000"minsparethreads=" +"maxsparethreads="2048"enablelookups="false"Redirectport="8443"Acceptcount="35000"Debug="0"ConnectionTimeout="40000"Disableuploadtimeout="true"uriencoding="UTF-8"Usebodyencodingforuri="true"/>


CentOS-6.5 optimization Tomcat7

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.