Chinaunix首页 | 论坛 | 博客
  • 博客访问: 31141
  • 博文数量: 1
  • 博客积分: 80
  • 博客等级: 民兵
  • 技术积分: 25
  • 用 户 组: 普通用户
  • 注册时间: 2011-08-04 16:16
文章分类
文章存档

2012年(1)

我的朋友

分类:

2012-07-07 09:57:27

查找tomcat6安装目录下conf目录中的server.xml文件,进行编辑
屏蔽tomcat默认Connector:
connectionTimeout=”20000″
redirectPort=”8443″ /-->
创建高线程的Connector:

executor="tomcatThreadPool" protocol="HTTP/1.1" redirectPort=”8443″ maxHttpHeaderSize=”8192″ useBodyEncodingForURI=”true” minProcessors=”100″ maxProcessors=”5000″ maxThreads=”5000″ minSpareThreads=”1000″ maxSpareThreads=”4000″ enableLookups=”false” acceptCount=”100″ compression=”on” compressionMinSize=”2048″ compressableMimeType=”text/html,text/xml,text/javascript,text/css,text/plain” connectionTimeout=”60000″ keepAliveTimeout="15000" maxKeepAliveRequests="1" disableUploadTimeout=”true” debug=”0″ URIEncoding=”UTF-8″ />
(注:加入响应线程数控制,加入压缩传递模式,调整超时设置,屏蔽调试模式)
参数说明:
• connectionTimeout - 网络连接超时,单位:毫秒。设置为0表示永不超时,这样设置有隐患的。通常可设置为30000毫秒。
• keepAliveTimeout - 长连接最大保持时间(毫秒)。此处为15秒。
• maxKeepAliveRequests - 最大长连接个数(1表示禁用,-1表示不限制个数,默认100个。一般设置在100~200之间) the maximum number of HTTP requests that can be held in the pipeline until the connection is closed by the server. Setting this attribute to 1 disables HTTP/1.0 keep-alive, as well as HTTP/1.1 keep-alive and pipelining. Setting this to -1 allows an unlimited number of pipelined or keep-alive HTTP requests. If not specified, this attribute is set to 100.
• maxHttpHeaderSize - http请求头信息的最大程度,超过此长度的部分不予处理。一般8K。
• URIEncoding - 指定Tomcat容器的URL编码格式。
• acceptCount - 指定当所有可以使用的处理请求的线程数都被使用时,可以放到处理队列中的请求数,超过这个数的请求将不予处理,默认为10个。defines the maximum queue length for incoming connection requests when all possible request processing threads are in use. Any requests received when the queue is full are refused. The default value is 10.
• disableUploadTimeout - 上传时是否使用超时机制
• enableLookups - 是否反查域名,取值为:true或false。为了提高处理能力,应设置为false
• bufferSize - defines the size (in bytes) of the buffer to be provided for input streams created by this connector. By default, buffers of 2048 bytes are provided.
• maxSpareThreads – 最多空闲连接数,一旦创建的线程超过这个值,Tomcat就会关闭不再需要的socket线程 the maximum number of unused request processing threads that are allowed to exist until the thread pool starts stopping the unnecessary threads. The default value is 50.
• maxThreads - 最多同时处理的连接数,Tomcat使用线程来处理接收的每个请求。这个值表示Tomcat可创建的最大的线程数。。 the maximum number of request processing threads to be created by this Connector, which therefore determines the maximum number of simultaneous requests that can be handled. If not specified, this attribute is set to 200.
• minSpareThreads - 最小空闲线程数,Tomcat初始化时创建的线程数 the number of request processing threads that are created when this Connector is first started. The connector will also make sure it has the specified number of idle processing threads available. This attribute should be set to a value smaller than that set for maxThreads. The default value is 4.
• minProcessors - 最小空闲连接线程数,用于提高系统处理性能,默认值为10。(用于Tomcat4中)
• maxProcessors - 最大连接线程数,即:并发处理的最大请求数,默认值为75。(用于Tomcat4中)
备注:
Tomcat4中可以通过修改minProcessors和maxProcessors的值来控制线程数。
在Tomcat5+主要对以下参数调整
maxThreads: Tomcat使用线程来处理接收的每个请求。这个值表示Tomcat可创建的最大的线程数。
acceptCount: 指定当所有可以使用的处理请求的线程数都被使用时,可以放到处理队列中的请求数,超过这个数的请求将不予处理。
connnectionTimeout : 网络连接超时,单位:毫秒。设置为0表示永不超时,这样设置有隐患的。通常可设置为30000毫秒。
minSpareThreads: Tomcat初始化时创建的线程数。
maxSpareThreads: 一旦创建的线程超过这个值,Tomcat就会关闭不再需要的socket线程。
 
 
 
 
 
 
 
 
tomcat APR的配置过程
Tomcat 可以使用 APR 来提供超强的可伸缩性和性能,更好地集成本地服务器技术。APR(Apache Portable Runtime) 是一个高可移植库,它是 Apache HTTP Server 2.x 的核心。 APR 有很多用途,包括访问高级 IO 功能 ( 例如 sendfile,epoll 和 OpenSSL) , OS 级别功能 ( 随机数生成,系统状态等等 ) ,本地进程管理 ( 共享内存, NT 管道和 UNIX sockets) 。这些功能可以使 Tomcat 作为一个通常的前台 WEB 服务器,能更好地和其它本地 web 技术集成,总体上让 Java 更有效率作为一个高性能 web 服务器平台而不是简单作为后台容器。
在产品环境中,特别是直接使用 Tomcat 做 WEB 服务器的时候,您应该使用 Tomcat Native 来提高其性能,详细配置和安装请参考 Tomcat 文档。
如果没有 apr 技术,启动 tomcat 时出现如下提示:
信息 : The APR based Apache Tomcat Native library which allows optimal performance in production environments was not found on the java.library.path: /usr/java/jdk1.6.0_06/jre/lib/i386/client:/usr/java/jdk1.6.0_06/jre/lib/i386:/usr/java/jdk1.6.0_06/jre/../lib/i386:/usr/java/packages/lib/i386:/lib:/usr/lib
按照官方说明需要:
    * APR library
    * OpenSSL libraries
