사용자 도구

사이트 도구


java:hibernate:performance

차이

문서의 선택한 두 판 사이의 차이를 보여줍니다.

차이 보기로 링크

양쪽 이전 판 이전 판
다음 판
이전 판
다음 판 양쪽 다음 판
java:hibernate:performance [2017/11/30 21:52]
kwon37xi [Hibernate 성능 분석]
java:hibernate:performance [2019/02/20 09:00]
kwon37xi
줄 4: 줄 4:
   * [[java:hibernate:cache|Hibernate Cache]] - [[java:jpa:cache|JPA Second Level Cache]]   * [[java:hibernate:cache|Hibernate Cache]] - [[java:jpa:cache|JPA Second Level Cache]]
   * [[java:hibernate:batch|Hibernate Batch/Bulk Insert/Update]]   * [[java:hibernate:batch|Hibernate Batch/Bulk Insert/Update]]
 +  * [[java:jpa:entitygraph|JPA @EntityGraph]]
 +
  
 ===== Hibernate 성능 분석 ===== ===== Hibernate 성능 분석 =====
-  * ''hibernate.generate_statistics=true'' 로 설정하고 ''org.hibernate.stat''을 ''DEBUG'' 모드로 둘 것. +  * [[java:hibernate:statistics|Hibernate Statistics]] 
-  * [[java:hibernate:log|Hibernate Log 남기기]] + 
-  * [[https://docs.jboss.org/hibernate/orm/5.2/javadocs/org/hibernate/SessionFactory.html|SessionFactory.getStatistics()]] 사용+==== Join Fetch ==== 
 +  * JPQL 에서 ''join fetch''를 통해서 (inner join등 명시N + 1 대신에 미리 join 문으로 객체를 로딩할 수 있다.
  
 ===== @org.hibernate.annotations.BatchSize ===== ===== @org.hibernate.annotations.BatchSize =====
줄 16: 줄 19:
 하지만 ''@BatchSize(size = 10)'' 처럼 해당 관계에 설정을 해 두면, Kitten 객체를 로딩할 때 Cat id 10개씩 ''**in**'' Query로 한번에 로딩한다. 하지만 ''@BatchSize(size = 10)'' 처럼 해당 관계에 설정을 해 두면, Kitten 객체를 로딩할 때 Cat id 10개씩 ''**in**'' Query로 한번에 로딩한다.
  
-  * ''hibernate.default_batch_fetch_size=100'' 프라퍼티 형태로 일괄 지정도 가능하다.+  * ''hibernate.default_batch_fetch_size=30'' 프라퍼티 형태로 일괄 지정도 가능하다.
   * OneToOne Eager 에 대해서는 작동하지 않았다.   * OneToOne Eager 에 대해서는 작동하지 않았다.
 +  * 지나치게 큰 값을 설정하지 말아야 한다. 30개 정도가 적당해 보이며, 쿼리 실행시간이 수십 밀리세컨드 이내로 끝날 수준으로 정하는게 좋다.
  
 ===== hibernate.jdbc.fetch_size ===== ===== hibernate.jdbc.fetch_size =====
 +  * [[https://access.redhat.com/documentation/en-us/jboss_enterprise_application_platform/5/html/performance_tuning_guide/sect-performance_tuning_guide-entity_beans-batching_database_operations|4.5.4. Batching Database Operations - Red Hat Customer Portal]]
 +
 TBD TBD
 +
 +===== hibernate.jdbc.batch_size =====
 +TBD
 +
 +===== autoCommit 을 꺼서 성능 향상시키기 =====
 +  * Connection Pool 의 ''auto commit=false''을 항상 켜고, Hibernate 에서 직접 ''auto commit=false'' 하는 것을 막아서 불필요한 ''setAutoCommit()'' 호출로 인한 성능 저하를 줄이기
 +  * [[https://pkgonan.github.io/2019/01/hibrnate-autocommit-tuning|Hibernate setAutoCommit 최적화를 통한 성능 튜닝]]
 +  * [[https://vladmihalcea.com/why-you-should-always-use-hibernate-connection-provider_disables_autocommit-for-resource-local-jpa-transactions/|Why you should always use hibernate.connection.provider_disables_autocommit for resource-local JPA transactions - Vlad Mihalcea]]
 +  * 커넥션 풀 설정의 ''auto-commit: false''로 지정. 이걸 ''true''로 해버리면 트랜잭션이 안 먹음.
 +  * ''hibernate.connection.provider_disables_autocommit: true''로 지정 : 커넥션 풀의 autocommit 을 무조건 따르겠다는 의미. ''5.2.10'' 이상 버전
 +  * [[springframework:springboot:2|SpringBoot 2]] 부터는 커넥션 풀의 ''auto-commit'' 설정값에 따라 자동으로 ''hibernate.connection.provider_disables_autocommit: true'' 설정을 해준다. 
 +    * [[https://github.com/spring-projects/spring-boot/issues/9261|Consider disabling auto-commit when wiring connection pool configs and setting hibernate.connection.provider_disables_autocommit for resource-local transactions · Issue #9261 · spring-projects/spring-boot]]
 +    * ''HibernateJpaConfiguration.java'' <code java>
 +if (!vendorProperties.containsKey(PROVIDER_DISABLES_AUTOCOMMIT)) { 
 +    configureProviderDisablesAutocommit(vendorProperties); 
 +}
 +
 +...
 +
 +if (isDataSourceAutoCommitDisabled() && !isJta()) { 
 +  vendorProperties.put(PROVIDER_DISABLES_AUTOCOMMIT, "true"); 
 +}
 +</code>
 +
 +> 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  =====
줄 40: 줄 72:
   * [[http://www.thoughts-on-java.org/tips-to-boost-your-hibernate-performance/|7 Tips to boost your Hibernate performance]]   * [[http://www.thoughts-on-java.org/tips-to-boost-your-hibernate-performance/|7 Tips to boost your Hibernate performance]]
   * [[https://www.youtube.com/watch?v=F5asq8ZG_1k|7 Tips to improve your Hibernate performance - YouTube]]   * [[https://www.youtube.com/watch?v=F5asq8ZG_1k|7 Tips to improve your Hibernate performance - YouTube]]
 +  * [[https://vladmihalcea.com/hibernate-performance-tuning-tips/|Hibernate performance tuning tips - Vlad Mihalcea]]
 +  * [[https://vladmihalcea.com/courses/high-performance-java-persistence-mach-2/|High-Performance Java Persistence – Mach 2 - Vlad Mihalcea]]
 +  * [[https://www.baeldung.com/hibernate-query-plan-cache|Hibernate Query Plan Cache | Baeldung]]
 +  * [[https://dzone.com/articles/best-performance-practices-for-hibernate-5-and-spr-1|Best Performance Practices for Hibernate 5 and Spring Boot 2 (Part 3) - DZone Java]]
java/hibernate/performance.txt · 마지막으로 수정됨: 2024/03/04 12:47 저자 kwon37xi