SlideShare a Scribd company logo
ORM and Distributed Caching



                     Alexey Ragozin
         alexey.ragozin@gmail.com
                          May 2012
ORM cache hierarchy

                     Session
   Level 1


       Query cache              Entry cache

   Level 2




                     Database
ORM cache hierarchy

                      Session
                                POJO
   Level 1


       Query cache               Entry cache
              Sets of PK                  Entities
   Level 2




                      Database
Second level cache

Query cache
 Query -> Result set (list of entry references)
Entity cache
 PK (entry reference) -> Entity data
Makes query cache useful
Helps with “N+1 select” problem
Actively used for lazy loading of entities
Consistency problem

Stale data in entity cache = big problem
Single process application
 Locking, to prevent concurrent updates
 Write through – modify DB and cache together
Distributed application
1. JTA transaction manager (add cache to Tx)
2. Use distributed locks for concurrency control
Solving Query Problem

Caching queries
 Exact query match may be infrequent
 Invalidation is messy

Why not execute quires in cache?
 Execute query in entity cache
 No invalidation problem
 Coherence, GemFire, Hazelcast has index support
Queries in Entity Cache

Pro
 DB is not involved in query processing
 Fallback to DB for complex quries
 Still using old good (or bad) JPQL

Cons
 ALL entities should be loaded in cache
 Only simple selects, no join queries are supported
    though link traversing works as usual
What is Next?

 Coherence cache is durable
 Why update DB synchronously?

Write behind for ORM
PRO

 reducing transaction execution time
 removing DB from critical path
CON

 Coherence does not honor transaction boundaries
 DB is out of sync, no way for execution complex JPQL
Few More Interesting Stuff


 Works with TopLink Grid
 Real transaction support
 Durability via distributed disk log
HIBERNATE         OGM
 JPQL for NoSQL (data grid included)
 Lucene (Hibernate Search) support
Thank you
http://aragozin.blogspot.com




                                Alexey Ragozin
                    alexey.ragozin@gmail.com

More Related Content

What's hot (20)

PDF
Scalability, Availability & Stability Patterns
Jonas Bonér
 
PPTX
1. beyond mission critical virtualizing big data and hadoop
Chiou-Nan Chen
 
PDF
Distributed Caching Essential Lessons (Ts 1402)
Yury Kaliaha
 
PDF
Distributed Caching Using the JCACHE API and ehcache, Including a Case Study ...
elliando dias
 
PPTX
From cache to in-memory data grid. Introduction to Hazelcast.
Taras Matyashovsky
 
PPTX
MongoDB San Francisco 2013: Storing eBay's Media Metadata on MongoDB present...
MongoDB
 
PDF
Scaling Out Tier Based Applications
Yury Kaliaha
 
PDF
An Elastic Metadata Store for eBay’s Media Platform
MongoDB
 
PDF
Thousands of Threads and Blocking I/O
George Cao
 
PPTX
New life inside monolithic application
Taras Matyashovsky
 
PDF
Web session replication with Hazelcast
Emrah Kocaman
 
PDF
The Google Chubby lock service for loosely-coupled distributed systems
Romain Jacotin
 
PDF
Architecture of a Next-Generation Parallel File System
Great Wide Open
 
PDF
Architecture of the Upcoming OrangeFS v3 Distributed Parallel File System
All Things Open
 
PPT
HTTP Session Replication with Oracle Coherence, GlassFish, WebLogic
Oracle
 
PDF
A Journey from Oracle to PostgreSQL
EDB
 
PDF
Geographically Distributed PostgreSQL
mason_s
 
PPTX
Infinispan @ Red Hat Forum 2013
Jaehong Cheon
 
PDF
인메모리 클러스터링 아키텍처
Jaehong Cheon
 
PDF
Caching technology comparison
Rohit Kelapure
 
Scalability, Availability & Stability Patterns
Jonas Bonér
 
1. beyond mission critical virtualizing big data and hadoop
Chiou-Nan Chen
 
Distributed Caching Essential Lessons (Ts 1402)
Yury Kaliaha
 
