You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Composite HealthIndicator that runs them in parallel #2652
Right now, invoking the health endpoint lead to a synchronous invocation of all underlying HealthIndicator instance(s) that have been configured. It would be nice to offer an option to run these in parallel instead.
Reacted by Axel Fontaine, Mike Kelly, Paweł, grinnery, Abhijith V Mohan, Eduardo Solanas, Ernesto J. Perez Garcia, Toasbi, Erik Greif, Rik Ende and 18 more
I would also like to have support for this. My project got a bunch of health checks and some of them can run up to few seconds. So in total performance of /health endpoint is terrible with sequential approach.
changed the title [-]composite HealthIndicator that runs them in parallel[/-][+]Composite HealthIndicator that runs them in parallel[/+]on Mar 22, 2018
Some services have requirements to respond within a given time limit. This time limit may be set by an external organization, not always under the control of the devs. This kind of timeout gets interpreted as a DOWN state, wakes devs up in the middle of the night, reboots service instances, and all the while provides no context as to which component was experiencing high latency (because there was no HTTP response).
I have successfully added timeouts per-actuator, but with 20 checks that require timeouts of around 5 seconds (any less would cause alerts for minor network blips), we are asking our caller to wait up to 1:40 for a response. At my org, this is absurd, and nobody wants to permit this behavior.
Reacted by Rik Ende, Kevin, Danny Paul, Christian Rehn, Pierre-Luc Maheu, rmie, Jimmy Praet, Rainer Scholz and Cosimo Damiano Prete
I considered having it only property-driven (management.health.async.indicator.$INDICATOR-BEAN-NAME.refresh-rate) or using a different interface (AsyncHealthIndicator) but believed an annotation would be more adequate.
I would be very happy to have your feedback on the approach taken. If you think this can be integrated directly into spring-boot-actuator, I'd gladly work on a PR.
Reacted by Andreas Höhmann, Sean Dukehart, Dumitru Boldureanu and Rainer Scholz
Thanks very much for the pull-request offer @antoinemeyer. It's really great to see that you've been able to add support in an additional library. We're currently not sure if we want to offer async support in the way that you've implemented it, or as suggested in #25459. Unfortunately, we're currently investing most of our time in Spring Boot 3.0 work so it's unlikely that we'll be able to make the decision anytime soon. I think it's best we wait until Spring Boot 3.0 is out before looking at this. That probably means that a pull-request would be a bit premature, and it would be best to consider things again when we're planning Spring Boot 3.1.
Thanks @philwebb for the feedback (once again).
I am looking forward to see what solution you will end up adopting for this problem. In the meantime I'll rely on (and improve) that library and hope it can benefit others!
+1 for the feature. My application has three health check components.
Component 1: <100ms response time
Component 2: <400ms response time
Component 3: <400ms response time
Would love to see the /actuator/health endpoint to respond within 400ms (worst case).
I am rendering the health details on react application (Home Page) which takes 100ms+400ms+400ms = 900ms right now. 900ms page load time is acceptable right now. It would be nice if the Home Page can load within 400ms.
We could implement the parallel processing logic as a temporary solution. But, I am sure this feature will come out of the box some day under spring-boot-starter-actuator.
I am not sure you're looking in the right direction. Running them in parallel should improve things a bit, but certainly not to the extend of what you're experiencing now. In other words, please review your indicator and backend configuration.
@snicoll thanks for the info. I was just thinking that parallel running (slow) health-check can improve the situation a little bit but at the end you are right. Regarding the configuration of my db-indicators is there maybe somewhere some documentation? Until yet my understanding was that springboot just wrap each running Datasource into a health-indicator. Would be maybe better to use just another datasource to the same db just to keep all configurated pooled connections ready for business or should I just increase the max number of pooled connections to be ready. Also what happens if multiple callers ask the health endpoint ... there is always an on-the-fly health-check as fas as I know and this means if aws elb + other dashboards checking health ... my connections to the db just waisted :) May my whole topic is var to much for a issue ... is there a good place for such a discussion.
That, and we don't use the issue tracker for discussions. You may want to chat with the community on Gitter. You may also be interested in endpoint caching.
importjava.time.Duration;
importorg.springframework.boot.actuate.health.HealthIndicator;
/** * This is an extension to {@link HealthIndicator}, except with the intention of providing similar * functionality to <a * href="https://github.com/antoinemeyer/spring-boot-async-health-indicator">antoinemeyer/spring-boot-async-health-indicator</a>. * This comes as a result of the following Spring Boot issues still being open: * * <ul> * <li>https://github.com/spring-projects/spring-boot/issues/2652 * <li>https://github.com/spring-projects/spring-boot/issues/25459 * </ul> * * <p>This aims to offer a means of getting asynchronously provided and potentially cached {@link * org.springframework.boot.actuate.health.Health Health} so as to allow the health actuator * endpoint to return almost immediately. * * @see: https://github.com/antoinemeyer/spring-boot-async-health-indicator */publicinterfaceAsyncHealthIndicatorextendsHealthIndicator {
publicdefaultDurationgetHealthCheckFrequency() {
returnDuration.ofSeconds(10);
}
}
AsyncHealthIndicatorAutoConfiguration
importjava.time.Duration;
importjava.time.ZonedDateTime;
importjavax.annotation.Nullable;
importlombok.Builder;
importlombok.Getter;
importlombok.Setter;
importorg.apache.commons.logging.Log;
importorg.apache.commons.logging.LogFactory;
importorg.springframework.beans.factory.InitializingBean;
importorg.springframework.beans.factory.annotation.Autowired;
importorg.springframework.boot.actuate.autoconfigure.health.HealthEndpointAutoConfiguration;
importorg.springframework.boot.actuate.health.Health;
importorg.springframework.boot.actuate.health.HealthContributorRegistry;
importorg.springframework.boot.actuate.health.HealthIndicator;
importorg.springframework.boot.actuate.health.NamedContributor;
importorg.springframework.boot.autoconfigure.AutoConfigureAfter;
importorg.springframework.context.annotation.Configuration;
importorg.springframework.scheduling.TaskScheduler;
/** * Configuration to allow replacing {@link HealthIndicator} instances in the {@link * HealthContributorRegistry} with {@link WrappedHealthIndicator} instances. The {@link * WrappedHealthIndicator} will be scheduled to refresh their internal state, and during {@link * HealthIndicator#health()} calls, will return their currently cached internal state immediately. * * <p>This relies on the existence of a {@link TaskScheduler}, which can be enabled by an {@link * org.springframework.scheduling.annotation.EnableScheduling @EnableScheduling} annotation * somewhere within your application. * * <p>Lombok can easily be replaced if it's not desired. * * <p>This is aims to provide similarfunctionality to <a * href="https://github.com/antoinemeyer/spring-boot-async-health-indicator">antoinemeyer/spring-boot-async-health-indicator</a>. * * @see: https://github.com/antoinemeyer/spring-boot-async-health-indicator */@Configuration@AutoConfigureAfter(HealthEndpointAutoConfiguration.class)
classAsyncHealthIndicatorAutoConfigurationimplementsInitializingBean {
privatestaticfinalLoglog = LogFactory.getLog(AsyncHealthIndicatorAutoConfiguration.class);
@AutowiredprivateHealthContributorRegistryhealthContributorRegistry;
@AutowiredprivateTaskSchedulertaskScheduler;
@OverridepublicvoidafterPropertiesSet() throwsException {
for (NamedContributor<?> namedContributor : healthContributorRegistry) {
finalStringname = namedContributor.getName();
finalObjectcontributor = namedContributor.getContributor();
if (contributorinstanceofAsyncHealthIndicatorasyncHealthIndicator) {
healthContributorRegistry.unregisterContributor(name);
log.debug(
"Wrapping " + contributor.getClass().getSimpleName() + " for async health scheduling");
WrappedHealthIndicatorwrappedHealthIndicator =
WrappedHealthIndicator.builder().wrappedHealthIndicator(asyncHealthIndicator).build();
healthContributorRegistry.registerContributor(name, wrappedHealthIndicator);
taskScheduler.scheduleWithFixedDelay(
wrappedHealthIndicator, asyncHealthIndicator.getHealthCheckFrequency());
}
}
}
@Getter@Setter@BuilderprivatestaticclassWrappedHealthIndicatorimplementsHealthIndicator, Runnable {
privatestaticfinalStringLAST_CHECKED_KEY = "lastChecked";
privatestaticfinalStringLAST_DURATION_KEY = "lastDuration";
privateHealthIndicatorwrappedHealthIndicator;
@NullableprivateHealthlastHealth;
@OverridepublicHealthhealth() {
HealthlastHealth = getLastHealth();
if (lastHealth == null) {
setLastHealth(getAndWrapHealth());
lastHealth = getLastHealth();
}
returnlastHealth;
}
privateHealthgetAndWrapHealth() {
ZonedDateTimestartTime = ZonedDateTime.now();
HealthbaseHealth = getWrappedHealthIndicator().health();
ZonedDateTimeendTime = ZonedDateTime.now();
Durationduration = Duration.between(startTime, endTime);
returnHealth.status(baseHealth.getStatus())
.withDetails(baseHealth.getDetails())
.withDetail(LAST_CHECKED_KEY, startTime)
.withDetail(LAST_DURATION_KEY, duration)
.build();
}
@Overridepublicvoidrun() {
setLastHealth(getAndWrapHealth());
}
}
}
Usage is simply replacing existing implements HealthIndicator instances with implements AsyncHealthIndicator
Activity
philwebb commentedon Mar 16, 2015
Definitely in the "nice to have" bucket. I imaging that the
healthendpoint isn't hit all that often so performance probably isn't a big deal.snicoll commentedon Mar 16, 2015
@philwebb I had the idea when I saw #2630
fatroom commentedon Oct 22, 2015
I would also like to have support for this. My project got a bunch of health checks and some of them can run up to few seconds. So in total performance of /health endpoint is terrible with sequential approach.
fjcano commentedon Oct 22, 2015
👍
Some of my projects have 20+ health checks.
For now we use our homebrew solution to do them in parallel.
Would love to see support for parallel health checks in Spring Boot out of the box.
Or at least a way to inject our own
CompositeHealthIndicator.prismec commentedon Sep 12, 2017
And it would be nice to include a standard detail information how long a certain health indicator took to execute.
[-]composite HealthIndicator that runs them in parallel[/-][+]Composite HealthIndicator that runs them in parallel[/+]erikgreif-acc commentedon Sep 7, 2018
Real-world example here:
Some services have requirements to respond within a given time limit. This time limit may be set by an external organization, not always under the control of the devs. This kind of timeout gets interpreted as a DOWN state, wakes devs up in the middle of the night, reboots service instances, and all the while provides no context as to which component was experiencing high latency (because there was no HTTP response).
I have successfully added timeouts per-actuator, but with 20 checks that require timeouts of around 5 seconds (any less would cause alerts for minor network blips), we are asking our caller to wait up to 1:40 for a response. At my org, this is absurd, and nobody wants to permit this behavior.
5 remaining items
antoinemeyer commentedon Nov 29, 2021
I ended up creating an implementation of async health indicators in this separate repo: https://github.com/antoinemeyer/spring-boot-async-health-indicator
It relies on a
ScheduledThreadPoolExecutorwith an annotation@AsyncHealth.I considered having it only property-driven (
management.health.async.indicator.$INDICATOR-BEAN-NAME.refresh-rate) or using a different interface (AsyncHealthIndicator) but believed an annotation would be more adequate.I would be very happy to have your feedback on the approach taken. If you think this can be integrated directly into spring-boot-actuator, I'd gladly work on a PR.
philwebb commentedon Dec 1, 2021
Thanks very much for the pull-request offer @antoinemeyer. It's really great to see that you've been able to add support in an additional library. We're currently not sure if we want to offer async support in the way that you've implemented it, or as suggested in #25459. Unfortunately, we're currently investing most of our time in Spring Boot 3.0 work so it's unlikely that we'll be able to make the decision anytime soon. I think it's best we wait until Spring Boot 3.0 is out before looking at this. That probably means that a pull-request would be a bit premature, and it would be best to consider things again when we're planning Spring Boot 3.1.
antoinemeyer commentedon Dec 2, 2021
Thanks @philwebb for the feedback (once again).
I am looking forward to see what solution you will end up adopting for this problem. In the meantime I'll rely on (and improve) that library and hope it can benefit others!
unnisathya92 commentedon Dec 27, 2021
hi @antoinemeyer, Do you have a working example for the aysnc-health-proj? It would really be helpful
antoinemeyer commentedon Dec 27, 2021
hi @unnisathya92 ! Sure, here is a starter with asynchronous health indicators: spring-async-health-indicator-demo.zip
kcshettar commentedon Mar 4, 2022
+1 for the feature. My application has three health check components.
Component 1: <100ms response time
Component 2: <400ms response time
Component 3: <400ms response time
Would love to see the
/actuator/healthendpoint to respond within 400ms (worst case).I am rendering the health details on react application (Home Page) which takes 100ms+400ms+400ms = 900ms right now. 900ms page load time is acceptable right now. It would be nice if the Home Page can load within 400ms.
We could implement the parallel processing logic as a temporary solution. But, I am sure this feature will come out of the box some day under
spring-boot-starter-actuator.ahoehma commentedon Aug 16, 2023
Any news here? In my app I have multiple db's, so multiple db-pools and so multiple health checks.
Now I see something like this:
Health contributor org.springframework.boot.actuate.jdbc.DataSourceHealthIndicator (db/creationCacheDbDataSource) took 269391ms to respond
This is really bad :)
Is there something I can do to pimp my (db) health checks to be little bit more smart regarding resources/runtime etc?
snicoll commentedon Aug 16, 2023
@ahoehma this issue represents the latest state.
I am not sure you're looking in the right direction. Running them in parallel should improve things a bit, but certainly not to the extend of what you're experiencing now. In other words, please review your indicator and backend configuration.
ahoehma commentedon Aug 17, 2023
@snicoll thanks for the info. I was just thinking that parallel running (slow) health-check can improve the situation a little bit but at the end you are right. Regarding the configuration of my db-indicators is there maybe somewhere some documentation? Until yet my understanding was that springboot just wrap each running Datasource into a health-indicator. Would be maybe better to use just another datasource to the same db just to keep all configurated pooled connections ready for business or should I just increase the max number of pooled connections to be ready. Also what happens if multiple callers ask the health endpoint ... there is always an on-the-fly health-check as fas as I know and this means if aws elb + other dashboards checking health ... my connections to the db just waisted :) May my whole topic is var to much for a issue ... is there a good place for such a discussion.
Many thanks!
Andreas
snicoll commentedon Aug 17, 2023
That, and we don't use the issue tracker for discussions. You may want to chat with the community on Gitter. You may also be interested in endpoint caching.
tomcruise81 commentedon Oct 19, 2023
Hopefully this is helpful to someone else here or in #25459. Taking a few queues from https://github.com/antoinemeyer/spring-boot-async-health-indicator (thanks @antoinemeyer), I came up with something for Spring Boot 3 that is not annotation based, but rather continues on in a manner similar to the existing
HealthIndicatorapproach:AsyncHealthIndicator
AsyncHealthIndicatorAutoConfiguration
Usage is simply replacing existing
implements HealthIndicatorinstances withimplements AsyncHealthIndicatorantoinemeyer commentedon Mar 2, 2024
@tomcruise81 FYI I updated spring-boot-async-health-indicator under version
boot3-v1.3for spring boot 3 support.