SlideShare a Scribd company logo
#DevoxxFR
#DevoxxFR
• Hibernate Developer Advocate
• vladmihalcea.com
• @vlad_mihalcea
#DevoxxFR
“More than half of application
performance bottlenecks originate
in the database”
AppDynamics - http://www.appdynamics.com/database/
#DevoxxFR
• Connection acquisition time
• Data access logic (e.g. entity state transitions)
• Statements submission time
• Statements execution time
• Result set fetching time
• Idle time prior to releasing the database connection
𝑇 = 𝑡 𝑎𝑐𝑞 + 𝑡 𝑑𝑎𝑙 + 𝑡 𝑟𝑒𝑞 + 𝑡 𝑒𝑥𝑒𝑐 + 𝑡 𝑟𝑒𝑠 + 𝑡𝑖𝑑𝑙𝑒
#DevoxxFR
• Connection providers
• Identifier generators
• Relationships
• Batching
• Fetching
• Caching
#DevoxxFR
#DevoxxFR
𝑇 = 𝑡 𝑎𝑐𝑞 + 𝑡 𝑑𝑎𝑙 + 𝑡 𝑟𝑒𝑞 + 𝑡 𝑒𝑥𝑒𝑐 + 𝑡 𝑟𝑒𝑠 + 𝑡𝑖𝑑𝑙𝑒
#DevoxxFR
• Connections acquired lazily
• The shorter the transaction lifespan, the higher the transaction
throughput
#DevoxxFR
#DevoxxFR
10 50 100 500 1000 5000 10000
0
200
400
600
800
1000
1200
1400
Statement count
Time(ms)
After statement After transaction
#DevoxxFR
<property name="hibernate.connection.release_mode" value="after_transaction"/>
• For JTA (e.g. Java EE), try this setting:
#DevoxxFR
• AUTO (IDENTITY or SEQUENCE)
• IDENTITY
• SEQUENCE
• TABLE
𝑇 = 𝑡 𝑎𝑐𝑞 + 𝑡 𝑑𝑎𝑙 + 𝑡 𝑟𝑒𝑞 + 𝑡 𝑒𝑥𝑒𝑐 + 𝑡 𝑟𝑒𝑠 + 𝑡𝑖𝑑𝑙𝑒
#DevoxxFR
• Default for SQL Server and MySQL when using AUTO
• Disables JDBC batch inserts
#DevoxxFR
• Default for Oracle and PostgreSQL when using AUTO
• May use roundtrip optimizers: hi/lo, pooled, pooled-lo
• Hibernate 5 uses the enhanced sequence generator by default
<property name="hibernate.id.new_generator_mappings" value="true"/>
#DevoxxFR
1 5 10 50
0
0.05
0.1
0.15
0.2
0.25
0.3
0.35
0.4
0.45
Sequence increment size
Time(ms)
#DevoxxFR
• Uses row-level locks and a separate transaction/connection
• May use roundtrip optimizers: hi/lo, pooled, pooled-lo
• Hibernate 5 uses the enhanced table generator by default
<property name="hibernate.id.new_generator_mappings" value="true"/>
#DevoxxFR
1 5 10 50
0
0.5
1
1.5
2
2.5
3
Table increment size
Time(ms)
#DevoxxFR
• Identity makes no use of batch inserts
• Table generator using an increment size of 100
#DevoxxFR
1 2 4 8 16
0
500
1000
1500
2000
2500
Thread count
Time(ms)
Identity Table
#DevoxxFR
• Both generators use an increment size of 100
1 2 4 8 16
0
200
400
600
800
1000
1200
Thread count
Time(ms)
Sequence Table
#DevoxxFR
𝑇 = 𝑡 𝑎𝑐𝑞 + 𝑡 𝑑𝑎𝑙 + 𝑡 𝑟𝑒𝑞 + 𝑡 𝑒𝑥𝑒𝑐 + 𝑡 𝑟𝑒𝑠 + 𝑡𝑖𝑑𝑙𝑒
#DevoxxFR
<property name="hibernate.jdbc.batch_size" value="10"/>
• SessionFactory configuration
• Plan to support Session-level batch size configuration
𝑇 = 𝑡 𝑎𝑐𝑞 + 𝑡 𝑑𝑎𝑙 + 𝑡 𝑟𝑒𝑞 + 𝑡 𝑒𝑥𝑒𝑐 + 𝑡 𝑟𝑒𝑠 + 𝑡𝑖𝑑𝑙𝑒
#DevoxxFR
1 10 20 30 40 50 60 70 80 90 100 1000
0
200
400
600
800
1000
1200
1400
1600
Batch size
Time(ms)
DB_A DB_B DB_C DB_D
#DevoxxFR
1 10 20 30 40 50 60 70 80 90 100 1000
0
100
200
300
400
500
600
700
Batch size
Time(ms)
DB_A DB_B DB_C DB_D
#DevoxxFR
1 10 20 30 40 50 60 70 80 90 100 1000
0
200
400
600
800
1000
1200
Batch size
Time(ms)
DB_A DB_B DB_C DB_D
#DevoxxFR
<property name="hibernate.order_inserts" value="true"/>
<property name="hibernate.order_updates" value="true"/>
• Plan to support delete statement ordering too
#DevoxxFR
<property name="hibernate.jdbc.batch_versioned_data" value="true"/>
• Enabled by default in Hibernate 5
• Disabled in Hibernate 3 and 4, Oracle 8i, 9i, and 10g dialects.
#DevoxxFR
• JDBC fetch size
• JDBC ResultSet size
• DTO vs Entity queries
• Association fetching
𝑇 = 𝑡 𝑎𝑐𝑞 + 𝑡 𝑑𝑎𝑙 + 𝑡 𝑟𝑒𝑞 + 𝑡 𝑒𝑥𝑒𝑐 + 𝑡 𝑟𝑒𝑠 + 𝑡𝑖𝑑𝑙𝑒
#DevoxxFR
• Oracle – Default fetch size is 10
• SQL Server – Adaptive buffering
• PostgreSQL, MySQL – Fetch the whole ResultSet at once
• SessionFactory setting:
<property name="hibernate.jdbc.fetch_size" value="100"/>
#DevoxxFR
• Query-level fetch size setting
List<PostCommentSummary> summaries = entityManager.createQuery(
"select new PostCommentSummary( " +
" p.id, p.title, c.review ) " +
"from PostComment c " +
"join c.post p")
.setHint(QueryHints.HINT_FETCH_SIZE, fetchSize)
.getResultList();
#DevoxxFR
1 10 100 1000 10000
0
100
200
300
400
500
600
Fetch size
Time(ms)
DB_A DB_B DB_C DB_D
#DevoxxFR
• Hibernate SQL-level limiting (works for native queries too!)
List<PostCommentSummary> summaries = entityManager.createQuery(
"select new PostCommentSummary( " +
" p.id, p.title, c.review ) " +
"from PostComment c " +
"join c.post p")
.setFirstResult(pageStart)
.setMaxResults(pageSize)
.getResultList();
#DevoxxFR
• 100k Post(s) and + 1M PostComment(s) vs 100 entries
Fetch all Fetch limit
0
500
1000
1500
2000
2500
3000
3500
4000
4500
5000
Time(ms)
DB_A DB_B DB_C DB_D
#DevoxxFR
SELECT *
FROM post_comment pc
INNER JOIN post p ON p.id = pc.post_id
INNER JOIN post_details pd ON p.id = pd.id
SELECT pc.version
FROM post_comment pc
INNER JOIN post p ON p.id = pc.post_id
INNER JOIN post_details pd ON p.id = pd.id
• Selecting all columns vs selecting a custom projection
#DevoxxFR
• 100 Post(s), 100 PostDetail(s) , and 1000 PostComment(s)
All columns Custom projection
0
5
10
15
20
25
30
Time(ms)
DB_A DB_B DB_C DB_D
#DevoxxFR
• Read-only views
• Tree structures (Recursive CTE)
• Paginated Tables
• Analytics (Window functions)
#DevoxxFR
• Writing data
• Web flows / Multi-request logical transactions
• Application-level repeatable reads
• Detached entities / PersistenceContextType.EXTENDED
• Optimistic concurrency control (e.g. version, dirty properties)
#DevoxxFR
#DevoxxFR
“You can turn a Lazy into an
Eager, but you cannot turn an
Eager into a Lazy”
#DevoxxFR
• Default to FetchType.LAZY
• Fetch directive in JPQL/Criteria API queries
• Entity graphs / @FetchProfile
• LazyInitializationException
#DevoxxFR
#DevoxxFR
<property name="hibernate.enable_lazy_load_no_trans" value="true"/>
• “Band aid” for LazyInitializationException
• One temporary Session/Connection for every lazily fetched association
#DevoxxFR
𝑇 = 𝑡 𝑎𝑐𝑞 + 𝑡 𝑑𝑎𝑙 + 𝑡 𝑟𝑒𝑞 + 𝑡 𝑒𝑥𝑒𝑐 + 𝑡 𝑟𝑒𝑠 + 𝑡𝑖𝑑𝑙𝑒
#DevoxxFR
#DevoxxFR
“There are only two hard things in
Computer Science: cache
invalidation and naming things.”
Phil Karlton
#DevoxxFR
#DevoxxFR
• Complement entity caching
• Store only entity identifiers
• Read-Through
• Invalidation-based (Consistency over Performance)
#DevoxxFR
#DevoxxFR
https://leanpub.com/high-performance-java-persistence
𝑇 = 𝑡 𝑎𝑐𝑞 + 𝑡 𝑑𝑎𝑙 + 𝑡 𝑟𝑒𝑞 + 𝑡 𝑒𝑥𝑒𝑐 + 𝑡 𝑟𝑒𝑠 + 𝑡𝑖𝑑𝑙𝑒