openssl 可以用 yum install openssl-devel , apr 还是下载 *.gz 来安装。
apr-1.3.2.tar.gz
apr-util-1.3.2.tar.gz
两个可以在找到。
tomcat-native-1.1.24-src.tar.gz
可以在 目录下找到。
下面是 APR 的配置过程:
安装 apr
1.         tar zxvf apr-1.3.2.tar.gz
2.         cd apr-1.3.2
3.         ./configure
4.         make
5.         make install
apr 默认安装在 /usr/local/apr
安装 apr-util
1.         tar zxvf apr-util-1.3.2.tar.gz
2.         cd apr-util-1.3.2
3.         ./configure --with-apr=/usr/local/apr
4.         make
5.         make install
安装 tomcat-native
 
1.         tar zxvf tomcat-native.tar.gz
2.         cd tomcat-native-1.1.24-src/jni/native
3.         ./configure --with-apr=/usr/local/apr --with-java-home=/usr/java/jdk1.6.0_29
4.         make
5.         make install
设置 apr 的环境变量:
1.         vi /etc/profile
2.         添加以下内容 
APR_HOME=/usr/local/apr/
LD_LIBRARY_PATH=$LD_LIBRARY_PATH:$APR_HOME/lib
Export   LD_LIBRARY_PATH
3.         使配置生效 source /etc/profile
为不影响其他 tomcat 的配置,我们不采用上面的设置方法,而是直接在 tomcat 的 bin 下的 catalina.sh 中加入如下配置:
LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/usr/local/apr/lib
export LD_LIBRARY_PATH
启动 tomcat 后, 看日志,有如下一行:
信息 : APR capabilities: IPv6 [true], sendfile [true], accept filters [false], random [true].
-------------------------配置1-----------------------
maxThreads="5000"
minSpareThreads="1000"
maxSpareThreads="4000 "
enableLookups="false"
acceptCount="3500"
compression="on"
compressableM imeType="text/html,text/xml,text/javascript,text/css,text/plain"
connectionTimeout="60000"
debug="0"
URIEncoding="UTF-8" />
--------------------推荐----配置2---------------------
executor="tomcatThreadPool" protocol="HTTP/1.1" redirectPort="6203"
maxHttpHeaderSize="8192" useBodyEncodingForURI="true"
minProcessors="100"
maxProcessors="5000"
maxThreads="5000"
minSpareThreads="1000"
maxSpareThreads="4000"
enableLookups="false"
acceptCount="100"
compression="on"
compressionMinSize="2048"
compressableMimeType="text/html,text/xml,text/javascript,text/css,text/plain"
connectionTimeout="60000"
keepAliveTimeout="15000"
maxKeepAliveRequests="1"
disableUploadTimeout="true"
debug="0"
URIEncoding="UTF-8" />
---------------------------------------------------
阅读(2454) | 评论(0) | 转发(0) |
0

上一篇:没有了

下一篇:没有了

给主人留下些什么吧!~~