Distributed Caching Using the JCACHE API and ehcache, Including a Case Study ...
elliando dias
 
From cache to in-memory data grid. Introduction to Hazelcast.
Taras Matyashovsky
 
MongoDB San Francisco 2013: Storing eBay's Media Metadata on MongoDB present...
MongoDB
 
Scaling Out Tier Based Applications
Yury Kaliaha
 
An Elastic Metadata Store for eBay’s Media Platform
MongoDB
 
Thousands of Threads and Blocking I/O
George Cao
 
New life inside monolithic application
Taras Matyashovsky
 
Web session replication with Hazelcast
Emrah Kocaman
 
The Google Chubby lock service for loosely-coupled distributed systems
Romain Jacotin
 
Architecture of a Next-Generation Parallel File System
Great Wide Open
 
Architecture of the Upcoming OrangeFS v3 Distributed Parallel File System
All Things Open
 
HTTP Session Replication with Oracle Coherence, GlassFish, WebLogic
Oracle
 
A Journey from Oracle to PostgreSQL
EDB
 
Geographically Distributed PostgreSQL
mason_s
 
Infinispan @ Red Hat Forum 2013
Jaehong Cheon
 
인메모리 클러스터링 아키텍처
Jaehong Cheon
 
Caching technology comparison
Rohit Kelapure
 

Similar to ORM and distributed caching (20)

PDF
Orcale Presentation
Sanjeev Kulkarni
 
PDF
Hibernate caching
Alex Verdyan
 
PPT
Hibernate caching
bsudy
 
PPT
Hibernate jj
Joe Jacob
 
DOC
Advanced Hibernate Notes
Kaniska Mandal
 
PDF
Hibernate ORM: Tips, Tricks, and Performance Techniques
Brett Meyer
 
PPT
An Engineer's Intro to Oracle Coherence
Oracle
 
PDF
Initial review of Firebird 3
Mind The Firebird
 
PPT
13 caching latest
thirumuru2012
 
PDF
Hibernate 3
Rajiv Gupta
 
PDF
Scaling Your Cache
Alex Miller
 
PDF
Building and deploying large scale real time news system with my sql and dist...
Tao Cheng
 
PDF
BATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASE
Ortus Solutions, Corp
 
PDF
Cold Hard Cache
Alex Miller
 
PDF
Oracle Diagnostics : Latches and Enqueues
Hemant K Chitale
 
PPTX
Apache ignite as in-memory computing platform
Surinder Mehra
 
PPT
JPA and Coherence with TopLink Grid
James Bayer
 
KEY
Appengine Nljug
Paul Bakker
 
Orcale Presentation
Sanjeev Kulkarni
 
Hibernate caching
Alex Verdyan
 
Hibernate caching
bsudy
 
Hibernate jj
Joe Jacob
 
Advanced Hibernate Notes
Kaniska Mandal
 
Hibernate ORM: Tips, Tricks, and Performance Techniques
Brett Meyer
 
An Engineer's Intro to Oracle Coherence
Oracle
 
Initial review of Firebird 3
Mind The Firebird
 
13 caching latest
thirumuru2012
 
Hibernate 3
Rajiv Gupta
 
Scaling Your Cache
Alex Miller
 
Building and deploying large scale real time news system with my sql and dist...
Tao Cheng
 
BATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASE
Ortus Solutions, Corp
 
Cold Hard Cache
Alex Miller
 
Oracle Diagnostics : Latches and Enqueues
Hemant K Chitale
 
Apache ignite as in-memory computing platform
Surinder Mehra
 
JPA and Coherence with TopLink Grid
James Bayer
 
Appengine Nljug
Paul Bakker
 
Ad

More from aragozin (20)

PDF
Java on Linux for devs and ops
aragozin
 
PDF
I know why your Java is slow
aragozin
 
PPTX
Java profiling Do It Yourself (jug.msk.ru 2016)
aragozin
 
PDF
Java black box profiling JUG.EKB 2016
aragozin
 
PDF
Распределённое нагрузочное тестирование на Java
aragozin
 
PDF
What every Java developer should know about network?
aragozin
 
