Tomcat参数详解

<Connector port="8080" protocol="HTTP/1.1"  
    maxPostSize="-1"   
    maxHttpHeaderSize="8192"
    maxConnections="10000"
    acceptCount="1000"
    connectionTimeout="3000"
    minProcessors="100"
    maxProcessors="1000"

    minSpareThreads="100"  
    maxSpareThreads="1000"
    maxThreads="1000"

    enableLookups="false"  
    compression="on"  
    compressionMinSize="2048"  
    compressableMimeType="text/html,text/xml,text/javascript,text/css,text/plain"
    URIEncoding="utf-8"                      
    redirectPort="8443"  
    disableUploadTimeout="true"
/>  

一、连接相关

  • maxConnections:在任何给定时间内,服务器接收并处理的最大连接数,默认值因链接类型不同有所区别,BIO默认值同maxThreads属性,如果使用了Executor,将使用Executor的maxThreads属性。NIO默认值为10000,APR默认值为8*1024。
  • acceptCount:当所有请求线程都被占用时,请求将被放到请求队列,队列的长度由acceptCount决定,超过该值时,接收到的请求将被拒绝。默认值为100。
  • connectionTimeout:连接超时时间

问题1:Tomcat能处理的最大请求数是多少?
Tomcat能处理的最大请求数由maxConnections和acceptCount决定。

问题2:connectionTimeout含义的理解?
  以前对这个参数一直不是很清楚,最终通过查看tomcat的源码,才知道该参数是用在了下面这个方法上:socket.setSoTimeout(int timeout)
  下面是JDK对该方法的解释,大致的意思是说调用socket的输入流的read方法会阻塞设置的时长,如果超过给定时间没有读取到数据,就会抛出SocketTimeoutException。
【Enable/disable SO_TIMEOUT with the specified timeout, in milliseconds. With this option set to a non-zero timeout, a read() call on the InputStream associated with this Socket will block for only this amount of time. If the timeout expires, a java.net.SocketTimeoutException is raised, though the Socket is still valid. The option must be enabled prior to entering the blocking operation to have effect. The timeout must be > 0. A timeout of zero is interpreted as an infinite timeout.】
  可参考下面的链接获取更加详细的解释:
http://cuisuqiang.iteye.com/blog/1725348

问题3:minProcessors与maxProcessors有什么用?
  minProcessors与maxProcessors是早期的tomcat 5.0之前的配置了。tomcat 5.0的时候,Connector每接受到一个请求,就会创建一个Processor,也就是一个线程。为了限制线程的个数,会把所有的Processor放在一个栈中,通过minProcessors和maxProcessors来控制大小。

二、线程池相关

Tomcat接收到请求后,会封装成SocketProcessor,然后交给线程池处理。

建议先了解一下线程池的几大核心参数:
https://blog.csdn.net/u011983531/article/details/49369489

  • minSpareThreads:核心线程数。处理客户端请求的线程池用的就是这个参数
  • maxSpareThreads:核心线程数。目前没看到使用场景
  • maxThreads:最大线程数

问题1:Tomcat线程池是由哪几个参数决定的
minSpareThreads和maxThreads,一个是核心线程数,一个是最大线程数。

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值