SlideShare a Scribd company logo
1 of 19
Download to read offline
DATA CACHING
Talk 10
CACHING: WHAT FOR?
• Spatial

optimization: original data is far and slow
to retrieve.	


• Temporal

compute.	


optimization: original data is heavy to

• Concurrency

optimization: many users request
the same data.
CACHE: WHAT?

Client
(CPU, web browser...)

Cache

Main
Repository
(RAM, disk, web, DB...)
LATENCY NUMBERS
!
!
!
!
!
!
!
!
!
!
!
!
!
Send packet CA->Netherlands->CA

150,000,000

https://gist.github.com/jboner/2841832

ns

150

ms
LATENCY NUMBERS
!
!
!
!
!
!
!
!
!
!
!
Disk seek
!
Send packet CA->Netherlands->CA

10,000,000

ns

10

ms!

150,000,000

ns

150

ms

https://gist.github.com/jboner/2841832
LATENCY NUMBERS
!
!
!
!
Main memory reference
!
!
!
!
!
!
Disk seek
!
Send packet CA->Netherlands->CA

100

ns!

10,000,000

ns

10

ms!

150,000,000

ns

150

ms

https://gist.github.com/jboner/2841832
LATENCY NUMBERS
!
!
L2 cache reference
!
Main memory reference
!
!
!
!
!
!
Disk seek
!
Send packet CA->Netherlands->CA

7

ns!

100

ns!

10,000,000

ns

10

ms!

150,000,000

ns

150

ms

https://gist.github.com/jboner/2841832
LATENCY NUMBERS
L1 cache reference
!
L2 cache reference
!
Main memory reference
!
!
!
!
!
!
Disk seek
!
Send packet CA->Netherlands->CA

0.5 ns!
7

ns!

100

ns!

10,000,000

ns

10

ms!

150,000,000

ns

150

ms

https://gist.github.com/jboner/2841832
LATENCY NUMBERS
L1 cache reference
0.5
Branch mispredict
5
L2 cache reference
7
Mutex lock/unlock
25
Main memory reference
100
Compress 1K bytes with Google Snappy
3,000
Send 1K bytes over 1 Gbps network
10,000
Read 4K randomly from SSD
150,000
Read 1 MB sequentially from memory
250,000
Round trip within same datacenter
500,000
Read 1 MB sequentially from SSD
1,000,000
Disk seek
10,000,000
Read 1 MB sequentially from disk
20,000,000
Send packet CA->Netherlands->CA
150,000,000
https://gist.github.com/jboner/2841832

ns!
ns!
ns!
ns!
ns!
ns!
ns
0.01
ns
0.15
ns
0.25
ns
0.5
ns
1
ns
10
ns
20
ns 150

ms!
ms!
ms!
ms!
ms!
ms!
ms!
ms
CACHE COHERENCE

• Cache

data.	


hit: the cache content must be in sync with the original

• Proxy
• DNS

ask to the original source if their data is up-to-date.	


cache provide stale data until expiration.
CACHE EVICTION

• Cache

miss: the cache eventually gets full. What can be
discarded?	

• LRU

(Last Recently Used)	


• LFU

(Least Frequently Used)
WRITE POLICY
•I

changed the data and put it back into the cache.	


• Write-through: the

data is synchronously pushed to the

original source.	


• Write

back: the data is pushed to the source only when it
is requested.

Client

Cache

Main
Repository
CACHE: THE BBOX WAY
Windows

Client

Controllers
BOs
Server
DAOs
Database
CACHE: THE BBOX WAY
Windows
Controllers
BOs
DAOs
Database

Application cache
Query cache
Second level cache
First level cache
DBMS cache
HIBERNATE
FIRST LEVEL CACHE

• Completely
• Is

automatic and not tunable.	


