Tomcat并发数优化

    xiaoxiao2021-03-25  129

    我们可以去Tomcat 的官网看一下相关的资料TOMCAT官网地址 在Connector的属性配置中,相关描述是这样的

    If more simultaneous requests are received than can be handled by the currently available request processing threads, additional threads will be created up to the configured maximum (the value of the maxThreads attribute). If still more simultaneous requests are received, they are stacked up inside the server socket created by the Connector, up to the configured maximum (the value of the acceptCount attribute). 如果接收到的更多并发请求超过当前可用的请求处理线程可以处理的数量,则将创建高达配置的最大值(maxThreads属性的值)的其他线程。如果仍收到更多的同时请求,它们将在由连接器创建的服务器套接字内堆叠,直到配置的最大值(acceptCount属性的值)。

    所以,配置Tomcat并发数只需要对maxThreads 和 acceptCount 两个参数做设置就可以了,文档中表示这两个默认值分别为200和100,可以增加这两个属性的值,并且使acceptCount大于等于maxThreads:

    <Connector className="org.apache.coyote.tomcat4.CoyoteConnector" port="8090" maxThreads="400" minSpareThreads="25" maxHttpHeaderSize="8192" enableLookups="false" redirectPort="8443" acceptCount="500" debug="0" connectionTimeout="20000" useURIValidationHack="false" URIEncoding="UTF-8"/>

    需要注意的是,具体能承载多少并发,需要看硬件的配置,CPU 越多性能越高,分配给 JVM 的内存越多性能也就越高,但也会加重 GC 的负担。在Linux系统中,每个进程中的线程数不允许超过 1000

    转载请注明原文地址: https://ju.6miu.com/read-4115.html

    最新回复(0)