In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-02-28 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/03 Report--
This article introduces the knowledge of "how to use Tomcat Native to improve the efficiency of Tomcat IO". Many people will encounter this dilemma in the operation of actual cases, so let the editor lead you to learn how to deal with these situations. I hope you can read it carefully and be able to achieve something!
Brief introduction
There are many kinds of IO, from the beginning of Block IO, to nonblocking IO, to IO multiplexing and asynchronous IO, step by step to improve the performance of IO to the extreme.
Today we will introduce how to use Tomcat Native to improve the efficiency of Tomcat IO.
The connection mode of Tomcat
Connectors are used in Tomcat to handle communication with external clients. Connecter is mainly used to accept requests from external clients and transfer them to the processing engine for processing.
There are two kinds of Connector in Tomcat. One is HTTP connector, the other is AJP connector.
HTTP connector should be easy to understand. It is also the default connector used by tomcat.
There is also a connector called AJP,AJP, which is mainly used to communicate with web servers, because the speed of AJP protocol is faster than that of HTTP, so AJP can also build tomcat clusters through AJP in addition to communicating with other webserver.
Both of these methods support 4 protocols, which are BIO,NIO,NIO2 and APR respectively.
# the following four Connector implementations process the Http request org.apache.coyote.http11.Http11Protocol directly from the client: the connector that supports the HTTP/1.1 protocol. Org.apache.coyote.http11.Http11NioProtocol: a connector that supports HTTP/1.1 protocol + New IO. Org.apache.coyote.http11.Http11Nio2Protocol: a connector that supports HTTP/1.1 protocol + New IO2. Org.apache.coyote.http11.Http11AprProtocol: using APR (Apache portable runtime) technology connectors, using Native# the following four implementation methods is to deal with web server org.apache.coyote.ajp.AjpProtocol: using AJP protocol connectors to achieve communication with web server (such as Apache httpd) org.apache.coyote.ajp.AjpNioProtocol:SJP protocol + New IOorg.apache.coyote.ajp.AjpNio2Protocol:SJP protocol + New IO2org.apache.coyote.ajp.AjpAprProtocol:AJP + APR
Let's talk about the difference between them. BIO is block IO is the most basic IO way, and we configure it like this:
The following versions of Tomcat7 run in bio mode by default. Tomcat has removed support for BIO since Tomcat version 8.5.
New IO is an IO approach based on java.nio packages and their subpackages. It can provide non-blocking IO mode and has more efficient operation efficiency than traditional BIO.
Let's configure New IO as follows:
What's the difference between New IO and New IO2?
New IO2 is an IO method introduced in tomcat8, and we can configure it as follows:
Apr is more advanced in this way, and this is the main role of tomcat native that we are going to talk about today.
APR and Tomcat Native
Apr, whose full name is Apache Portable Runtime, is a highly portable library that is the core of Apache HTTP Server 2.x. APR has many uses, including access to advanced IO functions (such as sendfile,epoll and OpenSSL), operating system-level functions (generating random numbers, system state, etc.), and native process processing (shared memory, NT pipes, and Unix sockets).
Tomcat can call the core dynamic link library of Apache HTTP server in the form of JNI to handle file reading or network transfer operations, thus greatly improving the performance of Tomcat in dealing with static files.
By using APR, we can obtain the following features:
Non-blocking I PUBO and request connection retention.
OpenSSL and TLS/SSL are supported.
Tomcat Native is a library through which Tomcat can use APR.
So the premise of using Tomcat Native is that you need to install APR library,OpenSSL and JDK.
We can install apr and openssl in the following ways:
Debian based linux system:
Apt-get install libapr1.0-dev libssl-dev
Rpm based Linux system:
Yum install apr-devel openssl-devel
Under windows, tcnative is provided in the form of a dll, which we can download and use directly.
But under linux, because the platform is different, tcnative needs to compile itself under linux.
Generally speaking, we can find the source package of tcnative in bin/tomcat-native.tar.gz. Decompress it.
Run the configure command first:
. / configure-- with-apr=/usr/bin/apr-1-config\-- with-java-home=/home/jfclere/JAVA/jdk1.7.0_80/\-- with-ssl=yes\-- prefix=$CATALINA_HOME
Then perform make operation:
Make & & make install
The generated lib file will be placed in $CATALINA_HOME/lib.
Using APR in tomcat
Once tcnative is installed, we can use APR in tomcat.
First check if there are the following configurations in conf/server.xml:
Then we need to modify $CATALINA_HOME/bin/setenv.sh to add tc-native 's lib file to LD_LIBRARY_PATH.
LD_LIBRARY_PATH=$LD_LIBRARY_PATH:$CATALINA_HOME/libexport LD_LIBRARY_PATH
Finally, add the connection to APR:
Just run it.
From the log, we will find the following:
Org.apache.catalina.core.AprLifecycleListener initINFO: Loaded APR based Apache Tomcat Native library 1.x.y.org.apache.catalina.core.AprLifecycleListener initINFO: APR capabilities: IPv6 [true], sendfile [true], accept filters [false], random [true]. Org.apache.coyote.http11.Http11AprProtocol initINFO: Initializing Coyote HTTP/1.1 on http-8080
Indicates that APR has been installed and is already in use.
This is the end of "how to use Tomcat Native to improve Tomcat IO efficiency". Thank you for reading. If you want to know more about the industry, you can follow the website, the editor will output more high-quality practical articles for you!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.