admin 管理员组文章数量: 1184232
性能优化
通常我们的应用都是部署在tomcat中,那么针对tomcat可以进行如下配置优化
删减配置
- 移除conf/web.xml中的org.apache.catalina.servlets.DefaultServlet
- 移除conf/web.xml中的org.apache.jasper.servlet.JspServlet
JspServlet:编译并且执行Jsp页面
DefaultServlet:处理静态资源
视情况而定,不需要处理Jsp和静态资源时即可移除掉 - 移除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> - 如果程序是REST JSON、Content-Type或者MIME TYPE:application/json时移除conf/web.xml中的mime-mapping
<mime-mapping><extension>123</extension><mime-type>application/vnd.lotus-1-2-3</mime-type> </mime-mapping> <mime-mapping><extension>3dml</extension><mime-type>text/vnd.in3d.3dml</mime-type> </mime-mapping> <mime-mapping><extension>3ds</extension><mime-type>image/x-3ds</mime-type> </mime-mapping> - 移除conf/web.xml中的session-config
<session-config><session-timeout>30</session-timeout> </session-config> - 移除Valve
valve作用打印accesslog,可以通过nginx的AccessLog打印该日志<Valve className="org.apache.catalina.valves.AccessLogValve" directory="logs" prefix="localhost_access_log." suffix=".txt" pattern="%h %l %u %t "%r" %s %b" />
配置调整
- 关闭自动重载
conf/server.xml中Context元素的reloadable=false<Context docBase="D:/compile/demo" reloadable="false"> </Context> - 修改连接线程池数量
conf/server.xml中的Executor<Executor name="tomcatThreadPool" namePrefix="catalina-exec-"maxThreads="150" minSpareThreads="4"/>
JVM调优
-
内存设置
JAVA_OPTS="-Xms256m -Xmx512m -Xss1024K -XX:PermSize=256m -XX:MaxPermSize=512m" -
调整GC算法
如果JAVA版本小于9,默认PS MarkSweep,可选设置CMS、G1。
如果JAVA9的话,默认G1
Springboot下的tomcat参数设置
- 继承WebServerFactoryCustomizer类
public class TomcatConfiguration implements WebServerFactoryCustomizer<ConfigurableWebServerFactory> {@Overridepublic void customize(ConfigurableWebServerFactory factory) {factory.setPort(8080);}
}
- application.properties
#线程池
server.tomcat.max-threads=200
server.tomcat.min-spare-threads=10#取消JspServlet
server.jsp-servlet.registered=false#取消 AccessLogValve
server.tomcat.accesslog.enabled=false
本文标签: 性能优化
版权声明:本文标题:性能优化 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.roclinux.cn/b/1686701922a26833.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论