We have 40+ spring boot apps and when we try to start all of them together parallel, it takes about 9 to 10 minutes. And we notice that CPU usage is always 100% throughout this entire duration. After all apps come up successfully and registered with Eureka, CPU usage is back to normal (on average ~30-40% CPU usage after startup).
It seems each spring boot app is taking at least about 15-20 seconds to startup, which we are not happy with since application is relatively small to start with.
We also disabled spring boot auto-configuration so to make sure only required "matching" classes are loaded at start up by spring boot. And we only gained about 1 or 2 seconds at startup after this change.
We seem to have enough system resources with 8 core CPUs and 32 gb of memory on this VM.
Spring boot version is 1.3.6.RELEASE.
Is it something to do with Spring boot? Because even when we startup single spring boot app it spikes CPU to 70-80% usage. Your help is very much appreciated!
If the CPU usage is around 100%, this means that your computer is trying to do more work than it has the capacity for. This is usually OK, but it means that programs may slow down a little. Computers tend to use close to 100% of the CPU when they are doing computationally-intensive things like running games.
spring.main.lazy-initialization=true Setting this property truely will initialize the bean only after it comes into the picture. This property will reduce the run time of the application.
A spike in CPU use as your computer starts up is not uncommon, but unusually high loads can be caused by too many programs trying to start up at once or an error in your system.
This is more of how many beans and Auto Configurations that get executed while the application being started.
For even a simple web application along with JPA, there is a webcontainer
and its thread pools
, DataSources
initializations and many more supporting beans and auto configurations that need to get initialized. These are some serious resource taking actions and they all are rushed at the start of the application to get application booted as soon as possible.
Given that you are starting 40+ apps like these simultaneously, the server will have to pay its toll.
There are ways you can improve the application boot time.
spring-boot-starter-web
when the application doesn't even need a web environment. Same goes for other starter
modules.Conditional
Bean definitions with the use of @ConditionalOnMissingBean
@ConditionalOnProperty
@ConditionalOnClass
@ConditionalOnBean
@ConditionalOnMissingClass
@ConditionalOnExpression
. This might backfire if you make spring to check for beans with lots of conditions.spring profiles
. If you don't want a specific set of beans not to be part of that running instance you can group them into a profile and enable them or disable theminitial number of threads
a web container can have. Same goes for Datasources
. Initiate your pool with only required number of active threads. @Lazy
. This annotation can be per bean or against an entire @Configuration
. If that doesn't satisfy your needs, you can always throttle the CPU usage per process with commands like nice
or cputools
.
Here is an article around cputools.
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