Spring Boot - 限制创建的连接数

新手上路,请多包涵

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

原文由 Punter Vicky 发布,翻译遵循 CC BY-SA 4.0 许可协议

阅读 1.1k
2 个回答

此设置源自嵌入式容器(tomcat、jetty…)。

Tomcat的线程数

您可以在 application.properties 中指定此属性

server.tomcat.max-threads=400

您说您计算了 20 个线程,但是根据这个 其他 stackoverflow 问题/答案,tomcat 的默认线程数应该是 200,因为 server.tomcat.max-threads 的默认值为 0。请参阅 tomcat 的文档

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

此外,该物业:

  • 暗流server.undertow.worker-threads

  • 码头server.jetty.acceptors

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

原文由 alexbt 发布,翻译遵循 CC BY-SA 3.0 许可协议

也许,你可以看看 springboot的配置

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.

原文由 Bruce 发布,翻译遵循 CC BY-SA 4.0 许可协议

撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题