Search code examples
javaspring-bootmicroservices

How to handle the fragmented requests very efficiently in java springboot microservice?


I am working on the springboot microservice for one of the client...

The client requests body contains {Group : A, SomeProp: ABC}.

From Server side: In server, there are mapping for every Group. Ex: Group A is 1,2,3,4 and Group B is 3,4,5,6,7,8 and so on. Now server should split the request like

-> 1, ABC

-> 2, ABC

-> 3, ABC and so on.... Now, all the fragmented requests should be processed in parallel and send the responses via acqtivemq. The point is, 1 request will be fragmented into multiple request at the server side and needs to process them asynchronously. Currently, I am using thread pool to manage it. The pain is latency time is going very high during heavy load/ more number of requests and also process usage gradually increases.

How to approach this uses cases efficiently in springboot microservice?


Solution

  • For something like this I think its important to configure spring boot to your liking and not rely on the defaults.

    1. you should configure the server.tomcat.max-threads so that its to your liking. The default is 200 and the max is 10000 if i'm not mistaken
    2. You should keep the ExecutorPool like you mentioned with completableFutures and properly configure the size of the pool.
    3. Probably increase your JVM heap size.
    4. Horizontally scale your app accordingly. (this will help alot)

    Those are really the only 4 things you can control from a spring boot perspective.