Go Configuring Tomcat+apr+native under Linux to handle high concurrency

Source: Internet
Author: User
Tags server port apache tomcat java se

absrtact : The number of Tomcat threads on a slow network is open to more than 300 of the level, not the APR, basically 300 threads will be full, the request will have to wait. However, with APR,Tomcat will call the Apache HTTP Server's core dynamic link library to handle file read or network transfer operations, when the number of concurrent threads is significantly reduced, from the original 300 may immediately drop to only dozens of, The new request will come in without a block.

Introduction to one or three modes of operation

Tomcat has three (BIO,NIO.APR) modes of operation, starting with a brief introduction to the

Bio
Bio (blocking I/O), as the name implies, is a blocking I/O operation that indicates that Tomcat is using traditional Java I/O operations (that is, the Java.io package and its sub-packages). Tomcat, by default, is run in bio mode. Unfortunately, in general, the Bio mode is the lowest performance in three operating modes. We can view the current state of the server through Tomcat Manager.

NiO
is a new I/O operation (i.e. the Java.nio package and its child packages) provided by Java SE 1.4 and subsequent releases. Java NiO is a buffer-based, Java API that provides non-blocking I/O operations, so NiO is also considered an abbreviation for non-blocking I/O. It has better concurrency performance than traditional I/O operations (bio).

Want to run in this mode, directly modify the connector node in the Server.xml, modify the protocol to

Apr
(Apache portable Runtime/apache Portable runtime), which is the support library for Apache HTTP servers. You can simply understand that Tomcat will invoke the core dynamic link Library of the Apache HTTP server in the form of JNI to handle file reads or network transfer operations, thus greatly improving the performance of Tomcat's handling of static files. Tomcat APR is also the preferred mode for running high concurrent applications on Tomcat.

For Tomcat to support APR, you must install APR and native so that Tomcat can take advantage of Apache's Apr interface and use part of the operating system's local operations to improve performance.

There are 3 modes of operation for Tomcat. Modify their run mode. 3 modes of operation is successful, you can see his startup console, or start the log. or log in to their default page http://localhost:8080/to see the server status.

Next introduce Linux under Tomcat+apr+native configuration

Second, Linux configuration tomcat+apr+native2.1 installation package preparation

Jdk-7u76-linux-x64.tar.gz (must be JDK1.7 above to support Apr)

Apr-1.5.2.tar.gz

Apr-util-1.5.4.tar.gz

Apache-tomcat-7.0.56.tar.gz (the installation package containing tomcat-native in the bin directory after decompression)

2.2 Installing the JDK

This is the first environment to run Tomcat, so this step is first performed.

2.2.1 Decompression
TAR-ZXVF jdk-7u76-linux-x64.tar.gz
2.2.2 Creating the/usr/local/java folder
Mkdir-p/usr/local/java
2.2.3 Move to/usr/local/java
MV Jdk1.7.0_76/usr/local/java
2.2.4 Adding environment variables
Vi/etc/profile

and finally add

#jdk1.7export java_home=/usr/local/java/jdk1.7.0_76export classpath= $JAVA _home/lib/export path=/usr/local/ruby/ Bin: $PATH: $JAVA _home/bin
2.2.5 Restart environment variables to make configuration effective
Source/etc/profile

See if it takes effect

The following word indicates that the installation was successful and then the Tomcat installation

2.3 Installing tomcat2.3.1 Decompression Tomcat
TAR-ZXVF apache-tomcat-7.0.56.tar.gz
2.3.2 renamed to Tomcat7
MV apache-tomcat-7.0.56 TOMCAT7
2.3.3 Modifying Tomcat memory (JVM memory)

I've put Tomcat in the/home directory.

vi/home/tomcat7/bin/catalina.sh

Add in Inside

Java_opts= "-server-xms1024m-xmx1024m-xx:permsize=512m-xx:maxnewsize=512m-xx:maxpermsize=512m"
2.3.4 Modifying the operating mode
Vi/home/tomcat7/conf/server.xml

Tim Plus

<!--Configure Apr--    <connector executor= "Tomcatthreadpool"               port= "8080" protocol= " Org.apache.coyote.http11.Http11AprProtocol "               uriencoding=" UTF-8 "enablelookups=" false "acceptcount="               connectiontimeout= "maxkeepaliverequests="               redirectport= "8443"/>

A server.xml complete configuration is posted below

