Tomcat optimization Strategy

Source: Internet
Author: User
Tags xms

JDK Installation

Su-Rootmkdir JDKCD Jdkwget HTTPS://Mirror.Its.Sfu.ca/mirror/centos< Span class= "pun" >-third-party/ nsg/common/x86_64< Span class= "pun" >/jdk-7u76- linux-x64. rpmrpm -ivh jdk-7u76-< Span class= "PLN" >linux-x64. RPM                  

Environment variables

Vi/etc/Profileexport Java_home=/usr/java/ jdk1. 7.0_76export classpath= $JAVA _home/lib/tools. Jar: $JAVA _home/lib/< Span class= "PLN" >dt.: $JAVA _home/lib.< Span class= "PLN" > /etc/profile    

Tomcat download

#建议用一般用户运行tomcatwget http://Www.Apache.Org/Dist/Tomcat/Tomcat-7/v7. 0.59/bin/apache-< Span class= "PLN" >tomcat-7.0. 59.tar. Gztar xzf apache-tomcat-7.0 59.tar. Gzapache-tomcat-7.059/binchmod +x *. sh                

Tomcat Hidden version number

CD Apache-Tomcat-7.0.59/Libmkdir TESTCD Testjar XF.. /Catalina.Jarvi org/Apache/Catalina/Util/ServerInfopropertiesserver.=tomcatserver.=6server. Built=jan 182013 14:51 :10 Utcjar CF . /catalina../*rm -RF test     

Tomcat jconsole Monitoring Remote JVM configuration
Reference: http://blog.linuxeye.com/262.html

Three modes and concurrency optimizations for Tomcat
Tomcat has 3 modes of operation
1. Bio
The default mode, performance is very low, without any optimization processing and support.

2. NiO
Using Java's asynchronous IO Care technology, noblocking IO technology.
Want to run in this mode, directly modify the connector node in the Server.xml, modify the protocol to

<Connector port="80″protocol="org.  Apache.  Coyote.  Http11.  Http11nioprotocol "connectiontimeout="20000"uriencoding=" utf-8″usebodyencodingforuri= "true "enablelookups="false"redirectport="8443">        

Once started, it can take effect.

3. Apr
From the operating system level to solve the asynchronous IO problem, greatly improve performance.
Apr and native must be installed and will be activated directly to support APR
Modify protocol to Org.apache.coyote.http11.Http11AprProtocol

Install Apr

-y Install Apr Apr-devel  

Installing native
Enter the Tomcat/bin directory, such as:

Cd/Usr/Local/Tomcat/Bin/Tar XZFV Tomcat-Native.tar.-native-1.1 32-src/jni /native/./--with-apr= /usr/bin/apr -1-configmake & & make install            

The following message appears after the installation is complete

Libraries in:   /usr/local/Apr/lib   

After successful installation, you will also need to set environment variables for tomcat by adding 1 rows to the catalina.sh file:

Catalina_opts="-djava.library.path=/usr/local/apr/lib" 

Modify the Conf/server.xml on the 8080 end

Protocol="Org.apache.coyote.http11.Http11AprProtocol" 

After Tomcat is started, viewing the log will have this line of information stating that the APR mode has started

INFO: APR capabilities:IPv6[true],[true],[false] , [True].               

Concurrency optimization
1.JVM Tuning
The new file tomcat_home/bin/setenv.sh The following statement, depending on the situation.

Java_opts="-xms1024m-xmx1024m-xss1024k-xx:permsize=64m-xx:maxpermsize=128m" 

Detailed parameters

-Xms JVM Initialize heap memory size - maximum memory for Xmx JVM heap- Xss thread stack size -XX:  PermSize JVM non-heap initial memory allocation size -XX:maxpermsize JVM non-heap maximum memory   

Suggestions and Precautions:
The-XMS and-XMX options are set to the same heap memory allocation to avoid resizing the heap after each GC, the heap memory is recommended as the memory 60%~80%, the non-heap memory is not recyclable, the size is dependent on the item, and the thread stack size is recommended for 256k.

The 32G memory configuration is as follows:

Java_opts="-xms20480m-xmx20480m-xss1024k-xx:permsize=512m-xx:maxpermsize=2048m" 

2. Turn off DNS reverse lookup
Add the following parameters to the <connector port= "8080″

Enablelookups="false" 

3. Optimize Tomcat parameters (using APR)

<ListenerClassName="Org.apache.catalina.core.AprLifecycleListener" />...<ConnectorPort= "8080"  Protocol= " Org.apache.coyote.http11.Http11AprProtocol " Connectiontimeout=  "20000"  //link timeout length  Redirectport = "8443"  Maxthreads= " " Minsparethreads="  acceptcount< Span class= "pun" >= "$"  Enablelookups= " False " uriencoding=" UTF-8 "  />             


Reproduced

Tomcat optimization Strategy

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.