Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Spring Boot Actuator to run in separate thread pool

Is it possible to handle actuator requests like health within a separate thread pool from the "main" application?

Why am I asking? I've got an application that might sometimes use up all available threads, and the Kubernetes health check is failing due to the unavailability of a thread to compute the health endpoint request.

I want to make sure that every health request is processed no matter how much load the application is under.

I was thinking about maybe defining a separate thread pool for the actuators to operate with, but I am not sure how to do this.

like image 770
onkeliroh Avatar asked Nov 18 '19 19:11

onkeliroh


People also ask

Can we use thread pool in spring boot?

In order to make methods that run in a separate thread the "SpringBoot way", we will use @Async annotations on those methods. But first, we must make an async config class to define the thread pool those methods will use. This config must have the @EnableAsync annotation.

How do you run an actuator on a spring boot?

To enable Spring Boot actuator endpoints to your Spring Boot application, we need to add the Spring Boot Starter actuator dependency in our build configuration file. Maven users can add the below dependency in your pom. xml file. Gradle users can add the below dependency in your build.

How does a spring actuator work internally?

Spring Boot Application Internal Working. Spring does not generate any code automatically and not using any xml configuration file . so spring uses internally pragmatically configuration done by spring boot developer that are provided by jar. To Enable preconfigured jars we just need to define dependency in pom.

How does spring boot actuator work?

Actuator is mainly used to expose operational information about the running application — health, metrics, info, dump, env, etc. It uses HTTP endpoints or JMX beans to enable us to interact with it. Once this dependency is on the classpath, several endpoints are available for us out of the box.


1 Answers

We had a similar problem with some of our apps when running in Kubernetes. We looked at different ways of creating multiple tomcat connectors and changing the spring management port to get the desired affect, but never quite got it.

In the end, we attacked the root of the problem, which was resource starvation within the pod. We found that the apps experiencing the health check timeouts had lots of extra threads for various 3rd party thread pools. In some cases we had apps with close to 500 threads, so even under what we considered moderate load, the tomcat pools would get starved and couldn't handle new requests.

FWIW, the biggest culprit we found was the effect of CPU request on a pod and the JDK. When we didn't set any request, the JDK would see every CPU on the node when it queried for numbers of processors. We found there are lots of places in the Java ecosystem where number of processors is used to initialize different thread pools.

In our case, each node had 36 processors, and we found around 10-12 thread pools using this number to determine size...not hard to see to how an app could quickly grow to 500 threads.

like image 82
Mike Avatar answered Sep 20 '22 04:09

Mike