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?
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 .
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.
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)
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.
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With