<?xml version= ' 1.0 ' encoding= ' utf-8 '? ><server port= "9016" shutdown= "Shutdown" > <!--off HTTPS security verification-- <listener classname= "Org.apache.catalina.core.AprLifecycleListener" sslengine= "Off"/> <listener className = "Org.apache.catalina.core.JasperListener"/> <listener classname= " Org.apache.catalina.core.JreMemoryLeakPreventionListener "/> <listener classname=" Org.apache.catalina.mbeans.GlobalResourcesLifecycleListener "/> <listener classname=" Org.apache.catalina.core.ThreadLocalLeakPreventionListener "/> <GlobalNamingResources> <resource name= "Userdatabase" auth= "Container" type= "Org.apache.catalina.UserDatabase" description= "User Databa              SE, can be updated and saved "factory=" Org.apache.catalina.users.MemoryUserDatabaseFactory " Pathname= "Conf/tomcat-users.xml"/> </GlobalNamingResources> <service name= "Catalina" > <!--the con Nectors can use a shared exEcutor, can define one or more named thread pools--> <!--configuration Thread--<executor name= "Tomcatthreadpool" nameprefix= "catalina-exec-" maxthreads= "minsparethreads=" maxidletime= "4000"/> <!- -Configure APR--<connector executor= "Tomcatthreadpool" port= "8080" protocol= "org.apache.coyote.http11.h Ttp11aprprotocol "uriencoding=" UTF-8 "enablelookups=" false "acceptcount=" ConnectionTimeout = "maxkeepaliverequests=" "redirectport=" 8443 "/> <connector port=" 9109 "protocol=" ajp/ 1.3 "redirectport=" 8443 "/> <engine name=" Catalina "defaulthost=" localhost "> <realm classname=" Org.apa               Che.catalina.realm.LockOutRealm "> <realm classname=" Org.apache.catalina.realm.UserDatabaseRealm " Resourcename= "Userdatabase"/> </Realm> 2.4 Installing the tomcat-native2.4.1 into the/home/tomcat7/bin/
Cd/home/tomcat7/bin
2.4.2 Decompression tomcat-native.tar.gz
TAR-ZXVF tomcat-native.tar.gz
2.4.3 into the extracted directory
CD tomcat-native-1.1.31-src/jni/native
2.4.4 detection, compilation, installation
./configure--with-apr=/usr/local/apr/bin/apr-1-config--with-java-home=/usr/local/java/jdk1.7.0_76 && Make && make install
2.5 Installing APR

Need to install apr-1.5.2.tar.gz and apr-util-1.5.4.tar.gz

2.5.1 Decompression apr-1.5.2.tar.gz and apr-util-1.5.4.tar.gz
TAR-ZXVF APR-1.5.2.TAR.GZTAR-ZXVF apr-util-1.5.4.tar.gz
2.5.2 detects, compiles, installs into apr-1.5.2, executes
./configure--prefix=/usr/local/apr && make && make install
Go to apr-util-1.5.4, execute
./configure--with-apr=/usr/local/apr/--prefix=/usr/local/apr-utils && make && make install
2.6 Modifying the maximum number of file handles and the number of open files

Since open files are much more, consider modifying the default number of open files

2.6.1 modifying/etc/sysctl.conf
Net.ipv4.ip_local_port_range = 10240 65535net.ipv4.ip_nonlocal_bind = 1
2.6.2 adds the following two lines of records to the/etc/security/limits.conf last
* Soft nofile 65535 * hard nofile 65535
2.6.3 Loading Bridge Module
Modprobe Bridge
2.6.4 re-loaded into sysctl to make its change effective
2.6.5 again exit re-login, with ulimit-a view

You can see that the open files have been changed from the default 1024 to 65535

2.7 Starting Tomcat
/home/tomcat7/bin/startup.sh

The following prompt indicates a successful configuration

III. Handling of error cases

3.1, start Tomcat times "The APR based Apache Tomcat Native Library which allows optimal performance in production Envi Ronments was wasn't found on the Java.library.path:/usr/local/apr/lib "

Solution Solutions: Make sure the tomcat-native installation is successful, otherwise perform the above 2.5, if it is still unsuccessful, follow the steps below #vi/opt/tomcat_api_8035/bin/catalina.sh catalina_opt S= "-djava.library.path=/usr/local/apr/lib"3.2, installing the APR times' Neither the java_home nor the JRE_HOME environment variable is defined 'Solution Solutions: This is not set environment Java_home with JAVA_JRE directory, make sure the JDK is installed successfully, verify that the/ETC/PROFILE environment variable is configured correctly3.3, the following error was found in the output when executing sysctl-pnet.ipv4.ip_forward = 0Net.ipv4.conf.default.rp_filter = 1net.ipv4.conf.default.accept_source_route = 0KERNEL.SYSRQ = 0kernel.core_uses_pid = 1net.ipv4.tcp_syncookies = 1error: "Net.bridge.bridge-nf-call-ip6tables" is an unknown keyerror: "Net.bridge.bridge-nf-call-iptables" is an unknown keyerror: "Net.bridge.bridge-nf-call-arptables" is an unknown keyKERNEL.MSGMNB = 65536Kernel.msgmax = 65536Kernel.shmmax = 68719476736Kernel.shmall = 4294967296cause: The above 3 parameters depend on the bridge module, if it is not loaded, it will now be the output error aboveSolution Solutions: Execute modprobe Bridge command, Load Bridge module

Go Configuring Tomcat+apr+native under Linux to handle high concurrency

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.