Brush 32 interview questions: What do you do performance tuning on tomcat?

image.png

background

Development of java java application programmers, usually choose to use tomcat release, but:
how to take full control of tomcat, and let it play the best performance?

This interview is also a hot issue, with many years of practice, I was Li Fuchun, to sum up today.

Use the tomcat

download

Now the latest stable release is tomcat9, the download page: https://tomcat.apache.org/download-90.cgi

Download the difference between five kinds of package

file

Generally, we chose the core package running tomcat, or directly select docker mirrored to run;

tomcat directory Description:

file

installation

Directly extracted, unzip command:tar -zxvf tomcat-xxx.tar.gz

Starting and stopping

Follow the instructions in the guide running.txt two ways to start:

1, sh ${catalina.home}/bin/startup.sh 
2,  sh ${catalina.home}/bin/catalina.sh start

Corresponding to the two ways to stop tomcat:

1, sh ${catalina.home}/bin/shutdown.sh
2,  sh ${catalina.home}/bin/catalina.sh stop 

Journal

Log produced into four groups tomcat

1, catalina.date.out recently at all levels of logging;
2, localhost-date.log error log

Real-time View Log command: tail -f catalina.out

AJP protocol

Tomcat generally used to establish a connection with the other HTTP server.

For example, Apache + Tomcat do static and dynamic separation:

apache handle all static resources;

apache dynamic resource request forwarded by the Tomcat JK (load balancing components), by AJP protocol.

tomcat monitoring

Leave the default tomcat webapps under the ROOT, host-manager, manager application, you can monitor the status tomcat single node.

The default is not accessible, the need to add users and permissions to see, otherwise it will report 403;

A method of increasing: conf/tomcat-user.xml

<role rolename='admin' />
...
<user username='admin' password='admin' roles='admin,admin-gui,admin-script,
manager-script,manager-gui,manager-jmx,manager-status' />

Monitoring the following page:

image.png
server status: you can see the version information and tomcat jvm, the partition information jvm internal tomcat thread pool state;
image.png

manager-app: management of applications running under tomcat, provide control buttons, start, stop, restart, unloading, as well as non-stop service to install new applications;
image.png

host-manger: Providing the management virtual host, i.e., the alias configuration and the secondary path to the application tomcat.
image.png

tomcat tuning of IO

tomcat9 default use of java nio io process.
can be seen from the log and configuration files.

09-Apr-2020 07:46:27.606 信息 [main] org.apache.coyote.AbstractProtocol.start 
开始协议处理句柄["http-nio-8080"]

APR optimize IO

Use apr (Apache Portable Runtime), to solve the problem of asynchronous io from the operating system level, you can greatly improve performance.
If linux installed apr and tomcat-native, the tomcat started to support the apr;

NIO optimize the old version of BIO

If the old version of tomcat using BIO (the log can be seen), can be adjusted to NIO, adjustment method:
conf/server.xml

The old configuration:

<connector protocol="HTTP/1.1" />

The new configuration:

//tomcat6选择nio1
<connector protocol="org.apache.coyote.http11.Http11NioProtocol" />
//tomcat8选择nio2,apr性能更好
<connector protocol="org.apache.coyote.http11.Http11Nio2Protocol" />

<connector protocol="org.apache.coyote.http11.Http11AprProtocol" />

tomcat thread pool tuning

tomcat not enabled by default thread pool, you can enable the thread pool threads to improve efficiency

Thread pool parameters:

file

Custom thread pool

    <Executor name="tomcatThreadPool" namePrefix="catalina-exec-"
        maxThreads="150" minSpareThreads="4"/>

Enable Configuration Connector

<connector executor="tomcatThreadPool">

connector parameters

file

The tuning parameters tomcat jvm

GC optimization

#gc优化
JAVA_GC="-XX:SurvivorRatio=10 
-XX:MaxTenuringThreshold=15 
-XX:NewRatio=2 
-XX:+DisableExplicitGC 
-Djava.security.egd=file:/dev/./urandom"

file

jvm and optimized thread pool

JVM_LEVEL="info"
JVM_Xms="100m"
JVM_Xmx="2048m"
JVM_Xmn="600m"
JVM_Xss="256k"
TOMCAT_acceptCount=4096 线程可以接受的请求数量
TOMCAT_maxThreads=512 最大线程数
TOMCAT_minSpareThreads=512 初始线程数

file

summary

Benpian review the basics of the tomcat.

As well as some basic knowledge to use the built-in monitor tomcat monitoring of java applications.

Then combined with work experience, tomcat tuning from three aspects io, thread pool, jvm

The original is not easy, thumbs concern support about it! Please indicate the source, let us complementarity and common progress, welcomed the communication.
I will continue to share Java programming knowledge and software programmers to develop career path, welcome attention, I put together a variety of resources all these years to learn programming, public concern number 'Li Fuchun continuous output' Send 'learning materials' share to you!

Guess you like

Origin www.cnblogs.com/snidget/p/12664761.html