Spring boot with JPA(Hibernate) after deployment first save/saveAll (write) to Database is very slow almost 20 seconds. but fetch/get are faster . (Running app in docker with 1CPU and 2GB RAM to have same as AWS)
Config are below
“spring.datasource.driver-class-name”: “com.mysql.cj.jdbc.Driver”,
“spring.datasource.password”: “pwd”,
“spring.datasource.url”: “jdbc:mysql://localhost5:3306/db?allowPublicKeyRetrieval=TRUE”,
“spring.datasource.username”: “usr”,
“spring.jpa.properties.hibernate.default_lazy_behavior”: false,
“spring.jpa.properties.hibernate.dialect”: “org.hibernate.dialect.MySQL8Dialect”,
“spring.jpa.properties.hibernate.hbm2ddl.auto”: “none”,
“spring.jpa.show-sql”: true,
“spring.jpa.properties.hibernate.format_sql”: true,
“spring.jpa.properties.hibernate.jdbc.batch_size”: 20,
“spring.jpa.properties.hibernate.order_inserts”: true,
“spring.jpa.properties.hibernate.order_updates”: true,
“spring.datasource.hikari.minimum-idle”: 10,
“spring.datasource.hikari.maximum-pool-size”: 30,
“spring.datasource.hikari.idle-timeout”: 30000,
“spring.datasource.hikari.connection-timeout”: 30000,
“spring.datasource.hikari.max-lifetime”: 1800000,
“spring.datasource.hikari.pool-name”: “HikariCP”,
“spring.main.lazy-initialization”: false,
“spring.datasource.initialization-mode”:”always”,
“spring.datasource.hikari.initialization-fail-timeout”:0,
“spring.jpa.hibernate.ddl-auto”:”validate”
Sprint boot
org.springframework.boot spring-boot-starter-parent 2.7.5 and JPA org.springframework.boot spring-boot-starter-data-jpa org.hibernate hibernate-core 5.6.12.Final com.mysql mysql-connector-j
its simple Rest application .
Logs below show first save call slow
2024-07-29 17:48:35 2024-07-29 13:48:35.159 INFO 1 — [nio-8086-exec-2] c.h.g.b.a.BackofficeServiceLoggingAspect : Back Office Service -> Enter: PKG.controller.BackofficeUserController.signIn(…) at = 2024-07-29T13:48:35.159376010
2024-07-29 17:48:35 2024-07-29 13:48:35.165 INFO 1 — [nio-8086-exec-2] c.h.g.b.a.BackofficeServiceLoggingAspect : Back Office Service -> Enter: PKG.service.impl.UserServiceImpl.signIn(…) at = 2024-07-29T13:48:35.164995218
2024-07-29 17:48:35 2024-07-29 13:48:35.172 INFO 1 — [nio-8086-exec-2] c.h.g.b.a.BackofficeServiceLoggingAspect : Back Office Service -> Enter: PKG.repository.BackofficeUserRepository.findUserByUserName(…) at = 2024-07-29T13:48:35.172132093
2024-07-29 17:48:35 2024-07-29 13:48:35.384 INFO 1 — [nio-8086-exec-2] c.h.g.b.a.BackofficeServiceLoggingAspect : Back Office Service -> Exit: PKG.repository.BackofficeUserRepository.findUserByUserName(..) at = 2024-07-29T13:48:35.384056635 took 211 ms
2024-07-29 17:48:38 2024-07-29 13:48:38.923 INFO 1 — [nio-8086-exec-2] c.h.g.b.a.BackofficeServiceLoggingAspect : Back Office Service -> Enter: org.springframework.data.repository.CrudRepository.save(…) at = 2024-07-29T13:48:38.923041179
2024-07-29 17:48:50 2024-07-29 13:48:50.707 INFO 1 — [nio-8086-exec-2] c.h.g.b.a.BackofficeServiceLoggingAspect : Back Office Service -> Exit: org.springframework.data.repository.CrudRepository.save(..) at = 2024-07-29T13:48:50.707711920 took 11783 ms
2024-07-29 17:48:50 2024-07-29 13:48:50.707 INFO 1 — [nio-8086-exec-2] c.h.g.b.a.BackofficeServiceLoggingAspect : Back Office Service -> Enter: PKG.service.impl.AWSCognitoAuthenticationServiceImpl.signIn(…) at = 2024-07-29T13:48:50.707979211
2024-07-29 17:48:51 2024-07-29 13:48:51.606 INFO 1 — [nio-8086-exec-2] c.h.g.b.a.BackofficeServiceLoggingAspect : Back Office Service -> Enter: PKG.service.impl.BackofficeUserServiceImpl.getBackofficeUserByUsername(…) at = 2024-07-29T13:48:51.606463254
2024-07-29 17:48:51 2024-07-29 13:48:51.612 INFO 1 — [nio-8086-exec-2] c.h.g.b.a.BackofficeServiceLoggingAspect : Back Office Service -> Enter: PKG.repository.BackofficeUserRepository.findUserByUserName(…) at = 2024-07-29T13:48:51.612634170
2024-07-29 17:48:51 2024-07-29 13:48:51.617 INFO 1 — [nio-8086-exec-2] c.h.g.b.a.BackofficeServiceLoggingAspect : Back Office Service -> Exit: PKG.repository.BackofficeUserRepository.findUserByUserName(..) at = 2024-07-29T13:48:51.617310212 took 4 ms
2024-07-29 17:48:51 2024-07-29 13:48:51.617 INFO 1 — [nio-8086-exec-2] c.h.g.b.a.BackofficeServiceLoggingAspect : Back Office Service -> Exit: PKG.service.impl.BackofficeUserServiceImpl.getBackofficeUserByUsername(..) at = 2024-07-29T13:48:51.617448420 took 11 ms
2024-07-29 17:48:51 2024-07-29 13:48:51.617 INFO 1 — [nio-8086-exec-2] c.h.g.b.a.BackofficeServiceLoggingAspect : Back Office Service -> Exit: PKG.service.impl.AWSCognitoAuthenticationServiceImpl.signIn(..) at = 2024-07-29T13:48:51.617497004 took 909 ms
2024-07-29 17:48:51 2024-07-29 13:48:51.617 INFO 1 — [nio-8086-exec-2] c.h.g.b.a.BackofficeServiceLoggingAspect : Back Office Service -> Enter: org.springframework.data.repository.CrudRepository.save(…) at = 2024-07-29T13:48:51.617572754
2024-07-29 17:48:51 2024-07-29 13:48:51.625 INFO 1 — [nio-8086-exec-2] c.h.g.b.a.BackofficeServiceLoggingAspect : Back Office Service -> Exit: org.springframework.data.repository.CrudRepository.save(..) at = 2024-07-29T13:48:51.625113379 took 7 ms
2024-07-29 17:48:51 2024-07-29 13:48:51.625 INFO 1 — [nio-8086-exec-2] c.h.g.b.a.BackofficeServiceLoggingAspect : Back Office Service -> Exit: PKG.service.impl.UserServiceImpl.signIn(..) at = 2024-07-29T13:48:51.625353254 took 16458 ms
2024-07-29 17:48:51 2024-07-29 13:48:51.625 INFO 1 — [nio-8086-exec-2] c.h.g.b.a.BackofficeServiceLoggingAspect : Back Office Service -> Exit: PKG.controller.BackofficeUserController.signIn(..) at = 2024-07-29T13:48:51.625394212 took 16464 ms