We have a Spring Boot app and it's startup time is a disadvantage for us; it is slowing down the CI/CD process. It's startup time is ~140 seconds;
- WebApplicationContext initialization completes in ~30 seconds
- org.hibernate.boot.internal.MetadataImpl.getSessionFactoryBuilder -> ~30 seconds
- DispatcherServlet initialization completes in ~60 seconds
- And rest of the operations takes ~20 seconds.
I've researched about how to increase Spring startup time and I've read How Fast is Spring? blog and related stackoverflow posts. But, these are not helping to us since the actual problem is different. For example, only DispatcherServlet initialization completes in ~60 seconds. Therefore, I've researched about DispatcherServlet and I saw that it is completely related with Spring; just a FontController, so it should be faster than the current version.
However, while DispatcherServlet initialization I see that hibernates opens a connection and commits something. Hibernate committing takes ~50 seconds where the whole DispatcherServlet initialization ~60 seconds.
Then, I've debugged and I saw that committing happens while DispatcherServlet.initHandlerMappings() call, but I couldn't go further than this.
Do you have an idea about why DispatcherServlet initialization takes this much time?
A part from log file about DispatcherServlet initialization:
2021-04-16 14:47:12 INFO 1 DispatcherServlet | Initializing Servlet 'dispatcherServlet'
2021-04-16 14:47:16 DEBUG 1 TransactionImpl | On TransactionImpl creation, JpaCompliance#isJpaTransactionComplianceEnabled == false
2021-04-16 14:47:16 WARN 1 NamedQuery | Finder method public abstract java.util.List com.example.TestRepository.getTestList1(org.springframework.data.domain.Pageable) is backed by a NamedQuery but contains a Pageable parameter! Sorting delivered via this Pageable will not be applied!
2021-04-16 14:47:16 DEBUG 1 TransactionImpl | On TransactionImpl creation, JpaCompliance#isJpaTransactionComplianceEnabled == false
2021-04-16 14:47:16 DEBUG 1 TransactionImpl | On TransactionImpl creation, JpaCompliance#isJpaTransactionComplianceEnabled == false
2021-04-16 14:47:16 DEBUG 1 TransactionImpl | On TransactionImpl creation, JpaCompliance#isJpaTransactionComplianceEnabled == false
2021-04-16 14:47:16 DEBUG 1 TransactionImpl | On TransactionImpl creation, JpaCompliance#isJpaTransactionComplianceEnabled == false
2021-04-16 14:47:16 DEBUG 1 TransactionImpl | On TransactionImpl creation, JpaCompliance#isJpaTransactionComplianceEnabled == false
2021-04-16 14:47:16 WARN 1 NamedQuery | Finder method public abstract java.util.List com.example.TestRepository.getTestList2(org.springframework.data.domain.Pageable) is backed by a NamedQuery but contains a Pageable parameter! Sorting delivered via this Pageable will not be applied!
2021-04-16 14:47:16 DEBUG 1 TransactionImpl | On TransactionImpl creation, JpaCompliance#isJpaTransactionComplianceEnabled == false
2021-04-16 14:47:16 DEBUG 1 TransactionImpl | On TransactionImpl creation, JpaCompliance#isJpaTransactionComplianceEnabled == false
2021-04-16 14:47:16 DEBUG 1 TransactionImpl | On TransactionImpl creation, JpaCompliance#isJpaTransactionComplianceEnabled == false
2021-04-16 14:47:16 DEBUG 1 TransactionImpl | On TransactionImpl creation, JpaCompliance#isJpaTransactionComplianceEnabled == false
2021-04-16 14:47:17 DEBUG 1 TransactionImpl | On TransactionImpl creation, JpaCompliance#isJpaTransactionComplianceEnabled == false
2021-04-16 14:47:17 DEBUG 1 TransactionImpl | begin
2021-04-16 14:47:17 INFO 1 p6spy | #1618573637572 | took 152ms | statement | connection 1| url jdbc:p6spy:firebirdsql:localhost/8080
SELECT 1 FROM TEST_QUERY
SELECT 1 FROM TEST_QUERY;
2021-04-16 14:47:17 DEBUG 1 TransactionImpl | committing
2021-04-16 14:48:03 INFO 1 EndpointLinksResolver | Exposing 15 endpoint(s) beneath base path '/app'
2021-04-16 14:48:04 DEBUG 1 TransactionImpl | On TransactionImpl creation, JpaCompliance#isJpaTransactionComplianceEnabled == false
2021-04-16 14:48:04 DEBUG 1 TransactionImpl | On TransactionImpl creation, JpaCompliance#isJpaTransactionComplianceEnabled == false
2021-04-16 14:48:04 DEBUG 1 TransactionImpl | On TransactionImpl creation, JpaCompliance#isJpaTransactionComplianceEnabled == false
2021-04-16 14:48:04 DEBUG 1 TransactionImpl | On TransactionImpl creation, JpaCompliance#isJpaTransactionComplianceEnabled == false
2021-04-16 14:48:04 DEBUG 1 TransactionImpl | On TransactionImpl creation, JpaCompliance#isJpaTransactionComplianceEnabled == false
2021-04-16 14:48:04 DEBUG 1 TransactionImpl | On TransactionImpl creation, JpaCompliance#isJpaTransactionComplianceEnabled == false
2021-04-16 14:48:04 DEBUG 1 TransactionImpl | On TransactionImpl creation, JpaCompliance#isJpaTransactionComplianceEnabled == false
2021-04-16 14:48:04 DEBUG 1 TransactionImpl | On TransactionImpl creation, JpaCompliance#isJpaTransactionComplianceEnabled == false
2021-04-16 14:48:04 DEBUG 1 TransactionImpl | On TransactionImpl creation, JpaCompliance#isJpaTransactionComplianceEnabled == false
2021-04-16 14:48:04 INFO 1 DispatcherServlet | Completed initialization in 52429 ms