Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Spring Boot - Limit on number of connections created

I developed a microservice using Spring Boot. I was performance testing the service by stubbing the backend calls. When I looked at the thread count , I see that the maximum number of threads that created to the service is 20 at any point in time even though the number of calls made is much higher. Are there any limitations with respect to number of calls that can be made to a microservice developed using Spring Boot. Please can you guide in what steps I need to follow to troubleshoot / increase the number of connections accepted by the service?

like image 900
Punter Vicky Avatar asked Aug 17 '16 16:08

Punter Vicky


People also ask

How do I limit the number of threads in spring boot?

Maximum number of threads in Spring Boot Application If you are using Tomcat as your embedded server (default), then you can use the property server. tomcat. max-threads to control how many threads you want to allow. This is set to 0 by default which means- use the Tomcat default which is 200 .

How many concurrent requests can spring boot handle?

Yes, Spring boot can handle simultaneously requests! If your servlet container is tomcat under the hood, it can handle 200 simultaneous requests. However, you can override this value by adding server.

What are the limitations of spring boot?

Disadvantages of Spring BootLarge deployment files that result from unused dependencies. The long amount of time that it takes to replace legacy systems with Spring Boot applications. Its inability to build large, monolithic applications (although it works extremely well for developing microservices)

How does spring boot handle 1000 requests per second?

To handle high traffic, you should setup Load Balancer with multiple node/instances. Better to go with Auto Scaling on Cloud server. It will increase the instances as per high load (number or request) and again decrease the instances when there will be low number of requests. Which is cost effective.


1 Answers

This setting is derived from the embedded container (tomcat, jetty...).

Tomcat's number of threads

You may specify this property in your application.properties

server.tomcat.max-threads=400 

You say you counted 20 threads, however according to this other stackoverflow question/answer, the default number of thread should be 200 with tomcat, since server.tomcat.max-threads's default value is 0. See tomcat's documentation:

The maximum number of request processing threads to be created by this Connector, which therefore determines the maximum number of simultaneous requests that can be handled. If not specified, this attribute is set to 200. If an executor is associated with this connector, this attribute is ignored as the connector will execute tasks using the executor rather than an internal thread pool.

Also, the property for:

  • undertow: server.undertow.worker-threads

  • jetty: server.jetty.acceptors

You'll find the list of properties in Spring's documentation

like image 176
alexbt Avatar answered Sep 23 '22 06:09

alexbt