
通过优化tomcat提高网站的并发能力。
服务器所能提供CPU、内存、硬盘的性能对处理能力有决定性影响。
在conf/ tomcat-users.xml下添加用户:
<role rolename="manager"/>
<role rolename="manager-gui"/>
<role rolename="admin"/>
<role rolename="admin-gui"/>
<user username="tomcat" password="tomcat" roles="admin-gui,admin,manager-gui,manager"/>
启动tomcat,登录查看信息:
:8080/
tomcat的运行模式有3种:
1、 bio
默认的模式,性能非常低下,没有经过任何优化处理和支持.
2、 nio
nio(new I/O),是Java SE 1.4及后续版本提供的一种新的I/O操作方式(即java.nio包及其子包)。Java nio是一个基于缓冲区、并能提供非阻塞I/O操作的Java API,因此nio也被看成是non-blocking I/O的缩写。它拥有比传统I/O操作(bio)更好的并发运行性能。
3、 apr
安装起来最困难,但是从操作系统级别来解决异步的IO问题,大幅度的提高性能.
修改server.xml里的Connector节点,修改protocol为org.apache.coyote.http11.Http11NioProtocol
在tomcat中每一个用户请求都是一个线程,所以可以使用线程池提高性能。
配置:
(long) If aThreadLocalLeakPreventionListeneris configured, it will notify this executor about stopped contexts. After a context is stopped, threads in the pool are renewed. To avoid renewing all threads at the same time, this option sets a delay between renewal of any 2 threads. The value is in ms, default value is1000ms. If value is negative, threads are not renewed.
。重建线程池内的线程时,为了避免线程同时重建,每隔threadRenewalDelay(单位: ms )重建一个线程。默认值为1000 ,设置为负则不重建
Connector是Tomcat接收请求的入口,每个Connector有自己专属的端口
Connector有两种:HTTP Connector和AJP Connector
A boolean value which can be used to enable or disable the TRACE HTTP method. If not specified, this attribute is set to false.
如果需要服务器能够处理用户的HAED/TRACE请求,这个值应该设置为true,默认值是false
The default timeout for asynchronous requests in milliseconds. If not specified, this attribute is set to 10000 (10 seconds).
本文来自电脑杂谈,转载请注明本文网址:
http://www.pc-fly.com/a/jisuanjixue/article-66845-1.html
小王子
先转再看
哇