Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Spring-boot slow to start

Tags:

jhipster

When I launch my jhipster app using "mvn spring-boot:run", it takes up to 60 seconds to start... First part of my log is :

[INFO] Scanning for projects...
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] Building jhipster 0.0.1-SNAPSHOT
[INFO] ------------------------------------------------------------------------
[INFO]
[INFO] >>> spring-boot-maven-plugin:1.1.9.RELEASE:run (default-cli) @ jhipster >>>
[INFO]
[INFO] --- maven-enforcer-plugin:1.3.1:enforce (enforce-versions) @ jhipster ---
[INFO]
[INFO] --- maven-resources-plugin:2.6:resources (default-resources) @ jhipster ---
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] Copying 4 resources
[INFO] Copying 22 resources
[INFO]
[INFO] --- maven-compiler-plugin:3.1:compile (default-compile) @ jhipster ---
[INFO] Nothing to compile - all classes are up to date
[INFO]
[INFO] --- maven-resources-plugin:2.6:testResources (default-testResources) @ jhipster ---
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] Copying 3 resources
[INFO]
[INFO] --- maven-compiler-plugin:3.1:testCompile (default-testCompile) @ jhipster ---
[INFO] Nothing to compile - all classes are up to date
[INFO]
[INFO] <<< spring-boot-maven-plugin:1.1.9.RELEASE:run (default-cli) @ jhipster <<<
[INFO]
[INFO] --- spring-boot-maven-plugin:1.1.9.RELEASE:run (default-cli) @ jhipster ---
[INFO] Attaching agents: []
Listening for transport dt_socket at address: 5005

--> Then it hangs for around 30 seconds before continuing :

[INFO] com.mycompany.myapp.Application - Starting Application on MacBook-Pro.local with PID 5130 (/Users/othomas/Developpement/jhipster-1.9.0/target/classes started by othomas in /Users/othomas/Developpement/jhipster-1.9.0)
[DEBUG] com.mycompany.myapp.Application - Running with Spring Boot v1.1.9.RELEASE, Spring v4.0.8.RELEASE
[DEBUG] org.jboss.logging - Logging Provider: org.jboss.logging.Log4jLoggerProvider

...

I remember having used older versions of jhipster generator (0.17 etc) et it started in 15-20 seconds. Is it normal or is there a problem on my side ? Where to look for ?

Thanks, O.

like image 243
user1848637 Avatar asked Nov 22 '14 18:11

user1848637


People also ask

Why is spring boot so slow?

When a Spring Boot Application has slow startup, it can be one or more beans and related dependencies taking longer to initialise and slowing down the entire process. Profiling Spring Boot application doesn't often help in diagnosing the startup issues.

Are Spring boots fast?

The only part that spring boot is slower than alternatives, is runtime start-up time. Especially on Kubernetes where several spring apps might start-up on the same VM, it's horrible.

Why is spring boot faster?

Spring Native Native image is Java code compiled using an ahead-of-time compiler and packed into an executable file. It doesn't require Java to run. The resulting program is faster and less memory-dependent since there is no JVM overhead.


2 Answers

I've been suffering slow startup times myself and wondering what the cause was. I get all the console messages saying various things have started and then it hangs just before the final message to say the app has loaded.

Eventually I found I could use Java VisualVM as part of the JDK to see what was going on. If you have the jdk installed its jvisualvm.exe in the bin folder. Then when I select to debug as Application.java the tomcat process pops up and you can track what's going on.

I took a couple of thread dumps where it hangs and it always seemed to be where the swagger API docs are being generated. A bit more digging and this is configured in a class called MetricsConfiguration which is excluded if you run with a profile called "fast".

In eclipse I edited my debug configuration to include a program argument of:

--spring.profiles.active=dev,fast

This cuts down the startup time from 230 seconds to just 25!

I had a quick scan and fast seems to disable all sorts of things. It mainly looks like the stuff under the admin menu which you'll probably not need during development anyway. Personally I would prefer a fast bootup to being able to see the rest docs during development.

Swagger being such a hog made me wonder if it's such a good idea after all. Is it worth the cost? i then read this http://java.dzone.com/articles/swagger-great and I'm considering just removing it altogether. It's a nice idea but seems to add 33mb to the build + for me was causing really slow startup times.

For info I have around 16 entities. So not small but not excessively large either.

like image 175
Ben Thurley Avatar answered Sep 30 '22 15:09

Ben Thurley


Make sure you aren't running the server in debug mode and have a breakpoint set. This reduced the startup time of one of my applications from 3 min to 22 sec.

like image 26
Jannik Avatar answered Sep 30 '22 14:09

Jannik