Scale SpringBoot App based on Thread Pool State

9/14/2020

We have a Spring Boot microservice which should get some data from old / legacy system. This microservice exposes external modern REST API. Sometimes we have to issue 7-10 requests to the legacy system in order to get all the data we need for single API call. Unfortunately we can't use Reactor / WebClient and have to stick with WebServiceTemplate to issue those "legacy" calls. We can't also use https://stackoverflow.com/questions/49685056/reactive-spring-webclient-making-a-soap-call

What is the best way to scale such a miroservice in Kubernetes? We have very big concerns that Thread Pool used for parallel WebServiceTemplate invocation will be depleted very fast, but I'm not sure that creating and exposing custom metric based on active threads count / thread pool size is a good idea.

Any advice will be helpful.

-- tillias
kubernetes
metrics
microservices
scaling
spring-boot

1 Answer

9/14/2020
  1. Enable Prometheus exporter in Spring
  2. Make sure metrics are scraped. You're going to watch for a threadpool_size metric. Refer your k8s/prometheus distro docs to get prometheus service discovery working for you.
  3. Write a horizontal pod autoscaler (HPA) based on a Prometheus metric:

Depending on what k8s distro you are using, you might have different ways to get the Prometheus and prometheus discovery:

-- Max Lobur
Source: StackOverflow