日常应用中,单台Tomcat能支持最大的并发数是多少?

作为一个有经验的Java Web开发人员对这个问题应该有大概的印象,并会让问题再具体点,比如Tomcat版本,运行模式,并发请求允许的最大响应时间等,然后针对其中某个点搜索答案,而不应该低效的去直接搜这个答案。并且如果你没相关知识,很容易被网上的知识误导,因为很多都是很早之前配置的答案的转载。

以现在主要用的Tomcat8为例,想要完全掌握配置,最好还是去官网去浏览锁定自己想知道的相关问题的关键词。https://tomcat.apache.org/tomcat-8.5-doc/config/http.html

从上面配置也可以看出Tomcat8在操作系统没有装arp库支持时默认工作在NIO模式,默认支持的最大并发连接数是10000。

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 NIO and NIO2 the default is 10000. For APR/native, the default is 8192.

Note that for APR/native on Windows, the configured value will be reduced to the highest multiple of 1024 that is less than or equal to maxConnections. This is done for performance reasons.
If set to a value of -1, the maxConnections feature is disabled and connections are not counted.

Sets the protocol to handle incoming traffic. The default value is HTTP/1.1 which uses an auto-switching mechanism to select either a Java NIO based connector or an APR/native based connector. If the PATH (Windows) or LD_LIBRARY_PATH (on most unix systems) environment variables contain the Tomcat native library, and the AprLifecycleListener that is used to initialize APR has its useAprConnector attribute set to true, the APR/native connector will be used. If the native library cannot be found or the attribute is not configured, the Java NIO based connector will be used. Note that the APR/native connector has different settings for HTTPS than the Java connectors.
To use an explicit protocol rather than rely on the auto-switching mechanism described above, the following values may be used:
org.apache.coyote.http11.Http11NioProtocol - non blocking Java NIO connector
org.apache.coyote.http11.Http11Nio2Protocol - non blocking Java NIO2 connector
org.apache.coyote.http11.Http11AprProtocol - the APR/native connector.
Custom implementations may also be used.
Take a look at our Connector Comparison chart. The configuration for both Java connectors is identical, for http and https.
For more information on the APR connector and APR specific SSL settings please visit the APR documentation

注意这个值是Tomcat默认接受的并发连接数,是TCP连接层相关的参数。Tomcat在NIO模式时有一个线程专业接受请求连接,然后将其放到任务队列,然后有工作线程从任务t队列取出请求并并发处理(工作线程数通过maxThreads值控制,Tomcat默认是200),如果每个请求处理很快比如20ms,则工作线程1s内就能处理10000个请求,否则若请求处理很慢比如要几秒,则请求队列中的连接得到处理收到响应的时间也会变慢。

  • maxThreads、minSpareThreads是tomcat工作线程池的配置参数,maxThreads就相当于jdk线程池的maxPoolSize,而minSpareThreads就相当于jdk线程池的corePoolSize。

  • acceptCount、maxConnections是tcp层相关的参数。

tomcat有一个acceptor线程来accept socket连接,然后有工作线程来进行业务处理。对于client端的一个请求进来,流程是这样的:tcp的三次握手建立连接,建立连接的过程中,OS维护了半连接队列(syn队列)以及完全连接队列(accept队列),在第三次握手之后,server收到了client的ack,则进入establish的状态,然后该连接由syn队列移动到accept队列。tomcat的acceptor线程则负责从accept队列中取出该connection,接受该connection,然后交给工作线程去处理(读取请求参数、处理逻辑、返回响应等等;如果该连接不是keep alived的话,则关闭该连接,然后该工作线程释放回线程池,如果是keep alived的话,则等待下一个数据包的到来直到keepAliveTimeout,然后关闭该连接释放回线程池),然后自己接着去accept队列取connection(当当前socket连接超过maxConnections的时候,acceptor线程自己会阻塞等待,等连接降下去之后,才去处理accept队列的下一个连接)。acceptCount指的就是这个accept队列的大小。

https://segmentfault.com/a/1190000008064162

