Description
Adib Saikali opened SPR-9887 and commented
As my application is growing in size spring start-up time is increasing and starting to be quite annoying during development. The application is setup to use component scanning, and JPA so there are a lot of @Entity
,@Service
, @Controller
, @Repository
, @Autowired
programming with the annotations is very productive, but start-up time of spring is starting to suffer. The app is still fairly small but growing here are some stats about the app:
628 classes in the application
279 beans with class level annotations
- 80
@Service
beans - 35
@Component
beans - 47
@Controller
beans - 15
@Repository
beans - 52
@Entity
JPA classes (Using Hibernate configured to scanning using spring) - 50
@MappedSupperClass
JPA classes (there contain various named queries so hibernate has to scan them)
489 beans with field and method declaration annotations
- 300
@Autowired
annotations - 146
@Transactional
methods - 43
@PersistenceContext
- 28
@PostConstruct
- 156
@Valid
annotations - 280
@RequestMapping
annotations
None of the @PostConstruct
do anything that requires network, or disk access, they are simple just computing and initializing objects in memory, or doing basic validation they can't possibly be causing the slow downs I see.
This application takes about 20 seconds to launch on high End Late 2011 MacBook Pro 2.5 GHz core i7 8GB RAM 256GB SSD running Java 7u9 and tomcat 7.0.29 on a machine that is a couple of years old with a mechanical drive or a slower cpu the startup time becomes a slow 90 to 180 seconds.
Class-path:
- Hibernate 4.1.7
- Spring 3.1.2
- Spring Security 3.1.3
- Hibernate Validator 4.3
- Tomcat 7.0.29
- AspectJ LTW 1.7.1
Here are the times to start-up the various parts of the applications, as seen in a typical run of the application from within STS 3.1.
- 17342 ms - Full server startup time
- 11098 ms - Root WebApplicationContext as printed by spring to the log file
- 1636 ms - Dispatcher servlet as printed by spring to the log file
total spring contexts initialization time 12734 ms out of 17342 ms reported by tomcat for application startup time or 73% of startup time
For the WebApplication context here are the main times of the non spring bits computed by looking at timestamp data in the log file
- 2013 ms - AspectJ load time weaving
- 567 ms - Flyway schema migration involves opening a connection to the db and checking one directory in the class for new .sql files
- 2762 ms - hibernate startup time
total 5342 ms for aspectj + flway + hibernate to do the initialization of the application context
Spring Web Context + Dispatches Servlets accounts for 7068 ms or 40% of total startup time
I have not taken a profiler to find out where that time is spent, my guess is that scanning of the classpath is a major part of this process, It would be great if spring can do the component scanning using multiple threads, to speed up the startup process.
20 seconds might seem pretty fast for a Java app but every week as code gets added that 20 seconds goes up. Also no complied stacks like nodeJS, and others really have very little startup time, I think Spring has always been the standard bearer in the java world for developer productivity, parallelizing startup will make a big difference for developers working on large application.
Affects: 3.1 GA
Issue Links:
- Parallel bean initialization during startup [SPR-8767] #13410 Parallel bean initialization during startup ("duplicates")
- Parallel bean initialization during startup [SPR-8767] #13410 Parallel bean initialization during startup
6 votes, 13 watchers