应用场景分析
如果当前的应用属于API Gateway
网关层、又或者属于REST应用、再或者属于传统应用:静态资源和JSP
动态资源我们就一定需要吗?那么我们是不是可以减少Tomcat的组件加载呢?
Yes, You Can ! Just do it.
优化方案
-
外置的Tomcat
-
定位Tomcat的
conf/web.xml
目录-
移除
welcome-file-list
<welcome-file-list> <welcome-file>index.html</welcome-file> <welcome-file>index.htm</welcome-file> <welcome-file>index.jsp</welcome-file> </welcome-file-list>
-
移除
DefaultServlet
-
移除或改变配置
jspServlet
- 定位属性
development = false
(不启用开发模式)
- 定位属性
-
移除 Valve
- 屏蔽
accessLog
- 屏蔽
-
java -jar -server
jvm
参数优化- -server:适用于提升系统的吞吐量
- -client : 适用于提升系统的访问速度
-
-
定位
conf/server.xml
-
调整线程池
<Executor name="tomcatThreadPool" namePrefix="catalina-exec-" maxThreads="99" minSpareThreads="9"/> <Connector executor="tomcatThreadPool" port="8080" protocol="HTTP/1.1" connectionTimeout="20000" redirectPort="8443" />
- 使用
jConsole、jMete
进行压测
- 使用
-
-
定位
conf/context.xml
- 关闭自动重载
<Context docBase="E:/Downloads/tomcat/target/tomcat-1.0-SNAPSHOT" reloadable="false" > </Context>
-
-
内置Tomcat (比如:
SpringBoot
)-
Maven依赖
<dependency> <groupId>org.apache.tomcat.embed</groupId> <artifactId>tomcat-embed-jasper</artifactId> </dependency>
-
application.properties
## 线程池大小 server.tomcat.maxThreads = 99 server.tomcat.minSpareThreads = 9 ## 取消 Tomcat AccessLogValve server.tomcat.accesslog.enabled = false ## 取消 JspServlet server.jspServlet.registered=false ## ...
-
网友评论