Spring Boot Slow Startup Time in Docker when limiting CPUs

See original GitHub issue

My organization is wanting to optimize the usage of our applications within a Kubernetes container by utilizing the minimum appropriate CPU for the applications running. When doing analysis, we have discovered a healthy area that the CPU allows the application to run appropriately. However the startup time for the application takes a huge hit in our environment.

Suggesting to increase CPU strictly for startup time enhancements really isn’t an option we want to pursue and looking through the documents and guides we could find, there doesn’t appear to be a lot of information on appropriate ways to address this problem effectively.

I would like to throw an issue up to analyze the use case of an application when restricting CPU. I have created a repo that has a bare bones Spring Boot application that we can analyze for this discussion.

We are interested in trying to create a standard document on how our developers can utilize Spring Boot effectively in Kubernetes with as thin of a CPU as possible while still having the startup time performance we would expect an application to have. Currently we are running using the cpu setting of 600m within Kubernetes which is roughly equivalent to running the docker command with --cpus=".6".

Running on my box which is an i7-7600U @ 2.8GHz with 16 GB of RAM, I am seeing roughly 30 seconds startup time with the code in my repository.

A member of our org has also created some benchmark results comparing other frameworks with similar code. Their box they ran the tests on was an i7 process @ 2.6 with 16 GB of RAM as well. The results are available here.

I would like to start a conversation that will hopefully lead to some focused documentation on this particular request. I believe this documentation could help many organizations using Spring Boot that is starting to migrate to Kubernetes. I’m not sure if it would help to also bring in the Spring Cloud Kubernetes team potentially as well but let this be the start of the discussion.

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Reactions:12
  • Comments:13 (5 by maintainers)

github_iconTop GitHub Comments

3reactions
dsyercommented, Feb 13, 2020

Thanks for the update.

Directly importing the autoconfiguration classes that are required

Probably could get you 10 or 20% improvement for simple apps.

Not using spring boot at all and initializing the application context manually

Not really going to help, unless you end up with fewer features (see above).

Using the spring-boot-thin-layout to reduce the number of used dependencies.

Not sure what you mean here. The dependencies are the dependencies. You either use them or you don’t - it has nothing to do with the JAR layout.

Playing with Spring Fu and Spring Graal Native projects

Both will have an impact (Graal Native a big impact). Both are limited in scope, and are still experimental. But please do play around and see if it works for you. Feedback more than welcome.

2reactions
dsyercommented, Mar 6, 2020

The database connection of implementation won’t make any difference. For JPA you need the additional spring data lazy flag, i.e. spring.data.jpa.repositories.bootstrap-mode=lazy.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Speed up Spring Boot startup time - java - Stack Overflow
Speed up Spring Boot startup time · 1. Post your code. · 1. If you use Hibernate it also tends to eat significant...
Read more >
Speed up Spring Boot Startup Time - Baeldung
In this tutorial, we'll cover different configurations and setups that can help decrease Spring Boot startup time.
Read more >
How to cold start fast a java service on k8s (EKS) - ITNEXT
Increasing the CPU limit of a java service will cause it to start faster but will create CPU over commitment that needs to...
Read more >
Very Slow Spring Boot Application Startup - ADocLib
A spring boot application takes very long to start (usually between 5 and 30 (so yes, quite a lot) I'm grateful for any...
Read more >
Production Considerations for Spring on Kubernetes
Here's the startup time for the famous Spring Boot Petclinic application ... CPUs on the host although I asked the container to limit...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found