从网上找了相关的tomcat优化的相关文章,现整理如下,如有错误之处请指正:
1、JAVA虚拟机性能优化
2、在tomcat配置文件server.xml中的<Connector ... />配置中,和连接数相关的参数有:
minProcessors:最小空闲连接线程数,用于提高系统处理性能,默认值为10
maxProcessors:最大连接线程数,即:并发处理的最大请求数,默认值为75
acceptCount:允许的最大连接数,应大于等于maxProcessors,默认值为100
enableLookups:是否反查域名,取值为:true或false。为了提高处理能力,应设置为false
connectionTimeout:网络连接超时,单位:毫秒。设置为0表示永不超时,这样设置有隐患的。通常可设置为30000毫秒。
3、tomcat的nio配置(非阻塞式处理请求)
将原来的tomcat中的server.xml中的
<Connector port="8080" protocol="HTTP/1.1" connectionTimeout="20000" redirectPort="8443" />
修改成
<Connector port="8080" protocol="org.apache.coyote.http11.Http11NioProtocol" connectionTimeout="20000" redirectPort="8443" />
默认的处理方式使用的是org.apache.coyote.http11.Http11Protocol
4、将conf/web.xml中的trimSpaces设为true,如果没有手动添加上,位置如下,(将响应的jsp页面中的空行或其他无用的字节去掉)
<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>trimSpaces</param-name>
<param-value>true</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>
在初始化参数中,还有development(默认为true,在进行项目产品部署时设置为false,不检查jsp修改);
genStrAsCharArray(默认为false,修改成true, Should text strings be generated as chararrays, to improve performance in some cases? );
modificationTestInterval(默认为4,修改成true , Causes a JSP (and its dependent files) to not be checked for modification during the specified time interval (in seconds) from the last time the JSP was checked for modification. A value of 0 will cause the JSP to be checked on every access. Used in development mode only. [4]If development has to be set to true
for any reason (such as dynamic generation of JSPs,如果项目中有地方动态形成jsp就不要把development改成false啦), setting this to a high value will improve performance a lot. (图省事就直接copy啦)
5、 Jikes to compile JSP pages(没用过,只知道比sun的编译速度高点)