More Related Content

What's hot (20)

PDF
Custom DevOps Monitoring System in MelOn (with InfluxDB + Telegraf + Grafana)
Seungmin Yu
 
PPT
Cassandra Data Model
ebenhewitt
 
PPTX
Accelerating query processing with materialized views in Apache Hive
DataWorks Summit
 
PDF
JavaScript Basics and Best Practices - CC FE & UX
JWORKS powered by Ordina
 
PDF
MySQL Advanced Administrator 2021 - 네오클로바
NeoClova
 
PPTX
Hibernate ppt
Aneega
 
PDF
Delta: Building Merge on Read
Databricks
 
PDF
MySQL 8.0 Optimizer Guide
Morgan Tocker
 
PDF
[오픈소스컨설팅] 스카우터 사용자 가이드 2020
Ji-Woong Choi
 
PPTX
Introduction to Spring Boot
Purbarun Chakrabarti
 
PPTX
Spring Boot Tutorial
Naphachara Rattanawilai
 
PPTX
Supporting Apache HBase : Troubleshooting and Supportability Improvements
DataWorks Summit
 
PDF
MariaDB: in-depth (hands on training in Seoul)
Colin Charles
 
PDF
Amazon RDS for PostgreSQLのインスタンス(DB)作成手順
Insight Technology, Inc.
 
