Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to realize concurrency Optimization in Tomcat

2025-01-16 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

Shulou(Shulou.com)06/01 Report--

This article is about how Tomcat implements concurrency optimization. The editor thinks it is very practical, so share it with you as a reference and follow the editor to have a look.

There are three common operation modes of Tomcat, which are bio,nio,apr. Apr is recommended for production environment.

Install APR

[root@liuyazhuang ~] # yum-y install apr apr-devel openssl-devel [root@liuyazhuang ~] # tar zxvf tomcat-native.tar.gz [root@liuyazhuang ~] # cd tomcat-native-1.1.24-src/jni/native [root@liuyazhuang native] #. / configure-with-apr=/usr/bin/apr-1-config-with-ssl=/usr/include/openssl/ [root@liuyazhuang native] # make & & make install

After the installation is complete, the following prompt appears

Libraries have been installed in: / usr/local/apr/lib

After a successful installation, you also need to set the environment variable for tomcat by adding one line to the catalina.sh file:

Add under this paragraph:

= # OS specific support. $var _ must_ be set to either true or false. Cygwin=false darwin=false = CATALINA_OPTS= "- Djava.library.path=/usr/local/apr/lib"

Modify the corresponding conf/server.xml on the 8080 side

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

After starting tomcat, check the log

More TOMCAT_HOME/logs/catalina.out Apr 07, 2017 11:49:12 AM org.apache.catalina.core.AprLifecycleListener init INFO: Loaded APR based Apache Tomcat Native library 1.1.31 using APR version 1.3.9. Apr 07, 2017 11:49:12 AM org.apache.catalina.core.AprLifecycleListener init INFO: APR capabilities: IPv6 [true], sendfile [true], accept filters [false], random [true]. Apr 07, 2017 11:49:12 AM org.apache.catalina.core.AprLifecycleListener initializeSSL INFO: OpenSSL successfully initialized (OpenSSL 1.0.1e 11 Feb 2013) Apr 07, 2017 11:49:13 AM org.apache.coyote.AbstractProtocol init INFO: Initializing ProtocolHandler ["http-apr-8080"] Apr 07, 2017 11:49:13 AM org.apache.coyote.AbstractProtocol init INFO: Initializing ProtocolHandler ["ajp-apr-8009"] Apr 07, 2017 11:49:13 AM org.apache.catalina.startup.Catalina load INFO: Initialization processed in 1125 ms

Tomcat optimization

1.JVM tuning

Add the following statement to TOMCAT_HOME/bin/catalina.sh, depending on the situation.

Add it to the end of the CATALINA_OPTS above:

JAVA_OPTS=-Xms512m-Xmx1024m-XX:PermSize=512M-XX:MaxNewSize=1024m-XX:MaxPermSize=1024m

Detailed explanation of parameters

-Xms JVM initializes the heap memory size

-maximum memory of the Xmx JVM heap

-Xss thread stack size

-XX:PermSize JVM non-heap initial memory allocation size

-XX:MaxPermSize JVM non-heap maximum memory

Recommendations and considerations:

The-Xms and-Xmx options are set to the same heap memory allocation to avoid adjusting the heap size after each GC. Heap memory is recommended to account for 60% / 80% of memory. Non-heap memory is non-recyclable memory, depending on the project. The thread stack size is recommended to be 256k.

The 32GB memory configuration is as follows:

JAVA_OPTS=-Xms20480m-Xmx20480m-Xss1024K-XX:PermSize=512m-XX:MaxPermSize=2048m

two。 Turn off DNS reverse query

Thank you for your reading! This is the end of this article on "how to achieve concurrency optimization in Tomcat". I hope the above content can be of some help to you, so that you can learn more knowledge. if you think the article is good, you can share it out for more people to see!

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.

Share To

Servers

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report