失效链接处理 |
Tomcat性能优化篇笔记 PDF 下载
本站整理下载:
提取码:lesh
相关截图:
主要内容:
01 性能优化
Tomcat性能指标:吞吐量、响应时间、错误数、线程池、CPU 、内存等。
使用jmeter进行压测,然后观察相关指标 咕泡学院 只为更好的你
使用命令查看相关指标
使用工具查看相关指标
1.1 优化思路
1.1.1 conf/server.xml核心组件
Server
官网描述 :Server interface which is rarely customized by users. 【pass】
Service
官网描述 :The Service element is rarely customized by users. 【pass】
Connector
官网描述 :Creating a customized connector is a significant effort. 【 need 】
Engine
官网描述 :The Engine interface may be implemented to supply custom Engines, though this is uncommon.
【pass】
Host
官网描述 :Users rarely create custom Hosts because the StandardHost implementation provides significant
additional functionality. 【pass】
Context
官网描述 :The Context interface may be implemented to create custom Contexts, but this is rarely the case
because the StandardContext provides significant additional functionality. 【 maybe 】 Context既然代表的是web应用,是和我们比较接近的,这块我们考虑对其适当的优化 conclusion:Connector and Context
1.1.2 conf/server.xml非核心组件
官网 :https://tomcat.apache.org/tomcat-8.0-doc/config/index.html
Listener
01 查看tomcat进程pid ps -ef | grep tomcat 02 查看进程的信息 cat /pro/pid/status 03 查看进程的cpu和内存 top -p pid jconsole、jvisualvm、arthas、psi-probe等 咕泡学院 只为更好的你
Global Resources
The GlobalNamingResources element defines the global JNDI resources for the [Server] (https://tomcat.apache.org/tomcat-8.0-doc/config/server.html) Valve
Realm
A Realm element represents a "database" of usernames, passwords, and roles (similar to Unix groups) assigned to those users.
1.1.3 conf/web.xml
Listener(即监听器)定义的组件,可以在特定事件发生时执行特定的操作;被监听的事件通常是Tomcat的启动和停止。 <Listener className="org.apache.catalina.core.AprLifecycleListener" SSLEngine="on" /> <!--监听内存溢出--> <Listener className="org.apache.catalina.core.JreMemoryLeakPreventionListener" /> <Listener className="org.apache.catalina.mbeans.GlobalResourcesLifecycleListener" /> <Listener className="org.apache.catalina.core.ThreadLocalLeakPreventionListener" /> GlobalNamingResources元素定义了全局资源,通过配置可以看出,该配置是通过读取$TOMCAT_HOME/ conf/tomcat-users.xml实现的。 <GlobalNamingResources> <Resource name="UserDatabase" auth="Container" type="org.apache.catalina.UserDatabase" description="User database that can be updated and saved" factory="org.apache.catalina.users.MemoryUserDatabaseFactory" pathname="conf/tomcat-users.xml" /> </GlobalNamingResources> <Valve className="org.apache.catalina.valves.AccessLogValve" directory="logs" prefix="localhost_access_log" suffix=".txt" pattern="%h %l %u %t "%r" %s %b" /> Realm,可以把它理解成“域”;Realm提供了一种用户密码与web应用的映射关系,从而达到角色安全管理的作用。在本例 中,Realm的配置使用name为UserDatabase的资源实现。而该资源在Server元素中使用GlobalNamingResources配置 <Realm className="org.apache.catalina.realm.LockOutRealm"> <!-- This Realm uses the UserDatabase configured in the global JNDI resources under the key "UserDatabase". Any edits that are performed against this UserDatabase are immediately available for use by the Realm. --> <Realm className="org.apache.catalina.realm.UserDatabaseRealm" resourceName="UserDatabase"/> </Realm> 咕泡学院 只为更好的你
全局的web.xml文件有些标签用不到的,可以删除掉。
1.1.4 JVM层面
因为Tomcat运行起来本身就是一个Java进程,所以这块可以参照JVM部分的优化思路。
1.2 配置优化
1.2.1 减少web.xml/server.xml中标签
最终观察tomcat启动日志[时间/内容],线程开销,内存大小,GC等
DefaultServlet
官网 :User Guide->Default Servlet
The default servlet is the servlet which serves static resources as well as serves the directory listings (if
directory listings are enabled).
JspServlet
<servlet><servlet-name>default</servlet-name> <servlet-class>org.apache.catalina.servlets.DefaultServlet</servlet-class> <init-param> <param-name>debug</param-name> <param-value>0</param-value> </init-param> <init-param> <param-name>listings</param-name> <param-value>false</param-value> </init-param> <load-on-startup>1</load-on-startup> </servlet> <servlet-mapping> <servlet-name>default</servlet-name> <url-pattern>/</url-pattern> </servlet-mapping> <servlet> <servlet-name>jsp</servlet-name> <servlet-class>org.apache.jasper.servlet.JspServlet</servlet-class> <init-param> <param-name>fork</param-name> <param-value>false</param-value> </init-param> <init-param> <param-name>xpoweredBy</param-name> <param-value>false</param-value> </init-param> <load-on-startup>3</load-on-startup> </servlet> 咕泡学院 只为更好的你
welcome-list-file
mime-mapping移除响应的内容
支持的下载打开类型
session-config
默认jsp页面有session,就是在于这个配置
1.2.2 调整优化server.xml中标签
1.2.2.1 Connector标签
protocol属性
对于protocol="HTTP/1.1",查看源码
构造函数 <servlet-mapping> <servlet-name>jsp</servlet-name> <url-pattern>*.jsp</url-pattern> <url-pattern>*.jspx</url-pattern> </servlet-mapping> <welcome-file-list> <welcome-file>index.html</welcome-file> <welcome-file>index.htm</welcome-file> <welcome-file>index.jsp</welcome-file> </welcome-file-list> <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> <session-config> <session-timeout>30</session-timeout> </session-config> <Connector port="8080" protocol="HTTP/1.1" connectionTimeout="20000" redirectPort="8443" />
|