tomcat 的acceptCount、acceptorThreadCount、maxConnections、maxThreads 如何确定
acceptCount
连接在被ServerSocketChannel accept之前就暂存在这个队列中,acceptCount就是这个队列的最大长度。
ServerSocketChannel accept就是从这个队列中不断取出已经建立连接的的请求。
acceptorThreadCount
使用的Acceptor线程的个数,tomcat设置为1
Acceptor线程只负责从上述队列中取出已经建立连接的请求。
maxConnections
这里就是tomcat对于连接数的一个控制,即最大连接数限制。一旦发现当前连接数已经超过了一定的数量(NIO默认是10000),上述的Acceptor线程就被阻塞了,
即不再执行ServerSocketChannel的accept方法从队列中获取已经建立的连接。但是它并不阻止新的连接的建立,新的连接的建立过程不是Acceptor控制的
maxThread
业务线程数,默认是200
1. maxConnections
The 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
.
2. maxThreads
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. 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.
3. acceptCount
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 will be refused. The default value is 100.
tomcat默认设置
maxConnections表示有多少个socket连接到tomcat上。NIO模式下默认是10000。
maxThreads:tomcat起动的最大线程数,即同时处理的任务个数,默认值为200
acceptCount:当tomcat起动的线程数达到最大时,接受排队的请求个数,默认值为100
tomcat能支持最大连接数由maxConnections加上acceptCount来决定。同时maxThreads如何设定?
1. cpu bound: maxThreads应该尽量设的小,降低同一时间内争抢cpu的线程个数,可以提高计算效率,提高系统的整体处理能力。
2. io bound: maxThreads应该尽量设的大,这样 才能提高同时处理请求的个数,从而提高系统整体的处理能力。
此情况下因为tomcat同时处理的请求量会比较大,所以需要关注一下tomcat的虚拟机内存设置和linux的open file限制。
现实应用中,我们的操作都会包含以上两种类型(计算、等待),所以maxThreads的配置并没有一个最优值,一定要根据具体情况来配置。
最好的做法是:在不断测试的基础上,不断调整、优化,才能得到最合理的配置。
4. spring 设置
server.tomcat.max-threads=1024
server.tomcat.max-connections=2048 server.tomcat.accept-count=100 或
@Configuration
public class WebServerConfiguration {
@Bean
public EmbeddedServletContainerFactory createEmbeddedServletContainerFactory() {
TomcatEmbeddedServletContainerFactory tomcatFactory = new TomcatEmbeddedServletContainerFactory();
tomcatFactory.setPort(8081);
tomcatFactory.addConnectorCustomizers(new MyTomcatConnectorCustomizer());
return tomcatFactory;
}
}
class MyTomcatConnectorCustomizer implements TomcatConnectorCustomizer {
public void customize(Connector connector) {
Http11NioProtocol protocol = (Http11NioProtocol) connector.getProtocolHandler();
//设置最大连接数
protocol.setMaxConnections(2000);
//设置最大线程数
protocol.setMaxThreads(2000);
protocol.setConnectionTimeout(30000);
}
}
参考:
segmentfault: tomcat的acceptCount与maxConnections
spring: howto-embedded-servlet-containers
noodles: 对 Linux TCP 的若干疑点和误会
helloDog: sysctl.conf学习和调优
Linux Tcp 参数调优
高性能网络编程7--tcp连接的内存使用
写点什么:tomcat-connector的微调(1): acceptCount参数
tomcat 的acceptCount、acceptorThreadCount、maxConnections、maxThreads 如何确定的更多相关文章
- Tomcat中acceptCount,maxConnections、maxThreads的含义及关系
个人对tomcat连接器3个属性maxConnections.maxThreads.acceptCount的理解: 先摘取官网对这3个属性的描述: acceptCount The maximum qu ...
- 秒懂:tomcat的maxConnections、maxThreads、acceptCount 图解
后面附图 | 秒懂 疯狂创客圈 Java 高并发[ 亿级流量聊天室实战]实战系列 [博客园总入口 ] 前言 疯狂创客圈(笔者尼恩创建的高并发研习社群)Springcloud 高并发系列文章,将为大家介 ...
- SpringBoot优化内嵌的Tomcat ---设置MaxConnections
使用kill -9杀掉springboot应用后,立马java -jar重启,会报错,需要等待一段时间才能启动成功,报错的原因是:/tmp/tomcat-docbase.474979491043437 ...
- tomcat 的优化配置
一.关于并发连接量的配置 在tomcat的server.xml配置文件中:将<Connector port="8080" protocol="HTTP/1.1&qu ...
- TCP 连接的 TIME_WAIT 过多 导致 Tomcat 假死
最近系统二次开发之后,发现使用的 Tomcat 7 会经常假死.前端点击页面无任何反应,打开firebug,很多链接一直在等待服务器的反应.查看服务器的状态,CPU占用很少,最多不超过10%,一般只有 ...
- Nginx与Tomcat、Client之间请求的长连接配置不一致问题解决[转]
http://bert82503.iteye.com/blog/2152613 前些天,线上出现“服务端长连接与客户端短连接引起Nginx的Writing.Active连接数过高问题”,这个是由于“服 ...
- tomcat根据繁忙线程数对keepalive进行动态调整
众所周知,Keep-Alive功能使客户端到服务器端的连接持续有效,当出现对服务器的后继请求时,Keep-Alive功能避免了建立或者重新建立连接.我们经常所用的tomcat服务器就支持HTTP Ke ...
- 详解tomcat的连接数与线程池
前言 在使用tomcat时,经常会遇到连接数.线程数之类的配置问题,要真正理解这些概念,必须先了解Tomcat的连接器(Connector). 在前面的文章 详解Tomcat配置文件server.xm ...
- 详解Tomcat的连接数和线程池
转: https://www.cnblogs.com/kismetv/p/7806063.html#t11 前言 在使用tomcat时,经常会遇到连接数.线程数之类的配置问题,要真正理解这些概念,必须 ...
随机推荐
- (笔记)Linux内核学习(三)之进程调度
进程调度: 在可运行态进程之间分配有限处理器时间资源的内核子系统. 一 调度策略 1 进程类型 I/O消耗型进程:大部分时间用来提交I/O请求或是等待I/O请求,经常处于可运行状态,但运行时间短,等待 ...
- mysql数据库建立的数据库在哪个文件夹?
一般在安装目录下的data文件夹下,或者在C:\Documents and Settings\All Users\Application Data\MySQL\MySQL Server 5.1\dat ...
- 移除input在type="number"时的上下箭头
网页在有些情况下,会需要input的输入的为单纯数字的文本框,此时type=number,但使用type=number时,输入框后面会有一个上下箭头,那么如何去掉上下箭头呢? <input ty ...
- linux环境下,对于一个大文件,如何查看其中某行的内容
需求说明: 今天在做mysql数据导入的过程中,导入到最后有一个报错,报某张表不存在.然后就想看看这行到底是在做什么操作的时候报的错误. 报错信息: [mysql@host---- ~]$ cat n ...
- 使用gdbserver远程调试
使用gdbserver远程调试 1.默认crosstool交叉编译器没有自带gdbserver,需要自行编译 到GNU官方FTP下载,目前最新版的是gdb-6.7.1下载地址:http://ftp ...
- Html 助手
/*! * Html 助手 * version: 1.0.0-2018.07.25 * Requires ES6 * Copyright (c) 2018 Tiac * http://www.cnbl ...
- 解决windows和ubuntu之间粘贴复制失效
vmware12中ubuntu15.10 16.10的vmware tools失效,导致不能复制粘贴文件以及自动适应窗口分辨率新安装或异常关机和重新划分分区导致的vmware tools失效,不能复制 ...
- 前端和后端的数据交互(jquery ajax+python flask+mysql)
上web课的时候老师布置的一个实验,要求省市连动,基本要求如下: 1.用select选中一个省份. 2.省份数据传送到服务器,服务器从数据库中搜索对应城市信息. 3.将城市信息返回客户,客户用sele ...
- springboot之thymeleaf学习
这是springboot的view层不建议使用jsp,而是thymeleaf,虽然我也不知道为什么,但是后来可能会明白一些.学springBoot也遇到很多bug,导致脱累了进度.有点类似于jsp,但 ...
- 移动端H5混合开发,Touch触控,拖拽,长按, 滑屏 实现方案
概述 近期由于产品快速原型开发的需要,不想用原声的方式开发App两端一起搞时间来不及,目前产品处于大量上feature的阶段,采用混合开发是最合适的选择,所以花了3天的时间研究怎么去实现移动端,拖拽, ...