PDF
GET and POST in PHP
Vineet Kumar Saini
 
PDF
MySQL/MariaDB Proxy Software Test
I Goo Lee
 
PDF
Efficient Data Storage for Analytics with Parquet 2.0 - Hadoop Summit 2014
Julien Le Dem
 
PDF
Naver속도의, 속도에 의한, 속도를 위한 몽고DB (네이버 컨텐츠검색과 몽고DB) [Naver]
MongoDB
 
ODP
HTML5
Hatem Mahmoud
 
PDF
Monitoring Oracle Database Instances with Zabbix
Gerger
 
Custom DevOps Monitoring System in MelOn (with InfluxDB + Telegraf + Grafana)
Seungmin Yu
 
Cassandra Data Model
ebenhewitt
 
Accelerating query processing with materialized views in Apache Hive
DataWorks Summit
 
JavaScript Basics and Best Practices - CC FE & UX
JWORKS powered by Ordina
 
MySQL Advanced Administrator 2021 - 네오클로바
NeoClova
 
Hibernate ppt
Aneega
 
Delta: Building Merge on Read
Databricks
 
MySQL 8.0 Optimizer Guide
Morgan Tocker
 
[오픈소스컨설팅] 스카우터 사용자 가이드 2020
Ji-Woong Choi
 
