设为首页 收藏本站
查看: 1350|回复: 1

[经验分享] Tomcat6配置打开线程池

[复制链接]
累计签到:1 天
连续签到:1 天
发表于 2014-10-17 08:30:57 | 显示全部楼层 |阅读模式
线程池配置(Tomcat6下)

使用线程池,用较少的线程处理较多的访问,可以提高tomcat处理请求的能力。使用方式:

首先。打开/conf/server.xml,增加

<Executor name="tomcatThreadPool" namePrefix="catalina-exec-"
        maxThreads="500" minSpareThreads="20" maxIdleTime="60000" />

最大线程500(一般服务器足以),最小空闲线程数20,线程最大空闲时间60秒。

然后,修改<Connector ...>节点,增加executor属性,如:

<Connectorexecutor="tomcatThreadPool"
               port="80"
protocol="HTTP/1.1"
maxThreads="600"  
minSpareThreads="100"
maxSpareThreads="300"
               connectionTimeout="60000"
               keepAliveTimeout="15000"
               maxKeepAliveRequests="1"
               redirectPort="443"
               ....../>

maxThreads:Tomcat可创建的最大的线程数,每一个线程处理一个请求;

minSpareThreads:最小备用线程数,tomcat启动时的初始化的线程数;

maxSpareThreads:最大备用线程数,一旦创建的线程超过这个值,Tomcat就会关闭不再需要的socket线程;

acceptCount:指定当所有可以使用的处理请求的线程数都被使用时,可以放到处理队列中的请求数,
就是被排队的请求数,超过这个数的请求将拒绝连接。

connnectionTimeout:网络连接超时,单位:毫秒。设置为0表示永不超时,这样设置有隐患的。通常可设置为30000毫秒。
enableLookups:是否允许DNS查询



注意:可以多个connector公用1个线程池。



3、调整连接相关Connector的参数:

<Connector executor="tomcatThreadPool"
               port="80" protocol="HTTP/1.1"
               connectionTimeout="60000"
               keepAliveTimeout="15000"
               maxKeepAliveRequests="1"
               redirectPort="443"
               maxHttpHeaderSize="8192" URIEncoding="UTF-8" enableLookups="false" acceptCount="100" disableUploadTimeout="true"/>



参数说明:

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中)


运维网声明 1、欢迎大家加入本站运维交流群:群②:261659950 群⑤:202807635 群⑦870801961 群⑧679858003
2、本站所有主题由该帖子作者发表,该帖子作者与运维网享有帖子相关版权
3、所有作品的著作权均归原作者享有,请您和我们一样尊重他人的著作权等合法权益。如果您对作品感到满意,请购买正版
4、禁止制作、复制、发布和传播具有反动、淫秽、色情、暴力、凶杀等内容的信息,一经发现立即删除。若您因此触犯法律,一切后果自负,我们对此不承担任何责任
5、所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其内容的准确性、可靠性、正当性、安全性、合法性等负责,亦不承担任何法律责任
6、所有作品仅供您个人学习、研究或欣赏,不得用于商业或者其他用途,否则,一切后果均由您自己承担,我们对此不承担任何法律责任
7、如涉及侵犯版权等问题,请您及时通知我们,我们将立即采取措施予以解决
8、联系人Email:admin@iyunv.com 网址:www.yunweiku.com

所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其承担任何法律责任,如涉及侵犯版权等问题,请您及时通知我们,我们将立即处理,联系人Email:kefu@iyunv.com,QQ:1061981298 本贴地址:https://www.yunweiku.com/thread-26189-1-1.html 上篇帖子: linux安装tomcat,并发布war包 下篇帖子: 问题解决:1040-Too many connections 错误
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

扫码加入运维网微信交流群X

扫码加入运维网微信交流群

扫描二维码加入运维网微信交流群,最新一手资源尽在官方微信交流群!快快加入我们吧...

扫描微信二维码查看详情

客服E-mail:kefu@iyunv.com 客服QQ:1061981298


QQ群⑦:运维网交流群⑦ QQ群⑧:运维网交流群⑧ k8s群:运维网kubernetes交流群


提醒:禁止发布任何违反国家法律、法规的言论与图片等内容;本站内容均来自个人观点与网络等信息,非本站认同之观点.


本站大部分资源是网友从网上搜集分享而来,其版权均归原作者及其网站所有,我们尊重他人的合法权益,如有内容侵犯您的合法权益,请及时与我们联系进行核实删除!



合作伙伴: 青云cloud

快速回复 返回顶部 返回列表