flushed at the session’s end (simplifying: at the
end of the transaction).
HIBERNATE
SECOND LEVEL CACHE
@Entity!
@Indexed!
@Table(name = "BOM_PLACE")!
@Cacheable!
@Cache(usage = CacheConcurrencyStrategy.NONSTRICT_READ_WRITE)!
public class PlaceImpl extends ThingImpl<PlaceImpl, PlaceTO,
PlaceStrategy> implements Place {!
...!

• The

cache survives the sessions.	


• The

cache is held and configured by EhCache.
HIBERNATE
QUERY CACHE
@CacheIt!
@Dao(entity = PlaceImpl.class)!
public interface PlaceImplDao extends GenericDao<PlaceImpl, Long> {!
!
@CacheIt!
List<PlaceTO> findTO();!
!
...!
!
!
!
Criteria c = sessionFactory.getCurrentSession().getCriteria(...);!
c.setCacheable(true);!

Works together with the Second level cache.
BBOX APPLICATION CACHE
/**!
* @author Federico Russo!
*/!
public interface PlaceBO extends ThingBO<Place, PlaceStrategy, PlaceTO> {!

!

!

/**!
* Ritorna tutti i figli di un certo TO.!
*/!
@PreAuthorize("hasRole('ROLE_READ_PLACES') and hasPermission(#parentTO, 'READ')")!
@PostFilter("hasPermission(filterObject, 'READ')")!
@Cacheable(cacheName = "places")!
Collection<PlaceTO> findChildrenTO(PlaceTO parentTO, String strategyClassName);!
/**!
* Rimuove il Component fornito dai magazzini in cui eventualmente sta.!
*/!
@Transactional!
@PreAuthorize("hasRole('ROLE_WRITE_PLACES')")!
@TriggersRemove(removeAll = true, cacheName = "places")!
void removeFromWarehouses(ComponentTO componentTO);!

We’re not using it. We should.
Next talk: Welcome to Java 7

More Related Content

What's hot

HBaseConEast2016: Practical Kerberos with Apache HBase
HBaseConEast2016: Practical Kerberos with Apache HBaseHBaseConEast2016: Practical Kerberos with Apache HBase
HBaseConEast2016: Practical Kerberos with Apache HBaseMichael Stack
 
Testing with Ansible
Testing with AnsibleTesting with Ansible
Testing with AnsibleBas Meijer
 
Jenkins and ansible reference
Jenkins and ansible referenceJenkins and ansible reference
Jenkins and ansible referencelaonap166
 
Network Automation: Ansible 102
Network Automation: Ansible 102Network Automation: Ansible 102
Network Automation: Ansible 102APNIC
 
Getting started with Ansible
Getting started with AnsibleGetting started with Ansible
Getting started with AnsibleIvan Serdyuk
 
Python Deployment with Fabric
Python Deployment with FabricPython Deployment with Fabric
Python Deployment with Fabricandymccurdy
 
Speeding Up The Snail
Speeding Up The SnailSpeeding Up The Snail
Speeding Up The SnailMarcus Deglos
 
Ansible 101 - Presentation at Ansible STL Meetup
Ansible 101 - Presentation at Ansible STL MeetupAnsible 101 - Presentation at Ansible STL Meetup
Ansible 101 - Presentation at Ansible STL MeetupJeff Geerling
 
Ansible + WordPress - WordCamp Toronto 2016
Ansible + WordPress - WordCamp Toronto 2016Ansible + WordPress - WordCamp Toronto 2016
Ansible + WordPress - WordCamp Toronto 2016Alan Lok
 
Using Capifony for Symfony apps deployment (updated)
Using Capifony for Symfony apps deployment (updated)Using Capifony for Symfony apps deployment (updated)
Using Capifony for Symfony apps deployment (updated)Žilvinas Kuusas
 
Getting Started with Ansible
Getting Started with AnsibleGetting Started with Ansible
Getting Started with AnsibleAhmed AbouZaid
 
Managing development environments with Docksal
Managing development environments with DocksalManaging development environments with Docksal
Managing development environments with DocksalVladimir Zdravkovic
 
Debugging webOS applications
Debugging webOS applicationsDebugging webOS applications
Debugging webOS applicationsfpatton
 
Webdevcon Keynote hh-2012-09-18
Webdevcon Keynote hh-2012-09-18Webdevcon Keynote hh-2012-09-18
Webdevcon Keynote hh-2012-09-18Pierre Joye
 
Multi tenant CMSes using php
Multi tenant CMSes using phpMulti tenant CMSes using php
Multi tenant CMSes using phpkae-verens
 
Drupal, varnish, esi - Toulouse November 2
Drupal, varnish, esi - Toulouse November 2Drupal, varnish, esi - Toulouse November 2
Drupal, varnish, esi - Toulouse November 2Marcus Deglos
 
Introduction to ansible
Introduction to ansibleIntroduction to ansible
Introduction to ansibleDharmit Shah
 

What's hot (20)

HBaseConEast2016: Practical Kerberos with Apache HBase
HBaseConEast2016: Practical Kerberos with Apache HBaseHBaseConEast2016: Practical Kerberos with Apache HBase
HBaseConEast2016: Practical Kerberos with Apache HBase
 
Testing with Ansible
Testing with AnsibleTesting with Ansible
Testing with Ansible
 
Ansible 101
Ansible 101Ansible 101
Ansible 101
 
Jenkins and ansible reference
Jenkins and ansible referenceJenkins and ansible reference
Jenkins and ansible reference
 
Network Automation: Ansible 102
Network Automation: Ansible 102Network Automation: Ansible 102
Network Automation: Ansible 102
 
Getting started with Ansible
Getting started with AnsibleGetting started with Ansible
Getting started with Ansible
 
Python Deployment with Fabric
Python Deployment with FabricPython Deployment with Fabric
Python Deployment with Fabric
 
Speeding Up The Snail
Speeding Up The SnailSpeeding Up The Snail
Speeding Up The Snail
 
Ansible 101 - Presentation at Ansible STL Meetup
Ansible 101 - Presentation at Ansible STL MeetupAnsible 101 - Presentation at Ansible STL Meetup
Ansible 101 - Presentation at Ansible STL Meetup
 
Ansible + WordPress - WordCamp Toronto 2016
Ansible + WordPress - WordCamp Toronto 2016Ansible + WordPress - WordCamp Toronto 2016
Ansible + WordPress - WordCamp Toronto 2016
 
Using Capifony for Symfony apps deployment (updated)
Using Capifony for Symfony apps deployment (updated)Using Capifony for Symfony apps deployment (updated)
Using Capifony for Symfony apps deployment (updated)
 
Scaling PHP web apps
Scaling PHP web appsScaling PHP web apps
Scaling PHP web apps
 
Getting Started with Ansible
Getting Started with AnsibleGetting Started with Ansible
Getting Started with Ansible
 
Managing development environments with Docksal
Managing development environments with DocksalManaging development environments with Docksal
Managing development environments with Docksal
 
Debugging webOS applications
Debugging webOS applicationsDebugging webOS applications
Debugging webOS applications
 
Node.js
Node.jsNode.js
Node.js
 
Webdevcon Keynote hh-2012-09-18
Webdevcon Keynote hh-2012-09-18Webdevcon Keynote hh-2012-09-18
Webdevcon Keynote hh-2012-09-18
 
Multi tenant CMSes using php
Multi tenant CMSes using phpMulti tenant CMSes using php
Multi tenant CMSes using php
 
Drupal, varnish, esi - Toulouse November 2
Drupal, varnish, esi - Toulouse November 2Drupal, varnish, esi - Toulouse November 2
Drupal, varnish, esi - Toulouse November 2
 
Introduction to ansible
Introduction to ansibleIntroduction to ansible
Introduction to ansible
 

Similar to 10 Data caching

Globo.com & Varnish
Globo.com & VarnishGlobo.com & Varnish
Globo.com & Varnishlokama
 
EECI 2013 - ExpressionEngine Performance & Optimization - Laying a Solid Foun...
EECI 2013 - ExpressionEngine Performance & Optimization - Laying a Solid Foun...EECI 2013 - ExpressionEngine Performance & Optimization - Laying a Solid Foun...
EECI 2013 - ExpressionEngine Performance & Optimization - Laying a Solid Foun...Nexcess.net LLC
 
Accelerating Rails with edge caching
Accelerating Rails with edge cachingAccelerating Rails with edge caching
Accelerating Rails with edge cachingMichael May
 
Roy foubister (hosting high traffic sites on a tight budget)
Roy foubister (hosting high traffic sites on a tight budget)Roy foubister (hosting high traffic sites on a tight budget)
Roy foubister (hosting high traffic sites on a tight budget)WordCamp Cape Town
 
Caching with Memcached and APC
Caching with Memcached and APCCaching with Memcached and APC
Caching with Memcached and APCBen Ramsey
 
Site Performance - From Pinto to Ferrari
Site Performance - From Pinto to FerrariSite Performance - From Pinto to Ferrari
Site Performance - From Pinto to FerrariJoseph Scott
 
CHI - YAPC NA 2012
CHI - YAPC NA 2012CHI - YAPC NA 2012
CHI - YAPC NA 2012jonswar
 
Large-scale Web Apps @ Pinterest
Large-scale Web Apps @ PinterestLarge-scale Web Apps @ Pinterest
Large-scale Web Apps @ PinterestHBaseCon
 
Maximize your Cache for No Cash
Maximize your Cache for No CashMaximize your Cache for No Cash
Maximize your Cache for No CashYorick Phoenix
 
Tuning Your SharePoint Environment
Tuning Your SharePoint EnvironmentTuning Your SharePoint Environment
Tuning Your SharePoint Environmentvmaximiuk
 
Caching and tuning fun for high scalability
Caching and tuning fun for high scalabilityCaching and tuning fun for high scalability
Caching and tuning fun for high scalabilityWim Godden
 
AWS re:Invent 2016: Streaming ETL for RDS and DynamoDB (DAT315)
AWS re:Invent 2016: Streaming ETL for RDS and DynamoDB (DAT315)AWS re:Invent 2016: Streaming ETL for RDS and DynamoDB (DAT315)
AWS re:Invent 2016: Streaming ETL for RDS and DynamoDB (DAT315)Amazon Web Services
 
High Performance With Java
High Performance With JavaHigh Performance With Java
High Performance With Javamalduarte
 
Scaling Servers and Storage for Film Assets
Scaling Servers and Storage for Film Assets  Scaling Servers and Storage for Film Assets
Scaling Servers and Storage for Film Assets Perforce
 
Hyperbatch (LoteRapido) - Punta Dreamin' 2017
Hyperbatch (LoteRapido) - Punta Dreamin' 2017Hyperbatch (LoteRapido) - Punta Dreamin' 2017
Hyperbatch (LoteRapido) - Punta Dreamin' 2017Daniel Peter
 
Introduction to memcached
Introduction to memcachedIntroduction to memcached
Introduction to memcachedJurriaan Persyn
 
Rails Caching: Secrets From the Edge
Rails Caching: Secrets From the EdgeRails Caching: Secrets From the Edge
Rails Caching: Secrets From the EdgeFastly
 
Rails Caching Secrets from the Edge
Rails Caching Secrets from the EdgeRails Caching Secrets from the Edge
Rails Caching Secrets from the EdgeMichael May
 

Similar to 10 Data caching (20)

Globo.com & Varnish
Globo.com & VarnishGlobo.com & Varnish
Globo.com & Varnish
 
EECI 2013 - ExpressionEngine Performance & Optimization - Laying a Solid Foun...
EECI 2013 - ExpressionEngine Performance & Optimization - Laying a Solid Foun...EECI 2013 - ExpressionEngine Performance & Optimization - Laying a Solid Foun...
EECI 2013 - ExpressionEngine Performance & Optimization - Laying a Solid Foun...
 
Accelerating Rails with edge caching
Accelerating Rails with edge cachingAccelerating Rails with edge caching
Accelerating Rails with edge caching
 
Roy foubister (hosting high traffic sites on a tight budget)
Roy foubister (hosting high traffic sites on a tight budget)Roy foubister (hosting high traffic sites on a tight budget)
Roy foubister (hosting high traffic sites on a tight budget)
 
Top ten-list
Top ten-listTop ten-list
Top ten-list
 
Caching with Memcached and APC
Caching with Memcached and APCCaching with Memcached and APC
Caching with Memcached and APC
 
Site Performance - From Pinto to Ferrari
Site Performance - From Pinto to FerrariSite Performance - From Pinto to Ferrari
Site Performance - From Pinto to Ferrari
 
CHI - YAPC NA 2012
CHI - YAPC NA 2012CHI - YAPC NA 2012
CHI - YAPC NA 2012
 
Large-scale Web Apps @ Pinterest
Large-scale Web Apps @ PinterestLarge-scale Web Apps @ Pinterest
Large-scale Web Apps @ Pinterest
 
Maximize your Cache for No Cash
Maximize your Cache for No CashMaximize your Cache for No Cash
Maximize your Cache for No Cash
 
Shadow forensics print
Shadow forensics printShadow forensics print
Shadow forensics print
 
Tuning Your SharePoint Environment
Tuning Your SharePoint EnvironmentTuning Your SharePoint Environment
Tuning Your SharePoint Environment
 
Caching and tuning fun for high scalability
Caching and tuning fun for high scalabilityCaching and tuning fun for high scalability
Caching and tuning fun for high scalability
 
AWS re:Invent 2016: Streaming ETL for RDS and DynamoDB (DAT315)
AWS re:Invent 2016: Streaming ETL for RDS and DynamoDB (DAT315)AWS re:Invent 2016: Streaming ETL for RDS and DynamoDB (DAT315)
AWS re:Invent 2016: Streaming ETL for RDS and DynamoDB (DAT315)
 
High Performance With Java
High Performance With JavaHigh Performance With Java
High Performance With Java
 
Scaling Servers and Storage for Film Assets
Scaling Servers and Storage for Film Assets  Scaling Servers and Storage for Film Assets
Scaling Servers and Storage for Film Assets
 
Hyperbatch (LoteRapido) - Punta Dreamin' 2017
Hyperbatch (LoteRapido) - Punta Dreamin' 2017Hyperbatch (LoteRapido) - Punta Dreamin' 2017
Hyperbatch (LoteRapido) - Punta Dreamin' 2017
 
Introduction to memcached
Introduction to memcachedIntroduction to memcached
Introduction to memcached
 
Rails Caching: Secrets From the Edge
Rails Caching: Secrets From the EdgeRails Caching: Secrets From the Edge
Rails Caching: Secrets From the Edge
 
Rails Caching Secrets from the Edge
Rails Caching Secrets from the EdgeRails Caching Secrets from the Edge
Rails Caching Secrets from the Edge
 

More from Federico Russo (20)

23 Sicurezza in BBox
23 Sicurezza in BBox23 Sicurezza in BBox
23 Sicurezza in BBox
 
21 Buzzwords
21 Buzzwords21 Buzzwords
21 Buzzwords
 
18 - InfluxDB
18 - InfluxDB18 - InfluxDB
18 - InfluxDB
 
19 - The Highlander Project
19 - The Highlander Project19 - The Highlander Project
19 - The Highlander Project
 
22 - Better Coding
22 - Better Coding22 - Better Coding
22 - Better Coding
 
20 - Ottimizzare le query
20 - Ottimizzare le query20 - Ottimizzare le query
20 - Ottimizzare le query
 
17 - Web Application Threats
17 - Web Application Threats17 - Web Application Threats
17 - Web Application Threats
 
16 - Project Lombok
16 - Project Lombok16 - Project Lombok
16 - Project Lombok
 
15 - Java 8
15 - Java 815 - Java 8
15 - Java 8
 
14 - Atom
14 - Atom14 - Atom
14 - Atom
 
Slides functionalities 0.26-r16
Slides   functionalities 0.26-r16Slides   functionalities 0.26-r16
Slides functionalities 0.26-r16
 
BBox e vaadin7
BBox e vaadin7BBox e vaadin7
BBox e vaadin7
 
Box Functionalities 0.20
Box Functionalities 0.20Box Functionalities 0.20
Box Functionalities 0.20
 
Tile server
Tile serverTile server
Tile server
 
Vaadin7
Vaadin7Vaadin7
Vaadin7
 
12 java modifiers
12 java modifiers12 java modifiers
12 java modifiers
 
11 Java 7
11 Java 711 Java 7
11 Java 7
 
08 Workflow e strumenti web
08 Workflow e strumenti web08 Workflow e strumenti web
08 Workflow e strumenti web
 
06 Refactoring
06 Refactoring06 Refactoring
06 Refactoring
 
09 Transactions
09 Transactions09 Transactions
09 Transactions
 

Recently uploaded

Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityPrincipled Technologies
 
Unblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesUnblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesSinan KOZAK
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsMaria Levchenko
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Scriptwesley chun
 
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...gurkirankumar98700
 
08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking MenDelhi Call girls
 
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure serviceWhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure servicePooja Nehwal
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsEnterprise Knowledge
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)Gabriella Davis
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdfhans926745
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc
 
Breaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountBreaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountPuma Security, LLC
 
Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101Paola De la Torre
 
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Igalia
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking MenDelhi Call girls
 
Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024The Digital Insurer
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerThousandEyes
 
A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024Results
 
Developing An App To Navigate The Roads of Brazil
Developing An App To Navigate The Roads of BrazilDeveloping An App To Navigate The Roads of Brazil
Developing An App To Navigate The Roads of BrazilV3cube
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...Martijn de Jong
 

Recently uploaded (20)

Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivity
 
Unblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesUnblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen Frames
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed texts
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Script
 
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...
 
08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men
 
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure serviceWhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI Solutions
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
 
Breaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountBreaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path Mount
 
Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101
 
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men
 
Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024
 
Developing An App To Navigate The Roads of Brazil
Developing An App To Navigate The Roads of BrazilDeveloping An App To Navigate The Roads of Brazil
Developing An App To Navigate The Roads of Brazil
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...
 

10 Data caching

  • 2. CACHING: WHAT FOR? • Spatial optimization: original data is far and slow to retrieve. • Temporal compute. optimization: original data is heavy to • Concurrency optimization: many users request the same data.
  • 3. CACHE: WHAT? Client (CPU, web browser...) Cache Main Repository (RAM, disk, web, DB...)
  • 4. LATENCY NUMBERS ! ! ! ! ! ! ! ! ! ! ! ! ! Send packet CA->Netherlands->CA 150,000,000 https://gist.github.com/jboner/2841832 ns 150 ms
  • 5. LATENCY NUMBERS ! ! ! ! ! ! ! ! ! ! ! Disk seek ! Send packet CA->Netherlands->CA 10,000,000 ns 10 ms! 150,000,000 ns 150 ms https://gist.github.com/jboner/2841832
  • 6. LATENCY NUMBERS ! ! ! ! Main memory reference ! ! ! ! ! ! Disk seek ! Send packet CA->Netherlands->CA 100 ns! 10,000,000 ns 10 ms! 150,000,000 ns 150 ms https://gist.github.com/jboner/2841832
  • 7. LATENCY NUMBERS ! ! L2 cache reference ! Main memory reference ! ! ! ! ! ! Disk seek ! Send packet CA->Netherlands->CA 7 ns! 100 ns! 10,000,000 ns 10 ms! 150,000,000 ns 150 ms https://gist.github.com/jboner/2841832
  • 8. LATENCY NUMBERS L1 cache reference ! L2 cache reference ! Main memory reference ! ! ! ! ! ! Disk seek ! Send packet CA->Netherlands->CA 0.5 ns! 7 ns! 100 ns! 10,000,000 ns 10 ms! 150,000,000 ns 150 ms https://gist.github.com/jboner/2841832
  • 9. LATENCY NUMBERS L1 cache reference 0.5 Branch mispredict 5 L2 cache reference 7 Mutex lock/unlock 25 Main memory reference 100 Compress 1K bytes with Google Snappy 3,000 Send 1K bytes over 1 Gbps network 10,000 Read 4K randomly from SSD 150,000 Read 1 MB sequentially from memory 250,000 Round trip within same datacenter 500,000 Read 1 MB sequentially from SSD 1,000,000 Disk seek 10,000,000 Read 1 MB sequentially from disk 20,000,000 Send packet CA->Netherlands->CA 150,000,000 https://gist.github.com/jboner/2841832 ns! ns! ns! ns! ns! ns! ns 0.01 ns 0.15 ns 0.25 ns 0.5 ns 1 ns 10 ns 20 ns 150 ms! ms! ms! ms! ms! ms! ms! ms
  • 10. CACHE COHERENCE • Cache data. hit: the cache content must be in sync with the original • Proxy • DNS ask to the original source if their data is up-to-date. cache provide stale data until expiration.
  • 11. CACHE EVICTION • Cache miss: the cache eventually gets full. What can be discarded? • LRU (Last Recently Used) • LFU (Least Frequently Used)
  • 12. WRITE POLICY •I changed the data and put it back into the cache. • Write-through: the data is synchronously pushed to the original source. • Write back: the data is pushed to the source only when it is requested. Client Cache Main Repository
  • 13. CACHE: THE BBOX WAY Windows Client Controllers BOs Server DAOs Database
  • 14. CACHE: THE BBOX WAY Windows Controllers BOs DAOs Database Application cache Query cache Second level cache First level cache DBMS cache
  • 15. HIBERNATE FIRST LEVEL CACHE • Completely • Is automatic and not tunable. flushed at the session’s end (simplifying: at the end of the transaction).
  • 16. HIBERNATE SECOND LEVEL CACHE @Entity! @Indexed! @Table(name = "BOM_PLACE")! @Cacheable! @Cache(usage = CacheConcurrencyStrategy.NONSTRICT_READ_WRITE)! public class PlaceImpl extends ThingImpl<PlaceImpl, PlaceTO, PlaceStrategy> implements Place {! ...! • The cache survives the sessions. • The cache is held and configured by EhCache.
  • 17. HIBERNATE QUERY CACHE @CacheIt! @Dao(entity = PlaceImpl.class)! public interface PlaceImplDao extends GenericDao<PlaceImpl, Long> {! ! @CacheIt! List<PlaceTO> findTO();! ! ...! ! ! ! Criteria c = sessionFactory.getCurrentSession().getCriteria(...);! c.setCacheable(true);! Works together with the Second level cache.
  • 18. BBOX APPLICATION CACHE /**! * @author Federico Russo! */! public interface PlaceBO extends ThingBO<Place, PlaceStrategy, PlaceTO> {! ! ! /**! * Ritorna tutti i figli di un certo TO.! */! @PreAuthorize("hasRole('ROLE_READ_PLACES') and hasPermission(#parentTO, 'READ')")! @PostFilter("hasPermission(filterObject, 'READ')")! @Cacheable(cacheName = "places")! Collection<PlaceTO> findChildrenTO(PlaceTO parentTO, String strategyClassName);! /**! * Rimuove il Component fornito dai magazzini in cui eventualmente sta.! */! @Transactional! @PreAuthorize("hasRole('ROLE_WRITE_PLACES')")! @TriggersRemove(removeAll = true, cacheName = "places")! void removeFromWarehouses(ComponentTO componentTO);! We’re not using it. We should.
  • 19. Next talk: Welcome to Java 7