More actuator optimizations #259
Comments
The |
See related spring-projects/spring-boot#20290 issue. |
The first step is to review this diff of used classes between a basic Spring MVC app and the same with the actuator starter. There are 3 levels where we could do something:
|
First round of optimizations have gone in purely related to hint adjustment and smarter feature analysis, I wanted to share the results. I have a variant of the Initial build with the starter for actuator removed from the pom to give us the baseline. (Macbook Pro)
Now with the actuator added back to the pom.xml
Recompiling with
Very roughly speaking if the observation in the first comment is that actuator had a We should probably review what is in the latter image to see if anything is obvious that doesn't need to be there. |
@aclement Could we compare the additional classes loaded by the JVM with actuator + exercising the |
Now we can see the wood for the trees after the first round of optimizations, I was able to dig a little deeper. As I commented before reviewing the difference between a pure app with no actuator with actuator added and only wanting to exercise
But that So a crude hack to do eager evaluation of ConditionalOnCloudPlatform. The changes are from:
to:
A meg saved in RSS. I also noticed a lot of micrometer stuff in there. I excluded micrometer in the pom (from the actuator dependency) to see the impact it would have:
Notice the giant decrease in RSS in this case. I suspect something similar could be achieved via not excluding micrometer as a dependency but evaluating conditions like |
Eager evaluation of
|
Just checking: eager evaluation of |
After more discussions with @wilkinsona and @dsyer I think the solution is the following:
|
In Spring Boot 2.4 there is That's what we do to disable metrics export in Integration tests. |
I'm not sure that this makes sense. If you're exporting metrics out-of-process – to Prometheus or whatever – you will care about metrics but in all likelihood won't have the metrics endpoint enabled. |
Yeah we probably need to refine a little bit the logic. |
I've managed to get close to simulating micrometer not being around but not quite. Whilst I've managed to eliminate the Spring beans by tweaking the GraalVM feature analysis, there is a class Pushing on optimizations I've made it to:
Which would make the health endpoint basically add 11M RSS to a base application and 2Meg to the image size. I now need to refactor my optimizations into real commits so not sure I'll quite get to that target as I undo some liberties I took, but I'll post things I've done and we can see if any small Spring refactorings might be able to help. |
If that's 1M of RSS and Reactive stack specific I think we can live with that. |
Hey @wilkinsona - you might be able to help me with this (I'm no expert on actuators!). As I take apart my hacks, I'm looking at
(that was with - overkill I know - |
Thanks, Andy. I think there's some scope to make Boot more efficient there, albeit with a non-zero (but small) risk of breaking someone if they're doing something a bit unusual. I've opened spring-projects/spring-boot#23977. |
Just thinking about the comment from @snicoll above:
In a native-image world (maybe in a JVM world...) isn't it a shame that we build all that metrics infrastructure when all you might have wanted from actuator was the health endpoint? I guess as a percentage memory cost on the JVM it may not be so large but bringing in micrometer seems to be about 10% of the memory for our native-image case here. Some crude measurements in JVM mode, running the actuator sample and just hitting the Now something super crude, checking how many classes are loaded for the app (count
From my point of view all I wanted was |
Final comment on this in 0.8.2 timeframe. I've pushed the changes I want to make and got some decent figures. What I ended up doing was building on a facility we already had to filter our configurations during feature processing. I wrote a filter for the metrics ones that bring in micrometer. If you set the right property it will filter our metrics configurations during image build. Here are the figures: Figures for hitting '/' endpoint and the health endpoint:
(Remember 49.5M was the RSS without actuator, so <10M impact if taking it to the extreme with the options). None of these options are on by default. |
Yes, I don't plan to do more here at the moment. |
Despite our effort to modularize and optimize actuator hints in our 0.8.0 milestone, adding actuator on a Spring Boot + Spring MVC
@Controller
+ Tomcat + Jackson increase RSS memory by 34M of RSS (97M
with,63M
without). This is a lot especially when we think that most users just want their default web endpoints.I think there are multiple things to explore here in order to find the best way how to optimize this:
spring-init
functional configuration decrease the footprint? How much remaining hints required after?The text was updated successfully, but these errors were encountered: