优化Tomcat篇:调增tomcat6响应池

本文介绍如何通过调整Tomcat配置文件server.xml中的参数来提升Tomcat服务器的性能,并详细介绍配置APR的过程,以实现更好的可伸缩性和性能。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

查找tomcat6安装目录下conf目录中的server.xml文件,进行编辑
屏蔽tomcat默认Connector:
<!–Connector port=”8080″ protocol=”HTTP/1.1″
connectionTimeout=”20000″
redirectPort=”8443″ /-->
创建高线程的Connector:
<Connector executor="tomcatThreadPool" port="8080" protocol="HTTP/1.1" maxHttpHeaderSize="8192" useBodyEncodingForURI="true" maxThreads="1000" enableLookups="false" redirectPort="8443" acceptCount="100" compression="on" compressionMinSize="2048" compressableMimeType="text/html,text/xml,text/javascript,text/css,text/plain" connectionTimeout="20000" disableUploadTimeout="true" URIEncoding="UTF-8"/>
<Connector port=”8080″
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
两个可以在 http://archive.apache.org/dist/apr/找到。
tomcat-native-1.1.24-src.tar.gz 
可以在  http://archive.apache.org/dist/tomcat/tomcat-connectors/native/ 目录下找到。
下面是 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-----------------------
<Connector port="8080 " redirectPort="8443"
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---------------------
<Connector port="8081"
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" />
---------------------------------------------------
资源下载链接为: https://pan.quark.cn/s/9e7ef05254f8 行列式是线性代数的核心概念,在求解线性方程组、分析矩阵特性以及几何计算中都极为关键。本教程将讲解如何用C++实现行列式的计算,重点在于如何输出分数形式的结果。 行列式定义如下:对于n阶方阵A=(a_ij),其行列式由主对角线元素的乘积,按行或列的奇偶性赋予正负号后求和得到,记作det(A)。例如,2×2矩阵的行列式为det(A)=a11×a22-a12×a21,而更高阶矩阵的行列式可通过Laplace展开或Sarrus规则递归计算。 在C++中实现行列式计算时,首先需定义矩阵类或结构体,用二维数组存储矩阵元素,并实现初始化、加法、乘法、转置等操作。为支持分数形式输出,需引入分数类,包含分子和分母两个整数,并提供与整数、浮点数的转换以及加、减、乘、除等运算。C++中可借助std::pair表示分数,或自定义结构体并重载运算符。 计算行列式的函数实现上,3×3及以下矩阵可直接按定义计算,更大矩阵可采用Laplace展开或高斯 - 约旦消元法。Laplace展开是沿某行或列展开,将矩阵分解为多个小矩阵的行列式乘积,再递归计算。在处理分数输出时,需注意避免无限循环和除零错误,如在分数运算前先约简,确保分子分母互质,且所有计算基于整数进行,最后再转为浮点数,以避免浮点数误差。 为提升代码可读性和可维护性,建议采用面向对象编程,将矩阵类和分数类封装,每个类有明确功能和接口,便于后续扩展如矩阵求逆、计算特征值等功能。 总结C++实现行列式计算的关键步骤:一是定义矩阵类和分数类;二是实现矩阵基本操作;三是设计行列式计算函数;四是用分数类处理精确计算;五是编写测试用例验证程序正确性。通过这些步骤,可构建一个高效准确的行列式计算程序,支持分数形式计算,为C++编程和线性代数应用奠定基础。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值