웹 개발/Spring Framework
[Spring boot + JPA] Hibernate 성능 분석을 위한 로깅하기
희랍인 조르바
2023. 12. 28. 17:43
1. 하이버네이트 세션 관련해서 걸린 시간들을 통계내기
* 주의: 성능 이슈를 유발하므로 운영환경에선 쓰지말자.
// application.yaml
spring.jpa.properties.hibernate.generate_statistics=true
// logback.xml
<logger name="org.hibernate.stat" level="DEBUG"/>
2. 슬로우 쿼리 찾기
필요한 경우, 운영환경에 적용해서 모니터링 해보자.
// application.yaml
spring.jpa.properties.hibernate.session.events.log.LOG_QUERIES_SLOWER_THAN_MS=1
// logback.xml
<logger name="org.hibernate.SQL_SLOW" level="INFO"/>
(스크린샷 내용하고 다름)아래처럼 찍힌다
2021-08-15 10:54:52.397 INFO 31972 --- [ main] org.hibernate.SQL_SLOW : SlowQuery: 11 milliseconds. SQL: 'HikariProxyPreparedStatement@1734615070 wrapping select tournament0_.players_id as players_2_4_0_, tournament0_.tournaments_id as tourname1_4_0_, chesstourn1_.id as id1_2_1_, chesstourn1_.end_date as end_date2_2_1_, chesstourn1_.name as name3_2_1_, chesstourn1_.start_date as start_da4_2_1_, chesstourn1_.version as version5_2_1_ from chess_tournament_players tournament0_ inner join chess_tournament chesstourn1_ on tournament0_.tournaments_id=chesstourn1_.id where tournament0_.players_id=1'
출처
- https://thorben-janssen.com/hibernate-features-with-spring-data-jpa