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)

PPTX
MicroProfile: A Quest for a Lightweight and Modern Enterprise Java Platform
Mike Croft
 
PDF
How to use the new Domino Query Language
Tim Davis
 
KEY
DjangoCon 2010 Scaling Disqus
zeeg
 
PPTX
Performance & Scalability Improvements in Perforce
Perforce
 
PPTX
Orchestrating Docker with Terraform and Consul by Mitchell Hashimoto
Docker, Inc.
 
PDF
Fosdem10
wremes
 
PPTX
Expand data analysis tool at scale with Zeppelin
DataWorks Summit
 
PPTX
Scaling asp.net websites to millions of users
oazabir
 
PDF
High Performance Hibernate JavaZone 2016
Vlad Mihalcea
 
PDF
High-Performance JDBC Voxxed Bucharest 2016
Vlad Mihalcea
 
PDF
GraphConnect 2014 SF: From Zero to Graph in 120: Scale
Neo4j
 
PPTX
Migration to ClickHouse. Practical guide, by Alexander Zaitsev
Altinity Ltd
 
PDF
Load Data Fast!
Karwin Software Solutions LLC
 
PDF
What is the State of my Kafka Streams Application? Unleashing Metrics. | Neil...
HostedbyConfluent
 
PPTX
App fabric introduction
Dennis van der Stelt
 
PPTX
Orms vs Micro-ORMs
David Paquette
 
PDF
Advanced Cassandra
DataStax Academy
 
PDF
ソーシャルアプリ向けシステム監視運用の勘所
Tatsuro Hisamori
 
PPTX
Dealing with and learning from the sandbox
Elaine Van Bergen
 
PPTX
Dealing with and learning from the sandbox
Elaine Van Bergen
 
MicroProfile: A Quest for a Lightweight and Modern Enterprise Java Platform
Mike Croft
 
How to use the new Domino Query Language
Tim Davis
 
DjangoCon 2010 Scaling Disqus
zeeg
 
Performance & Scalability Improvements in Perforce
Perforce
 
Orchestrating Docker with Terraform and Consul by Mitchell Hashimoto
Docker, Inc.
 
Fosdem10
wremes
 
Expand data analysis tool at scale with Zeppelin
DataWorks Summit
 
Scaling asp.net websites to millions of users
oazabir
 
High Performance Hibernate JavaZone 2016
Vlad Mihalcea
 
High-Performance JDBC Voxxed Bucharest 2016
Vlad Mihalcea
 
GraphConnect 2014 SF: From Zero to Graph in 120: Scale
Neo4j
 
Migration to ClickHouse. Practical guide, by Alexander Zaitsev
Altinity Ltd
 
What is the State of my Kafka Streams Application? Unleashing Metrics. | Neil...
HostedbyConfluent
 
App fabric introduction
Dennis van der Stelt
 
Orms vs Micro-ORMs
David Paquette
 
Advanced Cassandra
DataStax Academy
 
ソーシャルアプリ向けシステム監視運用の勘所
Tatsuro Hisamori
 
Dealing with and learning from the sandbox
Elaine Van Bergen
 
Dealing with and learning from the sandbox
Elaine Van Bergen
 
Ad

Recently uploaded (20)

PDF
intro_to_cpp_namespace_robotics_corner.pdf
MohamedSaied877003
 
PDF
Why is partnering with a SaaS development company crucial for enterprise succ...
Nextbrain Technologies
 
PDF
How to Hire AI Developers_ Step-by-Step Guide in 2025.pdf
DianApps Technologies
 
PDF
AI Prompts Cheat Code prompt engineering
Avijit Kumar Roy
 
PDF
TheFutureIsDynamic-BoxLang witch Luis Majano.pdf
Ortus Solutions, Corp
 
PPTX
Transforming Insights: How Generative AI is Revolutionizing Data Analytics
LetsAI Solutions
 
PPTX
Foundations of Marketo Engage - Powering Campaigns with Marketo Personalization
bbedford2
 
PPTX
Milwaukee Marketo User Group - Summer Road Trip: Mapping and Personalizing Yo...
bbedford2
 
PPTX
Library_Management_System_PPT111111.pptx
nmtnissancrm
 
PPTX
Prompt Like a Pro. Leveraging Salesforce Data to Power AI Workflows.pptx
Dele Amefo
 
PDF
Technical-Careers-Roadmap-in-Software-Market.pdf
Hussein Ali
 
PDF
[Solution] Why Choose the VeryPDF DRM Protector Custom-Built Solution for You...
Lingwen1998
 
PDF
Salesforce Experience Cloud Consultant.pdf
VALiNTRY360
 
PPTX
Build a Custom Agent for Agentic Testing.pptx
klpathrudu
 
PPTX
iaas vs paas vs saas :choosing your cloud strategy
CloudlayaTechnology
 
PPTX
AEM User Group: India Chapter Kickoff Meeting
jennaf3
 
PDF
Wondershare PDFelement Pro Crack for MacOS New Version Latest 2025
bashirkhan333g
 
PDF
Generic or Specific? Making sensible software design decisions
Bert Jan Schrijver
 
PPTX
prodad heroglyph crack 2.0.214.2 Full Free Download
cracked shares
 
PPTX
Smart Doctor Appointment Booking option in odoo.pptx
AxisTechnolabs
 
intro_to_cpp_namespace_robotics_corner.pdf
MohamedSaied877003
 
Why is partnering with a SaaS development company crucial for enterprise succ...
Nextbrain Technologies
 
How to Hire AI Developers_ Step-by-Step Guide in 2025.pdf
DianApps Technologies
 
AI Prompts Cheat Code prompt engineering
Avijit Kumar Roy
 
TheFutureIsDynamic-BoxLang witch Luis Majano.pdf
Ortus Solutions, Corp
 
Transforming Insights: How Generative AI is Revolutionizing Data Analytics
LetsAI Solutions
 
Foundations of Marketo Engage - Powering Campaigns with Marketo Personalization
bbedford2
 
Milwaukee Marketo User Group - Summer Road Trip: Mapping and Personalizing Yo...
bbedford2
 
Library_Management_System_PPT111111.pptx
nmtnissancrm
 
Prompt Like a Pro. Leveraging Salesforce Data to Power AI Workflows.pptx
Dele Amefo
 
Technical-Careers-Roadmap-in-Software-Market.pdf
Hussein Ali
 
[Solution] Why Choose the VeryPDF DRM Protector Custom-Built Solution for You...
Lingwen1998
 
Salesforce Experience Cloud Consultant.pdf
VALiNTRY360
 
Build a Custom Agent for Agentic Testing.pptx
klpathrudu
 
iaas vs paas vs saas :choosing your cloud strategy
CloudlayaTechnology
 
AEM User Group: India Chapter Kickoff Meeting
jennaf3
 
Wondershare PDFelement Pro Crack for MacOS New Version Latest 2025
bashirkhan333g
 
Generic or Specific? Making sensible software design decisions
Bert Jan Schrijver
 
prodad heroglyph crack 2.0.214.2 Full Free Download
cracked shares
 
Smart Doctor Appointment Booking option in odoo.pptx
AxisTechnolabs
 
Ad

High-Performance Hibernate Devoxx France 2016