Introduction to Spring Boot
Purbarun Chakrabarti
 
Spring Boot Tutorial
Naphachara Rattanawilai
 
Supporting Apache HBase : Troubleshooting and Supportability Improvements
DataWorks Summit
 
MariaDB: in-depth (hands on training in Seoul)
Colin Charles
 
Amazon RDS for PostgreSQLのインスタンス(DB)作成手順
Insight Technology, Inc.
 
GET and POST in PHP
Vineet Kumar Saini
 
MySQL/MariaDB Proxy Software Test
I Goo Lee
 
Efficient Data Storage for Analytics with Parquet 2.0 - Hadoop Summit 2014
Julien Le Dem
 
Naver속도의, 속도에 의한, 속도를 위한 몽고DB (네이버 컨텐츠검색과 몽고DB) [Naver]
MongoDB
 
Monitoring Oracle Database Instances with Zabbix
Gerger
 

Similar to High-Performance Hibernate Devoxx France 2016 (20)

PDF
High Performance Hibernate JavaZone 2016
Vlad Mihalcea
 
PPT
Hibernate Session 1
b_kathir
 
PDF
Hibernate performance tuning
Igor Dmitriev
 
PPTX
Hibernate
Prashant Kalkar
 
PPTX
Hibernate tutorial
Mumbai Academisc
 
PPT
Hibernate jj
Joe Jacob
 
PPTX
Hibernate in Nutshell
Onkar Deshpande
 
PDF
High-Performance Hibernate - JDK.io 2018
Vlad Mihalcea
 
PDF
Effiziente Datenpersistierung mit JPA 2.1 und Hibernate
Thorben Janssen
 
PPTX
Effiziente persistierung
Thorben Janssen
 
PDF
JPA 2.1 performance tuning tips
osa_ora
 
KEY
Hibernate Performance Tuning (JEEConf 2012)
Sander Mak (@Sander_Mak)
 
PPTX
Apache phoenix
Osama Hussein
 
PPTX
Евгений Хыст "Application performance database related problems"
Anna Shymchenko
 
PPT
Hibernate for Beginners
Ramesh Kumar
 
PDF
BATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASE
Ortus Solutions, Corp
 
DOC
To Study The Tips Tricks Guidelines Related To Performance Tuning For N Hib...
Shahzad
 
PDF
Hibernate notesforprofessionals
Right
 
High Performance Hibernate JavaZone 2016
Vlad Mihalcea
 
Hibernate Session 1
b_kathir
 
Hibernate performance tuning
Igor Dmitriev
 
Hibernate
Prashant Kalkar
 
Hibernate tutorial
Mumbai Academisc
 
Hibernate jj
Joe Jacob
 
Hibernate in Nutshell
Onkar Deshpande
 
High-Performance Hibernate - JDK.io 2018
Vlad Mihalcea
 
Effiziente Datenpersistierung mit JPA 2.1 und Hibernate
Thorben Janssen
 
Effiziente persistierung
Thorben Janssen
 
JPA 2.1 performance tuning tips
osa_ora
 
Hibernate Performance Tuning (JEEConf 2012)
Sander Mak (@Sander_Mak)
 
Apache phoenix
Osama Hussein
 
Евгений Хыст "Application performance database related problems"
Anna Shymchenko
 
Hibernate for Beginners
Ramesh Kumar
 
BATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASE
Ortus Solutions, Corp
 
To Study The Tips Tricks Guidelines Related To Performance Tuning For N Hib...
Shahzad
 
Hibernate notesforprofessionals
Right
 
Ad

Recently uploaded (20)

PDF
Generic or Specific? Making sensible software design decisions
Bert Jan Schrijver
 
PDF
UITP Summit Meep Pitch may 2025 MaaS Rebooted
campoamor1
 
