2

I have a Springboot application that has an embedded Tomcat to host some Jersey REST service. When I run the fat jar, around 8000 classes load in around 10 minutes. The class loading is extremely slow. However, other java apps seem faster. What should I do to improve the class loading performance from the fat jar? When I run the app with mvn spring-boot:run, it's quite fast.

enter image description here

Saptarshi Basu
  • 6,115
  • 3
  • 35
  • 46
  • So it also takes 10 minutes before the application actually starts to do anything, or is it only the loading of the classes which is spread out over time? – Gimby Oct 16 '17 at 11:12
  • Hi @Gimby, Yes - the application becomes available only after these 10 minutes. Basically for first 7 minutes or so, it doesn't print anything on the console. Even if I run in -Ddebug mode, the actual autoconfiguration starts much later – Saptarshi Basu Oct 16 '17 at 11:15
  • 1
    I don't have an explanation for it to be honest, this is highly unusual and not something I can reproduce locally. If it weren't so unlikely I'd be starting to doubt the integrity of the hard drive. – Gimby Oct 16 '17 at 12:15
  • @Gimby, my hard drive is encrypted and also running Semantec Endpoint Protection. Could it be because of that? The only thing I am not sure of is why `mv spring-boot:run` is so fast - it also scans the jar files - the only difference being a wrapper jar with BOOT-INF – Saptarshi Basu Oct 16 '17 at 12:34
  • 1
    Get hold of a Java profiler such as YourKit and profile the app to find out what's taking the time. This is honestly the only way you are going to find out exactly what the issue is. – PaulNUK Oct 16 '17 at 13:17
  • 2
    PS virus checkers are the spawn of the devil when they come across jar files, as these are basically zip files with thousands of entries within them. You could also try disabling jar scanning if you are using Tomcat: https://stackoverflow.com/questions/43264890/after-upgrade-from-spring-boot-1-2-to-1-5-2-filenotfoundexception-during-tomcat#43280452 – PaulNUK Oct 16 '17 at 13:21
  • 1
    @Saptarshi Encryption is usually pretty fast and especially when using AES with an AES-NI capable CPU. Reading a RAID with full speed increases the CPU usage by maybe 1% (it used to be 4% without AES-NI). I'd bet on the anti-virus. – maaartinus Oct 17 '17 at 00:17
  • Today [this](https://stackoverflow.com/questions/47095448/spring-component-scan-autowire-in-signed-jar-files-is-slow) question was asked. Might it be the same problem? – Gimby Nov 03 '17 at 15:06
  • @Saptarshi I am facing a similar issue. The fat jar takes approximately 7-8 times as compared to mvn spring-boot:run. Did you find the root cause for this? I also checked the number of times the resolving of resources takes and surprisingly it is equal in both cases. Please do let me know if you could somehow improve the performance. Thanks :) – Sahil Nagpal Jan 08 '18 at 21:40
  • @SahilNagpal - For me the same jar was taking only 10-15 seconds in Linux systems. I suspect the problem I faced in Windows system due to the installed Semantec antivirus only. Although it is true that the same Windows system can run other jar files (non-springboot) without such delay in loading. So, I couldn't really find the root cause. – Saptarshi Basu Jan 09 '18 at 10:46

0 Answers0