弹簧引导 - 对创建的连接数的限制

2022-08-31 14:43:27

我使用Spring Boot开发了一个微服务。我通过对后端调用进行存根来对服务进行性能测试。当我查看线程计数时,我看到在任何时间点为服务创建的最大线程数为20,即使所做的调用数要高得多。对于可以使用 Spring Boot 开发的微服务的调用次数,是否有任何限制?请您指导我需要遵循哪些步骤来排除故障/增加服务接受的连接数?


答案 1

此设置派生自嵌入式容器(tomcat、jetty...)。

雄猫的线程数

您可以在应用程序.属性中指定此属性

server.tomcat.max-threads=400

你说你计算了20个线程,但是根据另一个堆栈溢出问题/答案,tomcat的默认线程数应该是200,因为server.tomcat.max线程的默认值是0。请参阅tomcat的文档

此连接器要创建的最大请求处理线程数,因此,它决定了可以处理的最大并发请求数。如果未指定,则此属性设置为 200。如果执行程序与此连接器关联,则忽略此属性,因为连接器将使用执行程序而不是内部线程池执行任务。

此外,该属性用于:

  • 拖曳server.undertow.worker-threads

  • 码头server.jetty.acceptors

您可以在Spring的文档中找到属性列表


答案 2

也许,你可以看看弹簧靴的配置

server.tomcat.accept-count=100 # Maximum queue length for incoming connection requests when all possible request processing threads are in use.
server.tomcat.additional-tld-skip-patterns= # Comma-separated list of additional patterns that match jars to ignore for TLD scanning.
server.tomcat.background-processor-delay=10s # Delay between the invocation of backgroundProcess methods. If a duration suffix is not specified, seconds will be used.
server.tomcat.basedir= # Tomcat base directory. If not specified, a temporary directory is used.
server.tomcat.max-connections=10000 # Maximum number of connections that the server accepts and processes at any given time.
server.tomcat.max-http-header-size=0 # Maximum size in bytes of the HTTP message header.
server.tomcat.max-http-post-size=2097152 # Maximum size in bytes of the HTTP post content.
server.tomcat.max-threads=200 # Maximum amount of worker threads.
server.tomcat.min-spare-threads=10 # Minimum amount of worker threads.
server.tomcat.port-header=X-Forwarded-Port # Name of the HTTP header used to override the original port value.
server.tomcat.protocol-header= # Header that holds the incoming protocol, usually named "X-Forwarded-Proto".
server.tomcat.protocol-header-https-value=https # Value of the protocol header indicating whether the incoming request uses SSL.
server.tomcat.redirect-context-root=true # Whether requests to the context root should be redirected by appending a / to the path.
server.tomcat.remote-ip-header= # Name of the HTTP header from which the remote IP is extracted. For instance, `X-FORWARDED-FOR`.
server.tomcat.resource.cache-ttl= # Time-to-live of the static resource cache.
server.tomcat.uri-encoding=UTF-8 # Character encoding to use to decode the URI.
server.tomcat.use-relative-redirects= # Whether HTTP 1.1 and later location headers generated by a call to sendRedirect will use relative or absolute redirects.


推荐