PDF
Wondershare PDFelement Pro Crack for MacOS New Version Latest 2025
bashirkhan333g
 
PPTX
Help for Correlations in IBM SPSS Statistics.pptx
Version 1 Analytics
 
PPTX
Empowering Asian Contributions: The Rise of Regional User Groups in Open Sour...
Shane Coughlan
 
PDF
Simplify React app login with asgardeo-sdk
vaibhav289687
 
PDF
ERP Consulting Services and Solutions by Contetra Pvt Ltd
jayjani123
 
PPTX
OpenChain @ OSS NA - In From the Cold: Open Source as Part of Mainstream Soft...
Shane Coughlan
 
PDF
Dipole Tech Innovations – Global IT Solutions for Business Growth
dipoletechi3
 
PDF
Open Chain Q2 Steering Committee Meeting - 2025-06-25
Shane Coughlan
 
PDF
TheFutureIsDynamic-BoxLang witch Luis Majano.pdf
Ortus Solutions, Corp
 
PDF
[Solution] Why Choose the VeryPDF DRM Protector Custom-Built Solution for You...
Lingwen1998
 
PDF
IDM Crack with Internet Download Manager 6.42 Build 43 with Patch Latest 2025
bashirkhan333g
 
PPTX
ChiSquare Procedure in IBM SPSS Statistics Version 31.pptx
Version 1 Analytics
 
PDF
Add Background Images to Charts in IBM SPSS Statistics Version 31.pdf
Version 1 Analytics
 
PDF
Top Agile Project Management Tools for Teams in 2025
Orangescrum
 
PPTX
Finding Your License Details in IBM SPSS Statistics Version 31.pptx
Version 1 Analytics
 
PDF
SciPy 2025 - Packaging a Scientific Python Project
Henry Schreiner
 
PPTX
Homogeneity of Variance Test Options IBM SPSS Statistics Version 31.pptx
Version 1 Analytics
 
PDF
SAP Firmaya İade ABAB Kodları - ABAB ile yazılmıl hazır kod örneği
Salih Küçük
 
Generic or Specific? Making sensible software design decisions
Bert Jan Schrijver
 
UITP Summit Meep Pitch may 2025 MaaS Rebooted
campoamor1
 
Wondershare PDFelement Pro Crack for MacOS New Version Latest 2025
bashirkhan333g
 
Help for Correlations in IBM SPSS Statistics.pptx
Version 1 Analytics
 
Empowering Asian Contributions: The Rise of Regional User Groups in Open Sour...
Shane Coughlan
 
Simplify React app login with asgardeo-sdk
vaibhav289687
 
ERP Consulting Services and Solutions by Contetra Pvt Ltd
jayjani123
 
OpenChain @ OSS NA - In From the Cold: Open Source as Part of Mainstream Soft...
Shane Coughlan
 
Dipole Tech Innovations – Global IT Solutions for Business Growth
dipoletechi3
 
Open Chain Q2 Steering Committee Meeting - 2025-06-25
Shane Coughlan
 
TheFutureIsDynamic-BoxLang witch Luis Majano.pdf
Ortus Solutions, Corp
 
[Solution] Why Choose the VeryPDF DRM Protector Custom-Built Solution for You...
Lingwen1998
 
IDM Crack with Internet Download Manager 6.42 Build 43 with Patch Latest 2025
bashirkhan333g
 
ChiSquare Procedure in IBM SPSS Statistics Version 31.pptx
Version 1 Analytics
 
Add Background Images to Charts in IBM SPSS Statistics Version 31.pdf
Version 1 Analytics
 
Top Agile Project Management Tools for Teams in 2025
Orangescrum
 
Finding Your License Details in IBM SPSS Statistics Version 31.pptx
Version 1 Analytics
 
SciPy 2025 - Packaging a Scientific Python Project
Henry Schreiner
 
Homogeneity of Variance Test Options IBM SPSS Statistics Version 31.pptx
Version 1 Analytics
 
SAP Firmaya İade ABAB Kodları - ABAB ile yazılmıl hazır kod örneği
Salih Küçük
 
Ad

High-Performance Hibernate Devoxx France 2016