Tomcat 优化过程

1.在线上项目运行一段时间后发现tomcat应用无法访问,重启后依然不能访问。而后开始分析日志排查,首先想到的是查看tomcat 内存/线程等运行情况

2.分析步骤:

 a. 获取tomcat pid

[root@d2f28d129f00 local]# ps -ef | grep java
root         1     0  0 Jun14 ?        00:27:18 /usr/local/java/bin/java -Djava.util.logging.config.file=/usr/local/tomcat/conf/logging.properties -Djava.util.logging.manager=org.apache.juli.ClassLoaderLogManager -Djdk.tls.ephemeralDHKeySize=2048 -Djava.endorsed.dirs=/usr/local/tomcat/endorsed -classpath /usr/local/tomcat/bin/bootstrap.jar:/usr/local/tomcat/bin/tomcat-juli.jar -Dcatalina.base=/usr/local/tomcat -Dcatalina.home=/usr/local/tomcat -Djava.io.tmpdir=/usr/local/tomcat/temp org.apache.catalina.startup.Bootstrap start

--获取tomcat进程的pid, 由于当前tomcat跑在docker中,故其pid为1

 

 b.通过pid获取tomcat运行线程数

[root@d2f28d129f00 local]# ps -T -p 1 | wc -l  或者使用 ps -o nlwp 1
250

 

 c.获取tomcat运行版本

[root@dock01 ~]# docker exec -it www /usr/local/tomcat/bin/catalina.sh version
Using CATALINA_BASE:   /usr/local/tomcat
Using CATALINA_HOME:   /usr/local/tomcat
Using CATALINA_TMPDIR: /usr/local/tomcat/temp
Using JRE_HOME:        /usr/local/java
Using CLASSPATH:       /usr/local/tomcat/bin/bootstrap.jar:/usr/local/tomcat/bin/tomcat-juli.jar
Server version: Apache Tomcat/8.5.24
Server built:   Nov 27 2017 13:05:30 UTC
Server number:  8.5.24.0
OS Name:        Linux
OS Version:     3.10.0-693.el7.x86_64
Architecture:   amd64
JVM Version:    1.8.0_151-b12
JVM Vendor:     Oracle Corporation

  

d. tomcat 7.x 和 8.x 默认最大线程数均为200

 

e. 调整线程数maxThreads,修改$CATALINA_HOME/conf/server.xml文件,添加内容如下:

<Connector port="8080" protocol="HTTP/1.1"
               connectionTimeout="20000"
               redirectPort="8443" maxThreads="500" />

  

 f. 重启tomcat观察验证

#/usr/local/tomcat/bin/catalina.sh stop
#/usr/local/tomcat/bin/catalina.sh start

  

Reference: http://www.importnew.com/27309.html

 

posted @ 2018-07-04 13:59  2240930501  阅读(201)  评论(0编辑  收藏  举报