tomcat默认最大线程数、等待队列长度、连接超时时间

04-23 2406阅读 0评论

tomcat默认最大线程数、等待队列长度、连接超时时间

  • tomcat的默认最大线程数是200,默认核心线程数(最小空闲线程数)是10。

  • 在核心线程数满了之后,会直接启用最大线程数(和JDK线程池不一样,JDK线程池先使用工作队列再使用最大线程数),当达到最大线程数后,新的请求会添加到工作队列,工作队列长度是Integer.MAX_VALUE(2147483647)。

  • tomcat允许接收和处理的最大连接数:BIO模型的默认值等于maxThread的值(默认200),NIO模型的默认值为10000,APR/native的默认长度为8192。连接超时时间默认为20秒。

  • 当达到最大连接数后,新的连接请求添加到一个连接请求等待队列,队列默认长度100,当队列达到100后,直接拒绝此次请求返回connection refused。

  • 来着tomcat官方文档Apache Tomcat 7 Configuration Reference (7.0.109) - The HTTP Connector

  • AttributeDescription翻译
    acceptCountThe maximum queue length for incoming connection requests when all possible request processing threads are in use. Any requests received when the queue is full will be refused. The default value is 100.当所有可能的请求处理线程都在使用时,传入连接请求的最大队列长度。当队列满时收到的任何请求都将被拒绝。缺省值为100。
    connectionTimeoutThe number of milliseconds this Connector will wait, after accepting a connection, for the request URI line to be presented. Use a value of -1 to indicate no (i.e. infinite) timeout. The default value is 60000 (i.e. 60 seconds) but note that the standard server.xml that ships with Tomcat sets this to 20000 (i.e. 20 seconds). Unless disableUploadTimeout is set to false, this timeout will also be used when reading the request body (if any).在接受连接后,此连接器为显示请求URI行所等待的毫秒数。使用-1值表示没有超时(即无限超时)。默认值是60000(即60秒),但请注意Tomcat附带的标准server.xml将其设置为20000(即20秒)。除非disableUploadTimeout设置为false,否则该超时也将在读取请求正文时使用。
    keepAliveTimeoutThe number of milliseconds this Connector will wait for another HTTP request before closing the connection. The default value is to use the value that has been set for the connectionTimeout attribute. Use a value of -1 to indicate no (i.e. infinite) timeout.这个连接器在关闭连接之前等待另一个HTTP请求的毫秒数。默认值是使用为connectionTimeout属性设置的值。使用-1值表示没有超时(即无限超时)。
    maxConnectionsThe maximum number of connections that the server will accept and process at any given time. When this number has been reached, the server will accept, but not process, one further connection. This additional connection be blocked until the number of connections being processed falls below maxConnections at which point the server will start accepting and processing new connections again. Note that once the limit has been reached, the operating system may still accept connections based on the acceptCount setting. The default value varies by connector type. For BIO the default is the value of maxThreads unless an Executor is used in which case the default will be the value of maxThreads from the executor. For NIO the default is 10000. For APR/native, the default is 8192.For NIO only, setting the value to -1, will disable the maxConnections feature and connections will not be counted.服务器在任何给定时间接受和处理的最大连接数。当达到这个数字时,服务器将接受(但不处理)另一个连接。这个额外的连接将被阻塞,直到正在处理的连接数量低于maxConnections,此时服务器将再次开始接受和处理新的连接。注意,一旦达到限制,操作系统仍可能根据acceptCount设置接受连接。缺省值因连接器类型而异。对于BIO,默认值是maxThreads的值,除非使用Executor,在这种情况下,默认值将是Executor的maxThreads的值。对于NIO,默认值是10000。对于APR/native,缺省值是8192。仅对于NIO,将该值设置为-1将禁用maxConnections特性,连接将不会被计数。
    maxThreadsThe 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. If an executor is associated with this connector, this attribute is ignored as the connector will execute tasks using the executor rather than an internal thread pool. Note that if an executor is configured any value set for this attribute will be recorded correctly but it will be reported (e.g. via JMX) as -1 to make clear that it is not used.由该连接器创建的请求处理线程的最大数量,因此它决定了可以处理的并发请求的最大数量。如果未指定,此属性将被设置为200。如果执行器与此连接器关联,则此属性将被忽略,因为连接器将使用执行器而不是内部线程池执行任务。注意,如果配置了一个执行器,为这个属性设置的任何值都将被正确记录,但它将被报告(例如通过JMX)为-1,以明确表示它没有被使用。
    minSpareThreadsThe minimum number of threads always kept running. This includes both active and idle threads. If not specified, the default of 10 is used. If an executor is associated with this connector, this attribute is ignored as the connector will execute tasks using the executor rather than an internal thread pool. Note that if an executor is configured any value set for this attribute will be recorded correctly but it will be reported (e.g. via JMX) as -1 to make clear that it is not used.最小线程数始终保持运行。这包括活动线程和空闲线程。如果未指定,则使用默认值10。如果执行器与此连接器关联,则此属性将被忽略,因为连接器将使用执行器而不是内部线程池执行任务。注意,如果配置了一个执行器,为这个属性设置的任何值都将被正确记录,但它将被报告(例如通过JMX)为-1,以明确表示它没有被使用。

    注意

    • 单个tomcat能支持的最大工作线程数还和Linux CPU有关,现在一般服务器都是多核,可支持最大线程数800。
    • 另外,Linux单个进程的最大线程数是1024。这个限制可以在 /usr/include/bits/local_lim.h 中查看(ulimit -l)。

      -----------------------------------------------------------------------------------

      offer突击训练营简介:

      1:针对不知道怎么面试,面试没有信心的小伙伴,我们会给你一个offer保障。

      2:我们会监督你15-20天内把面试体系技术点掌握至少7成,这样足够你去找到满意的工作了。

      3:我们是面向面试学习指导,不会带你们去写代码,会把项目真实开发的迭代过程和技术细节如何实现业务功能都详细教清楚,你能在面试中流畅表达清楚就行了,项目经验你不用担心(技术老师提供的真实项目经验肯定拿的出手),自己学和别人带着系统学,效率完全不一样。

      详情请点击这里:offer突击训练营,给你一个offer的保障,求职跳槽的看过来!


免责声明
1、本网站属于个人的非赢利性网站,转载的文章遵循原作者的版权声明。
2、本网站转载文章仅为传播更多信息之目的,凡在本网站出现的信息,均仅供参考。本网站将尽力确保所
提供信息的准确性及可靠性,但不保证信息的正确性和完整性,且不对因信息的不正确或遗漏导致的任何
损失或损害承担责任。
3、任何透过本网站网页而链接及得到的资讯、产品及服务,本网站概不负责,亦不负任何法律责任。
4、本网站所刊发、转载的文章,其版权均归原作者所有,如其他媒体、网站或个人从本网下载使用,请在
转载有关文章时务必尊重该文章的著作权,保留本网注明的“稿件来源”,并白负版权等法律责任。

手机扫描二维码访问

文章版权声明:除非注明,否则均为主机测评原创文章,转载或复制请以超链接形式并注明出处。

发表评论

快捷回复: 表情:
评论列表 (暂无评论,2406人围观)

还没有评论,来说两句吧...

目录[+]