문서의 선택한 두 판 사이의 차이를 보여줍니다.
양쪽 이전 판 이전 판 다음 판 | 이전 판 다음 판 양쪽 다음 판 | ||
java:hibernate:performance [2015/11/11 20:02] kwon37xi |
java:hibernate:performance [2023/07/03 14:54] kwon37xi [Join Fetch] |
||
---|---|---|---|
줄 1: | 줄 1: | ||
====== Hibernate Performance Tuning ====== | ====== Hibernate Performance Tuning ====== | ||
* [[http:// | * [[http:// | ||
+ | * [[http:// | ||
* [[java: | * [[java: | ||
* [[java: | * [[java: | ||
+ | * [[java: | ||
+ | |||
+ | ===== Hibernate 성능 분석 ===== | ||
+ | * [[java: | ||
+ | * [[java: | ||
+ | |||
+ | ===== N+1 ===== | ||
+ | * [[https:// | ||
+ | * https:// | ||
+ | * [[https:// | ||
+ | |||
+ | ===== Join Fetch ===== | ||
+ | * JPQL 에서 '' | ||
+ | * 하지만 **1:N 관계에서 1측이 N 만큼 반복 조회되는 문제가 있다. 실제 엔티티 객체가 여러개 생성된다.** | ||
+ | * **limit 을 걸더라도 limit 이 DB에 걸리지 않고 모두 조회후 메모리에 걸리게 된다.** | ||
+ | * 따라서 '' | ||
+ | * see [[java: | ||
+ | * [[java: | ||
===== @org.hibernate.annotations.BatchSize ===== | ===== @org.hibernate.annotations.BatchSize ===== | ||
'' | '' | ||
줄 10: | 줄 29: | ||
하지만 '' | 하지만 '' | ||
- | * '' | + | * '' |
- | * OneToOne Eager 에 대해서는 작동하지 않았다. | + | * OneToOne, ManyToOne |
+ | * 지나치게 큰 값을 설정하지 말아야 한다. 30개 정도가 적당해 보이며, 쿼리 실행시간이 수십 밀리세컨드 이내로 끝날 수준으로 정하는게 좋다. | ||
===== hibernate.jdbc.fetch_size ===== | ===== hibernate.jdbc.fetch_size ===== | ||
- | TBD | + | * [[https:// |
+ | > In the first case, hibernate.jdbc.fetch_size sets the statement' | ||
+ | * '' | ||
+ | |||
+ | ===== hibernate.jdbc.batch_size ===== | ||
+ | * [[java: | ||
+ | * '' | ||
+ | * 이 때 sequence 기반으로 ID를 생성한다면, | ||
+ | ===== hibernate.query.in_clause_parameter_padding=true ===== | ||
+ | * Hibernate 5.2.18 이후 버전 '' | ||
+ | * '' | ||
+ | * [[https:// | ||
+ | * 위 옵션을 켜지 않으면, '' | ||
+ | * 또한 RDBMS 의 경우 그 자체 execution plan cache 가 있는데, 이 옵션을 켜면 그에 대한 hit 율도 높아지게 된다. | ||
+ | <note warning> | ||
+ | [[database: | ||
+ | |||
+ | 특히 200 개 기준인게 보통인데, | ||
+ | |||
+ | in 에 들어가는 값이 128 을 초과하지 않게 파티셔닝하고 관리하는게 좋다. '' | ||
+ | |||
+ | * '' | ||
+ | * '' | ||
+ | |||
+ | 참조 : [[https:// | ||
+ | </ | ||
+ | ===== Hibernate Query Plan Cache ===== | ||
+ | * [[https:// | ||
+ | * '' | ||
+ | * 별문제 없으면 변경하지 말 것. | ||
+ | ===== autoCommit 을 꺼서 성능 향상시키기 ===== | ||
+ | * Connection Pool 의 '' | ||
+ | |||
+ | <note warning> | ||
+ | 아주 많은 Spring의 확장들이 auto commit=true를 가정하고 만들어져 있는 것으로 보인다. | ||
+ | |||
+ | auto commit=false 이면서 Spring Data 사용시 제대로 Transaction이 안 걸려 있으면 오동작이 발생한다. | ||
+ | 모든 Repository 인터페이스와 Custom 구현에 '' | ||
+ | </ | ||
+ | |||
+ | * [[https:// | ||
+ | * [[https:// | ||
+ | * 커넥션 풀 설정의 '' | ||
+ | * '' | ||
+ | * [[springframework: | ||
+ | * [[https:// | ||
+ | * '' | ||
+ | if (!vendorProperties.containsKey(PROVIDER_DISABLES_AUTOCOMMIT)) { | ||
+ | configureProviderDisablesAutocommit(vendorProperties); | ||
+ | } | ||
+ | |||
+ | ... | ||
+ | |||
+ | if (isDataSourceAutoCommitDisabled() && !isJta()) { | ||
+ | vendorProperties.put(PROVIDER_DISABLES_AUTOCOMMIT, | ||
+ | } | ||
+ | </ | ||
+ | |||
+ | > in Hibernate 5.2.10, we introduced the hibernate.connection.provider_disables_autocommit configuration property which tells Hibernate that the underlying JDBC Connections already disabled the auto-commit mode. | ||
===== Assert statement count ===== | ===== Assert statement count ===== | ||
줄 32: | 줄 111: | ||
* [[http:// | * [[http:// | ||
* [[http:// | * [[http:// | ||
+ | * [[http:// | ||
+ | * [[https:// | ||
+ | * [[https:// | ||
+ | * [[https:// | ||
+ | * [[https:// | ||
+ | * [[https:// | ||
+ | * [[https:// | ||
+ | * [[https:// | ||
+ | * [[https:// | ||
+ | * [[https:// | ||
+ | * [[https:// | ||
+ | * [[https:// |