Search code examples
javaspring-boottomcatresourcesetl

Optimise a Spring Boot backend for high CPU/memory workloads


I am running a Spring Boot application that acts as a backend for a frontend Javascript application. The frontend is served to the client as a static resource and the backend serves API requests coming from it. The application is initially designed to run on-premise but should be built in a way that allows easy porting to a cloud-native solution.

I expect the backend to do some heavy lifting ETL work which will be heavy on the memory and CPU side. At the same time, it won't need to scale to serve many concurrent requests - it only really needs to serve requests that kick-off and manage the jobs, which will be invoked by a single user who's interfacing with it.

What are some parameters that I could tweak to fine-tune for this type of deployment?

Current thinking:

  • Reduce server.tomcat.max-threads to a single digit to minimize the footprint of the request thread pool as I am not expected to handle more than one-two concurrently
  • Do the same for the database connection pool
  • Fine-tune Xms and Xmx when launching the JAR

I would appreciate any other insights about how to make sure that the Java application takes up as big a footprint on the system as it can as well as Spring Boot specific parameters that I could tweak. Thank you.


Solution

  • If you have long running background tasks, I would offload to work to a threadpool and set the maximum number of threads to the number of CPU's in your system. Also set a maximum capacity on the queue of the executor so you don't overload it with too much pending work.

    Offloading to a different thread will make sure that the threads of the container remain available and you don't end up with a completely unresponsive system.

    Your suggestions for the maximum heap size and connection pool are valid.