单台Tomcat Server所支持的最大并发数
tomcat内存的设置:1.4GBJVM+256MB的池
set JAVA_HOME=C:\JAVA\JDK15
set CATALINA_OPTS=-server -Xms 1400m -Xmx1400m -XX:PermSize=256m -XX:MaxPermSize=256m
参数解析:
-Xms:初始化堆内存
-Xmx:堆内存最大值
-Xss:指设定每个线程的堆栈大小,一般是128k或者256k(这个值注意默值512K,有时会出现这个过小,tomcat起不来情况。所有根据的项目设置,反正越小越好)
-XX:PermSize:初始化永久保存去内存大小
-XX:MaxPermSize:永久保存去内存最大值
tomcat线程初始设置:初始支持1000线程,最大支持2000线程
<Connector port="80" maxHttpHeaderSize="8192"
maxThreads="250" minSpareThreads="100" maxConnections="1000"
enableLookups="false" redirectPort="8443" acceptCount="200"
connectionTimeout="20000" disableUploadTimeout="true" />
参数解析:
maxThreads:tomcat起动的最大线程数,每一个线程可以处理一个请求,即同时处理的任务个数,默认值为200
minSpareThreads:tomcat最小备用线程数,也就是最小空闲线程数
maxConnections:tomcat可以接受并且处理的线程数。也就是说当线程数小于maxConnections的时候,tomcat会接收并且处理这些请求,一旦到达maxConnections数之后,tomcat就只接收这些请求,但是并不会处理这些请求,超过maxConnections之后的请求会一直阻塞,直到tomcat里面的线程数低于maxConnections,然后tomcat会继续处理这些新求情。另外注意的是,当线程数到达maxConnections数之后,tomcat还会接受不了acceptCount数的请求,如果线程数在超过acceptCount那么tomcat就不在接收这些请求。
官方解释: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.
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.
connectionTimeout:连接超时时间
总结:
简单的说,maxThreads就是单个tomcat的并发数,只要在maxThreads的范围内来多少请求,tomcat处理多少请求;minSpareThreads是tomcat维护的最小空闲线程数,我的理解是当tomcat没有请求访问的时候,tomcat会维护minSpareThreads的线程数,也就是线程池最小空闲线程;maxConnections就是说当请求数大于maxThreads的时候,tomcat还是会接受并且处理maxConnections数字范围内的请求,如果当达到了maxConnections的时候tomcat就只接受新请求但是并不会处理它,直到tomcat可处理的线程数低于maxConnections然后tomcat会接受并且处理新请求;acceptCount意思是当maxConnections到达之后,tomcat这时候还是会只接受但是不处理新请求,acceptCount就是只接收不处理的请求上线。