PPTX
Java profiling Do It Yourself
aragozin
 
PPTX
DIY Java Profiler
aragozin
 
PPTX
Java black box profiling
aragozin
 
PDF
Блеск и нищета распределённых кэшей
aragozin
 
PDF
JIT compilation in modern platforms – challenges and solutions
aragozin
 
PDF
Casual mass parallel computing
aragozin
 
PPTX
Nanocloud cloud scale jvm
aragozin
 
PDF
Java GC tuning and monitoring (by Alexander Ashitkin)
aragozin
 
PDF
Garbage collection in JVM
aragozin
 
PDF
Virtualizing Java in Java (jug.ru)
aragozin
 
PDF
Filtering 100M objects in Coherence cache. What can go wrong?
aragozin
 
PDF
Cборка мусора в Java без пауз (HighLoad++ 2013)
aragozin
 
PDF
JIT-компиляция в виртуальной машине Java (HighLoad++ 2013)
aragozin
 
PDF
Performance Test Driven Development (CEE SERC 2013 Moscow)
aragozin
 
Java on Linux for devs and ops
aragozin
 
I know why your Java is slow
aragozin
 
Java profiling Do It Yourself (jug.msk.ru 2016)
aragozin
 
Java black box profiling JUG.EKB 2016
aragozin
 
Распределённое нагрузочное тестирование на Java
aragozin
 
What every Java developer should know about network?
aragozin
 
Java profiling Do It Yourself
aragozin
 
DIY Java Profiler
aragozin
 
Java black box profiling
aragozin
 
Блеск и нищета распределённых кэшей
aragozin
 
JIT compilation in modern platforms – challenges and solutions
aragozin
 
Casual mass parallel computing
aragozin
 
Nanocloud cloud scale jvm
aragozin
 
Java GC tuning and monitoring (by Alexander Ashitkin)
aragozin
 
Garbage collection in JVM
aragozin
 
Virtualizing Java in Java (jug.ru)
aragozin
 
Filtering 100M objects in Coherence cache. What can go wrong?
aragozin
 
Cборка мусора в Java без пауз (HighLoad++ 2013)
aragozin
 
JIT-компиляция в виртуальной машине Java (HighLoad++ 2013)
aragozin
 
Performance Test Driven Development (CEE SERC 2013 Moscow)
aragozin
 
Ad

Recently uploaded (20)

PDF
POV_ Why Enterprises Need to Find Value in ZERO.pdf
darshakparmar
 
PDF
"AI Transformation: Directions and Challenges", Pavlo Shaternik
Fwdays
 
PDF
Fl Studio 24.2.2 Build 4597 Crack for Windows Free Download 2025
faizk77g
 
PPTX
AUTOMATION AND ROBOTICS IN PHARMA INDUSTRY.pptx
sameeraaabegumm
 
PDF
"Beyond English: Navigating the Challenges of Building a Ukrainian-language R...
Fwdays
 
PDF
[Newgen] NewgenONE Marvin Brochure 1.pdf
darshakparmar
 
PDF
Chris Elwell Woburn, MA - Passionate About IT Innovation
Chris Elwell Woburn, MA
 
PDF
Newgen Beyond Frankenstein_Build vs Buy_Digital_version.pdf
darshakparmar
 
PDF
The Rise of AI and IoT in Mobile App Tech.pdf
IMG Global Infotech
 
PDF
Blockchain Transactions Explained For Everyone
CIFDAQ
 
PPTX
COMPARISON OF RASTER ANALYSIS TOOLS OF QGIS AND ARCGIS
Sharanya Sarkar
 
PDF
Achieving Consistent and Reliable AI Code Generation - Medusa AI
medusaaico
 
PPTX
WooCommerce Workshop: Bring Your Laptop
Laura Hartwig
 
PDF
Jak MŚP w Europie Środkowo-Wschodniej odnajdują się w świecie AI
dominikamizerska1
 
PDF
From Code to Challenge: Crafting Skill-Based Games That Engage and Reward
aiyshauae
 