Tomcat的最大并发数的更多相关文章

  1. tomcat并发数

    Tomcat的最大并发数是可以配置的,实际运用中,最大并发数与硬件性能和CPU数量都有很大关系的.更好的硬件,更多的处理器都会使Tomcat支持更多的并发. Tomcat默认的HTTP实现是采用阻塞式 ...

  2. tomcat支持多少并发

    作者:孟男男 来源:https://zhidao.baidu.com/question/1445941399668603020.html Tomcat的最大并发数是可以配置的,实际运用中,最大并发数与 ...

  3. Tomcat最多支持并发多少用户?

    当一个进程有 500 个线程在跑的话,那性能已经是很低很低了.Tomcat 默认配置的最大请求数是 150,也就是说同时支持 150 个并发,当然了,也可以将其改大.当某个应用拥有 250 个以上并发 ...

  4. Tomcat并发数优化,修改service.xml性能调优 增加最大并发连接数

    可以在控制台的启动信息里看见,默认状态下没有被打开nio配置,启动时的信息,如下: 2010-2-1 12:59:40 org.apache.coyote.http11.Http11Protocol ...

  5. tomcat 最大并发数

    只针对BIO模式,目标请求会sleep两秒再返回结果,通过jmeter测试工具进行并发测试 操作系统:windows && linux tomcat7测试: <Connector ...

  6. Linux查看连接数,并发数

    Linux查看连接数,并发数 博客分类: 小记 linux  软连接 ln -s /home/ictfmcg/data/photo /var/jtnd/data/photo tomcat 6的Conn ...

  7. 详解tomcat连接数和线程数

    前言 在使用tomcat时,经常会遇到连接数.线程数之类的配置问题,要真正理解这些概念,必须先了解Tomcat的连接器(Connector). 在前面的文章 详解Tomcat配置文件server.xm ...

  8. PV 与 并发数 之间的故事

    PV: Page View UV: Unique Visitor 在一些已经上线的项目中,运营会统计每日的PV,UV,IP 等数据 而根据PV量,可以推算出一个相对较科学的并发数,来作为负载测试的一个 ...

  9. mmysql-最大链接数和最大并发数的区别

    关于连接数和并发数的设置(针对Innodb引擎) 对于机器本身来说,进程数是说机器正在运行的进程数量,调出任务管理器就可以看到.连接数是指进程接收和发送数据的连接ip的数量.并发数是指进程同时发送数据 ...

随机推荐

  1. GreenOpenPaint的实现(六)图片的保存和打开

    如果只是直接的图片保存和打开,是没有很多内容的.但是我这里,将EXIF的信息融入其中,使得图像处理的结果能够保存下来.这样就非常有价值意义了. 所有的操作都放在DOC中进行处理. 我之前已经对EXIF ...

  2. MFC读写EXIF信息,图片非占用

    MFC读写EXIF信息 读取有类库可以直接调用,网络上有直接可以用的:但是写Exif的资料非常少,我花了一点时间研究收集,终于成功. 将相关的资料共享.主要是借助gdi+,需要注意的地方很多   // ...

  3. 20145104张家明 《Java程序设计》第6周学习总结

    20145104张家明 <Java程序设计>第6周学习总结 教材学习内容总结 第10章与11章总结 标准输入输出 System.in: 标准输入,默认关联到键盘(终端输入) System. ...

  4. 20145204 《Java程序设计》第9周学习总结

    20145204 <Java程序设计>第9周学习总结 教材学习内容总结 JDBC Java语言访问数据库的一种规范,是一套API.JDBC (Java Database Connectiv ...

  5. hdu_2048 错排问题

    错排问题本质上就是一个动态规划问题,其状态转移方程为: 记d[n]为n个人错排情况的总数. 那么策略可以描述为:分析第n个人错排的可能情况: 1)前n-1个人满足错排的情况,那么第n个人加入后还要错排 ...

  6. python 进制转换

    print hex(),hex(-) #转换成十六进制 print oct(),oct(-) #转换成八进制 print bin(),bin(-) #转换成二进制 print int("字面 ...

  7. Linux 常用环境搭建

    已有环境 python 2.6.6 jdk 1.7 —tomcat— —jenkins— —jq— —Python 2.7— —pip— —PIL— —Android SDK— —yum or apt ...

  8. 一个故意消耗内存的java程序MemoryEater

    公司提供的测试服务器是vmware的,号称给我6G, 物理内存事实上是按需分配的. 等到真正拿到6G物理内存,黄花菜都凉了. 看到下面的文章,觉得故意用java程序侵占6G内存, 然后把侵占到内存的释 ...

  9. Android之微信支付

    Android开发中,大多数电商APP都会有支付这么模块,此博客就讲一下微信支付,代码不多,很简单就可以完成,支付宝支付请看博客 Android支付之支付宝封装类 先来看看效果图 微信支付首先要去微信 ...

  10. hdu1846巴什博弈

    巴什博弈:只有一堆n个物品,两个人轮流从这堆物品中取物, 规定每次至少取一个,最多取m个.最后取光者得胜. 结论:只要不能整除,那么必然是先手取胜,否则后手取胜. #include<map> ...