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

Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...shyamraj55
 
Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreternaman860154
 
Build your next Gen AI Breakthrough - April 2024
Build your next Gen AI Breakthrough - April 2024Build your next Gen AI Breakthrough - April 2024
Build your next Gen AI Breakthrough - April 2024Neo4j
 
Transcript: New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024Transcript: New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024BookNet Canada
 
Swan(sea) Song – personal research during my six years at Swansea ... and bey...
Swan(sea) Song – personal research during my six years at Swansea ... and bey...Swan(sea) Song – personal research during my six years at Swansea ... and bey...
Swan(sea) Song – personal research during my six years at Swansea ... and bey...Alan Dix
 
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking MenDelhi Call girls
 
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
 
Unlocking the Potential of the Cloud for IBM Power Systems
Unlocking the Potential of the Cloud for IBM Power SystemsUnlocking the Potential of the Cloud for IBM Power Systems
Unlocking the Potential of the Cloud for IBM Power SystemsPrecisely
 
Beyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry InnovationBeyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry InnovationSafe Software
 
Artificial intelligence in the post-deep learning era
Artificial intelligence in the post-deep learning eraArtificial intelligence in the post-deep learning era
Artificial intelligence in the post-deep learning eraDeakin University
 
Install Stable Diffusion in windows machine
Install Stable Diffusion in windows machineInstall Stable Diffusion in windows machine
Install Stable Diffusion in windows machinePadma Pradeep
 
Human Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsHuman Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsMark Billinghurst
 
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhi
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | DelhiFULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhi
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhisoniya singh
 
The Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxThe Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxMalak Abu Hammad
 
SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024Scott Keck-Warren
 
My Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationMy Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationRidwan Fadjar
 
Understanding the Laravel MVC Architecture
Understanding the Laravel MVC ArchitectureUnderstanding the Laravel MVC Architecture
Understanding the Laravel MVC ArchitecturePixlogix Infotech
 
AI as an Interface for Commercial Buildings
AI as an Interface for Commercial BuildingsAI as an Interface for Commercial Buildings
AI as an Interface for Commercial BuildingsMemoori
 

Recently uploaded (20)

Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
 
Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreter
 
Build your next Gen AI Breakthrough - April 2024
Build your next Gen AI Breakthrough - April 2024Build your next Gen AI Breakthrough - April 2024
Build your next Gen AI Breakthrough - April 2024
 
DMCC Future of Trade Web3 - Special Edition
DMCC Future of Trade Web3 - Special EditionDMCC Future of Trade Web3 - Special Edition
DMCC Future of Trade Web3 - Special Edition
 
Transcript: New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024Transcript: New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024
 
Swan(sea) Song – personal research during my six years at Swansea ... and bey...
Swan(sea) Song – personal research during my six years at Swansea ... and bey...Swan(sea) Song – personal research during my six years at Swansea ... and bey...
Swan(sea) Song – personal research during my six years at Swansea ... and bey...
 
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
 
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
 
Unlocking the Potential of the Cloud for IBM Power Systems
Unlocking the Potential of the Cloud for IBM Power SystemsUnlocking the Potential of the Cloud for IBM Power Systems
Unlocking the Potential of the Cloud for IBM Power Systems
 
Beyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry InnovationBeyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
 
Artificial intelligence in the post-deep learning era
Artificial intelligence in the post-deep learning eraArtificial intelligence in the post-deep learning era
Artificial intelligence in the post-deep learning era
 
Install Stable Diffusion in windows machine
Install Stable Diffusion in windows machineInstall Stable Diffusion in windows machine
Install Stable Diffusion in windows machine
 
Human Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsHuman Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR Systems
 
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhi
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | DelhiFULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhi
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhi
 
E-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptx
E-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptxE-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptx
E-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptx
 
The Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxThe Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptx
 
SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024
 
My Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationMy Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 Presentation
 
Understanding the Laravel MVC Architecture
Understanding the Laravel MVC ArchitectureUnderstanding the Laravel MVC Architecture
Understanding the Laravel MVC Architecture
 
AI as an Interface for Commercial Buildings
AI as an Interface for Commercial BuildingsAI as an Interface for Commercial Buildings
AI as an Interface for Commercial Buildings
 

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