PDF
CIFDAQ Market Insights for July 7th 2025
CIFDAQ
 
PDF
How Startups Are Growing Faster with App Developers in Australia.pdf
India App Developer
 
PPTX
OpenID AuthZEN - Analyst Briefing July 2025
David Brossard
 
PDF
HubSpot Main Hub: A Unified Growth Platform
Jaswinder Singh
 
PPTX
Building Search Using OpenSearch: Limitations and Workarounds
Sease
 
POV_ Why Enterprises Need to Find Value in ZERO.pdf
darshakparmar
 
"AI Transformation: Directions and Challenges", Pavlo Shaternik
Fwdays
 
Fl Studio 24.2.2 Build 4597 Crack for Windows Free Download 2025
faizk77g
 
AUTOMATION AND ROBOTICS IN PHARMA INDUSTRY.pptx
sameeraaabegumm
 
"Beyond English: Navigating the Challenges of Building a Ukrainian-language R...
Fwdays
 
[Newgen] NewgenONE Marvin Brochure 1.pdf
darshakparmar
 
Chris Elwell Woburn, MA - Passionate About IT Innovation
Chris Elwell Woburn, MA
 
Newgen Beyond Frankenstein_Build vs Buy_Digital_version.pdf
darshakparmar
 
The Rise of AI and IoT in Mobile App Tech.pdf
IMG Global Infotech
 
Blockchain Transactions Explained For Everyone
CIFDAQ
 
COMPARISON OF RASTER ANALYSIS TOOLS OF QGIS AND ARCGIS
Sharanya Sarkar
 
Achieving Consistent and Reliable AI Code Generation - Medusa AI
medusaaico
 
WooCommerce Workshop: Bring Your Laptop
Laura Hartwig
 
Jak MŚP w Europie Środkowo-Wschodniej odnajdują się w świecie AI
dominikamizerska1
 
From Code to Challenge: Crafting Skill-Based Games That Engage and Reward
aiyshauae
 
CIFDAQ Market Insights for July 7th 2025
CIFDAQ
 
How Startups Are Growing Faster with App Developers in Australia.pdf
India App Developer
 
OpenID AuthZEN - Analyst Briefing July 2025
David Brossard
 
HubSpot Main Hub: A Unified Growth Platform
Jaswinder Singh
 
Building Search Using OpenSearch: Limitations and Workarounds
Sease
 

ORM and distributed caching

  • 1. ORM and Distributed Caching Alexey Ragozin [email protected] May 2012
  • 2. ORM cache hierarchy Session Level 1 Query cache Entry cache Level 2 Database
  • 3. ORM cache hierarchy Session POJO Level 1 Query cache Entry cache Sets of PK Entities Level 2 Database
  • 4. Second level cache Query cache  Query -> Result set (list of entry references) Entity cache  PK (entry reference) -> Entity data Makes query cache useful Helps with “N+1 select” problem Actively used for lazy loading of entities
  • 5. Consistency problem Stale data in entity cache = big problem Single process application  Locking, to prevent concurrent updates  Write through – modify DB and cache together Distributed application 1. JTA transaction manager (add cache to Tx) 2. Use distributed locks for concurrency control
  • 6. Solving Query Problem Caching queries  Exact query match may be infrequent  Invalidation is messy Why not execute quires in cache?  Execute query in entity cache  No invalidation problem  Coherence, GemFire, Hazelcast has index support
  • 7. Queries in Entity Cache Pro  DB is not involved in query processing  Fallback to DB for complex quries  Still using old good (or bad) JPQL Cons  ALL entities should be loaded in cache  Only simple selects, no join queries are supported  though link traversing works as usual
  • 8. What is Next?  Coherence cache is durable  Why update DB synchronously? Write behind for ORM PRO  reducing transaction execution time  removing DB from critical path CON  Coherence does not honor transaction boundaries  DB is out of sync, no way for execution complex JPQL
  • 9. Few More Interesting Stuff  Works with TopLink Grid  Real transaction support  Durability via distributed disk log HIBERNATE OGM  JPQL for NoSQL (data grid included)  Lucene (Hibernate Search) support