Home > OS >  How to handle 1000 requests per second in spring boot rest API?
How to handle 1000 requests per second in spring boot rest API?

Time:06-06

I am newbie in Spring boot. We are implementing one spring boot microservice application.

As spring boot uses embedded tomcat server, by default thread pool is 200.

So whats the best approach to increase the capactiy to handle 1000 requests?

Do we need to make it async or?

Any inputs are appreciated.

Thanks in advance.

CodePudding user response:

There is no single parameter which would ensure that your application will handle 1000 requests in parallel.
It depends on many factors, like:

  1. What is the average execution time for your request. e.g. If your request only needs nanoseconds to return then X number of threads could suffice to serve Y parallel requests (even when X<Y).
  2. Available resources: Sometimes even if number of threads is greater than number of parallel requests (X>Y), it may not be able to process them simultaneously if the resources are limited (e.g. RAM, Processing power, max number of database connections) etc.

So, in real life, it all depends on lot of factors (not covered above) which are taken care by software architecture which in turn takes care of your functional as well as non functional requirements. So, even if your number of requests change from 1000 to 10000, your architecture will take care of it if it is Scalable.

Knowing which parameter to tune may suffice for now, for future though, look at quality attributes in software architecture https://en.wikipedia.org/wiki/List_of_system_quality_attributes

CodePudding user response:

There is hardware capacity (RAM, CPU etc) So you can not set any number of thread in pool (like 1000 in your case). Also it depend on execution time of each request.

To handle high traffic, you should setup Load Balancer with multiple node/instance.

Better to go with Auto Scaling on Cloud server. It will help to increase the instance as per high load (number or request) and again decrease the instances when there is low number of request. Which is cost effective.

  • Related