SlideShare a Scribd company logo
1 of 26
Download to read offline
Principles of Caching and Distributed
            Caching (Java)

            Praveen Manvi
whoami


Currently working as Senior Technologist @ Thomson Reuters
13 + years java development experience (portals, web services, content
management...)
Goals of this presentation

• Learn about caching/distributed caching basic
  principles
• Get familiar with prominent use cases and the
  list of solutions available in this space
• Be ‘Distributed cache’ related buzzwords
  compliant
TwoHardThings


There are only two hard things in Computer
Science: cache invalidation and naming things.-
                                                                          - Phil Karlton




No other efficient way to increase throughput/scalability than caching.
Why distributed Cache




2 minutes video from terracota that explains nicely about caching
(http://terracotta.org/video/)
Some fundamentals
• Cache
 A temporary storage area where frequently accessed data can be stored for
 rapid access. Defining frequently accessed data is a matter of judgment and
 engineering
• Why Cache
 The differences to fetch data from a CPU register , RAM, disk & network are
 many orders of magnitude, so it makes perfect sense that keeping the most
 frequently used data in the closest location that reduces latency. There is no
 better way to improve the performance.
• Memory Hierarchy
 Pictures of pyramids in the next slides should help to remember memory
 architecture better
Memory Hierarchy
In terms clock cycles
RAM Vs Disk
Latency Numbers

  •     L1 cache reference 0.5 ns
  •     L2 cache reference 7 ns
  •     Mutex lock/unlock 25 ns
  •     Main memory reference 100 ns
  •     Send 2K bytes over 1 Gbps network 20,000 ns
  •     Read 1 MB sequentially from memory 250,000 ns
  •     Round trip within same datacenter 500,000 ns
  •     Disk seek 10,000,000 ns
  •     Read 1 MB sequentially from disk 20,000,000 ns
1 ns = 10-9 seconds
1 ms = 10-3 seconds
& Pictorial representation
Distributed Cache

• One machine cannot manage huge amount of data
• 100s of servers need to be treated as single unit managing the
  partitions, transaction, security & speed of concurrent access
• Distributed caching solutions simplifies the all the hard work required
  by distributed programming
Shared Memory In Java
No support (direct) memory mapping (sharing memory across the different processes)
• Java is designed to be a (virtual) machine unto itself. It doesn't really support the idea of
    separate processes. It has robust support for lightweight independent execution path
    through threads sharing same memory space.
• Java's memory guarantees are a more fine-grained version of sharing memory, with type and
    privacy control, and built-in robust concurrency features.
• There are ways access through new java nio APIs and through JNI.

Why memory mapped IO
• memory-mapped IO allows us to map a file on disk to memory byte buffer so that when we
   read the memory buffer, the data is read from the file. There is no overhead of the system
   call and the creation and copying of buffers. More importantly, from Java perspective, the
   memory buffer resides in the native space and not in the JVM's heap.
Why its not so important for Java
• Java is a general purpose language, programmers are relieved from dealing with page faults,
   in-appropriate access of disk sector & providing a layer over them memory
Use cases

•   share data/state among many servers for better performance
•   clustering of application
•   partition your in-memory data
•   send/receive messages among applications on demand
•   distribute workload onto many servers
•   take advantage of parallel processing
•   provide fail-safe data management
•   provide secure communication among servers
•   better utilization of cpu and network bandwidth
& some economics


A blade with 64GB RAM for ~$1.5K
$30K we can have 1TB of RAM capacity (20 blades)

– Gartner estimates that by 2014 at least 40% of large organizations will
  deploy an IMDG (In Memory Data Grid) product with the market
  reaching to $1 billion
Caching topologies

-    Partitioned
A partitioned cache is a clustered, fault-tolerant cache that
has linear scalability.
-    Replication
A replicated cache is a clustered, fault tolerant cache where
data is fully replicated to every member in the cluster.
-    Near Cache
A near cache is a hybrid cache; it typically fronts a distributed
cache or a remote cache with a local cache.
Cache Load techniques
• Cache Through
  – Synchronous
• Write Behind
  – Asynchronous
• Read Through (Lazy loading technique)
  – if(get(Key)) is NULL load it.
   Else return the result obtained from cache
Caching patterns

• Minimize the number of hops to locate and
  access data
  Separate data and metadata, provide hints, and
  avoid cache-to-cache transfer
• Do not slow down - Cache data close to client
  Location-hints
• Share data among many caches
  Separate data paths and metadata paths,
  location-hints and index
Cache Performance Characteristics
  – Application throughput/latency
  – JVM : Threads, Heap memory, GC
  & also CPU, Memory, Disk at OS level

 The main performance characteristic of a cache is a hit/miss ratio. The
 hit/miss ratio is calculated as number of cache hits divided by number
 of cache misses. The hit/miss ratio is calculated using hit and miss
 counters accumulated over a period of time. A high hit/miss ratio
 means that a cache performs well. A low hit/miss ratio means that the
 cache is applied to data that should not be cached. Also, the low
 hit/miss ratio may mean that a cache is too small to capture temporal
 locality of data access.
Sample Usage (Hazelcast)
Map<String,User> users = new ConcurrentHashMap<String,User>();

users.put(“praveen", new AdminUser(“praveen", “yahoo123"));
users.put(“suresh", new ClientUser(“suresh", “wipro123"));



   Single change will do the magic & we can get the users in
   different JVMs and the host

Map<String,User> users = Hazelcast.getMap("users");
users.put(“praveen", new AdminUser(“praveen", “yahoo123"));
users.put(“suresh", new ClientUser(“suresh", “wipro123"));
Stand-alone JVM caching
   JVM’s inbuilt mechanisms to handle the references are important concepts to
   understand.

• Soft Reference
• Weak Reference
Ex: MapMarker library from Guava.
Map<Key,Graph> graphs = new MapMaker() .concurrencyLevel(4) .weakKeys() .maximumSize(10000)
                            .expireAfterWrite(10, TimeUnit.MINUTES) .makeComputingMap( new Function() {
                             public Graph apply(Key key) {
                                       return createExpensiveGraph(key);
} });
Distributed Caching Solutions
Some non java based options
Job Trends
Questions?

More Related Content

What's hot

Using Distributed In-Memory Computing for Fast Data Analysis
Using Distributed In-Memory Computing for Fast Data AnalysisUsing Distributed In-Memory Computing for Fast Data Analysis
Using Distributed In-Memory Computing for Fast Data AnalysisScaleOut Software
 
Roeder posterismb2010
Roeder posterismb2010Roeder posterismb2010
Roeder posterismb2010Chris Roeder
 
Storage for Microsoft®Windows Enfironments
Storage for Microsoft®Windows EnfironmentsStorage for Microsoft®Windows Enfironments
Storage for Microsoft®Windows EnfironmentsMichael Hudak
 
Times Ten in-memory database when time counts - Laszlo Ludas
Times Ten in-memory database when time counts - Laszlo LudasTimes Ten in-memory database when time counts - Laszlo Ludas
Times Ten in-memory database when time counts - Laszlo LudasORACLE USER GROUP ESTONIA
 
Stability Patterns for Microservices
Stability Patterns for MicroservicesStability Patterns for Microservices
Stability Patterns for Microservicespflueras
 
HBase Operations and Best Practices
HBase Operations and Best PracticesHBase Operations and Best Practices
HBase Operations and Best PracticesVenu Anuganti
 
Logical Architecture for Protection
Logical Architecture for ProtectionLogical Architecture for Protection
Logical Architecture for ProtectionSunita Shrivastava
 
Nn ha hadoop world.final
Nn ha hadoop world.finalNn ha hadoop world.final
Nn ha hadoop world.finalHortonworks
 
Caching in Distributed Environment
Caching in Distributed EnvironmentCaching in Distributed Environment
Caching in Distributed Environmentabhigad
 
Thousands of Threads and Blocking I/O
Thousands of Threads and Blocking I/OThousands of Threads and Blocking I/O
Thousands of Threads and Blocking I/OGeorge Cao
 
Introducing Lattus Object Storage
Introducing Lattus Object StorageIntroducing Lattus Object Storage
Introducing Lattus Object StorageQuantum
 
Scalability, Availability & Stability Patterns
Scalability, Availability & Stability PatternsScalability, Availability & Stability Patterns
Scalability, Availability & Stability PatternsJonas Bonér
 
A Paradigm Shift: The Increasing Dominance of Memory-Oriented Solutions for H...
A Paradigm Shift: The Increasing Dominance of Memory-Oriented Solutions for H...A Paradigm Shift: The Increasing Dominance of Memory-Oriented Solutions for H...
A Paradigm Shift: The Increasing Dominance of Memory-Oriented Solutions for H...Ben Stopford
 
PostgreSQL Scaling And Failover
PostgreSQL Scaling And FailoverPostgreSQL Scaling And Failover
PostgreSQL Scaling And FailoverJohn Paulett
 
Best Practices of HA and Replication of PostgreSQL in Virtualized Environments
Best Practices of HA and Replication of PostgreSQL in Virtualized EnvironmentsBest Practices of HA and Replication of PostgreSQL in Virtualized Environments
Best Practices of HA and Replication of PostgreSQL in Virtualized EnvironmentsJignesh Shah
 
Planning & Best Practice for Microsoft Virtualization
Planning & Best Practice for Microsoft VirtualizationPlanning & Best Practice for Microsoft Virtualization
Planning & Best Practice for Microsoft VirtualizationLai Yoong Seng
 
TECHNICAL BRIEF▶ NetBackup 7.6 Deduplication Technology
TECHNICAL BRIEF▶ NetBackup 7.6 Deduplication TechnologyTECHNICAL BRIEF▶ NetBackup 7.6 Deduplication Technology
TECHNICAL BRIEF▶ NetBackup 7.6 Deduplication TechnologySymantec
 

What's hot (20)

5 Reasons to Upgrade Ehcache to BigMemory Go
5 Reasons to Upgrade Ehcache to BigMemory Go5 Reasons to Upgrade Ehcache to BigMemory Go
5 Reasons to Upgrade Ehcache to BigMemory Go
 
Using Distributed In-Memory Computing for Fast Data Analysis
Using Distributed In-Memory Computing for Fast Data AnalysisUsing Distributed In-Memory Computing for Fast Data Analysis
Using Distributed In-Memory Computing for Fast Data Analysis
 
Roeder posterismb2010
Roeder posterismb2010Roeder posterismb2010
Roeder posterismb2010
 
Storage for Microsoft®Windows Enfironments
Storage for Microsoft®Windows EnfironmentsStorage for Microsoft®Windows Enfironments
Storage for Microsoft®Windows Enfironments
 
Times Ten in-memory database when time counts - Laszlo Ludas
Times Ten in-memory database when time counts - Laszlo LudasTimes Ten in-memory database when time counts - Laszlo Ludas
Times Ten in-memory database when time counts - Laszlo Ludas
 
Stability Patterns for Microservices
Stability Patterns for MicroservicesStability Patterns for Microservices
Stability Patterns for Microservices
 
HBase Operations and Best Practices
HBase Operations and Best PracticesHBase Operations and Best Practices
HBase Operations and Best Practices
 
Data replication
Data replicationData replication
Data replication
 
Logical Architecture for Protection
Logical Architecture for ProtectionLogical Architecture for Protection
Logical Architecture for Protection
 
Nn ha hadoop world.final
Nn ha hadoop world.finalNn ha hadoop world.final
Nn ha hadoop world.final
 
Caching in Distributed Environment
Caching in Distributed EnvironmentCaching in Distributed Environment
Caching in Distributed Environment
 
Thousands of Threads and Blocking I/O
Thousands of Threads and Blocking I/OThousands of Threads and Blocking I/O
Thousands of Threads and Blocking I/O
 
Introducing Lattus Object Storage
Introducing Lattus Object StorageIntroducing Lattus Object Storage
Introducing Lattus Object Storage
 
Scalability, Availability & Stability Patterns
Scalability, Availability & Stability PatternsScalability, Availability & Stability Patterns
Scalability, Availability & Stability Patterns
 
A Paradigm Shift: The Increasing Dominance of Memory-Oriented Solutions for H...
A Paradigm Shift: The Increasing Dominance of Memory-Oriented Solutions for H...A Paradigm Shift: The Increasing Dominance of Memory-Oriented Solutions for H...
A Paradigm Shift: The Increasing Dominance of Memory-Oriented Solutions for H...
 
No sql exploration keyvaluestore
No sql exploration   keyvaluestoreNo sql exploration   keyvaluestore
No sql exploration keyvaluestore
 
PostgreSQL Scaling And Failover
PostgreSQL Scaling And FailoverPostgreSQL Scaling And Failover
PostgreSQL Scaling And Failover
 
Best Practices of HA and Replication of PostgreSQL in Virtualized Environments
Best Practices of HA and Replication of PostgreSQL in Virtualized EnvironmentsBest Practices of HA and Replication of PostgreSQL in Virtualized Environments
Best Practices of HA and Replication of PostgreSQL in Virtualized Environments
 
Planning & Best Practice for Microsoft Virtualization
Planning & Best Practice for Microsoft VirtualizationPlanning & Best Practice for Microsoft Virtualization
Planning & Best Practice for Microsoft Virtualization
 
TECHNICAL BRIEF▶ NetBackup 7.6 Deduplication Technology
TECHNICAL BRIEF▶ NetBackup 7.6 Deduplication TechnologyTECHNICAL BRIEF▶ NetBackup 7.6 Deduplication Technology
TECHNICAL BRIEF▶ NetBackup 7.6 Deduplication Technology
 

Similar to Caching principles-solutions

From cache to in-memory data grid. Introduction to Hazelcast.
From cache to in-memory data grid. Introduction to Hazelcast.From cache to in-memory data grid. Introduction to Hazelcast.
From cache to in-memory data grid. Introduction to Hazelcast.Taras Matyashovsky
 
Jug Lugano - Scale over the limits
Jug Lugano - Scale over the limitsJug Lugano - Scale over the limits
Jug Lugano - Scale over the limitsDavide Carnevali
 
Distributed applications using Hazelcast
Distributed applications using HazelcastDistributed applications using Hazelcast
Distributed applications using HazelcastTaras Matyashovsky
 
Oracle RAC Internals - The Cache Fusion Edition
Oracle RAC Internals - The Cache Fusion EditionOracle RAC Internals - The Cache Fusion Edition
Oracle RAC Internals - The Cache Fusion EditionMarkus Michalewicz
 
Caching fundamentals by Shrikant Vashishtha
Caching fundamentals by Shrikant VashishthaCaching fundamentals by Shrikant Vashishtha
Caching fundamentals by Shrikant VashishthaShriKant Vashishtha
 
Inter connect2016 yss1841-cloud-storage-options-v4
Inter connect2016 yss1841-cloud-storage-options-v4Inter connect2016 yss1841-cloud-storage-options-v4
Inter connect2016 yss1841-cloud-storage-options-v4Tony Pearson
 
VMworld 2013: Extreme Performance Series: Storage in a Flash
VMworld 2013: Extreme Performance Series: Storage in a Flash VMworld 2013: Extreme Performance Series: Storage in a Flash
VMworld 2013: Extreme Performance Series: Storage in a Flash VMworld
 
Data has a better idea the in-memory data grid
Data has a better idea   the in-memory data gridData has a better idea   the in-memory data grid
Data has a better idea the in-memory data gridBogdan Dina
 
Azug - successfully breeding rabits
Azug - successfully breeding rabitsAzug - successfully breeding rabits
Azug - successfully breeding rabitsYves Goeleven
 
Beyond The Data Grid: Coherence, Normalisation, Joins and Linear Scalability
Beyond The Data Grid: Coherence, Normalisation, Joins and Linear ScalabilityBeyond The Data Grid: Coherence, Normalisation, Joins and Linear Scalability
Beyond The Data Grid: Coherence, Normalisation, Joins and Linear ScalabilityBen Stopford
 
M6d cassandrapresentation
M6d cassandrapresentationM6d cassandrapresentation
M6d cassandrapresentationEdward Capriolo
 
Webinar: Overcoming the Storage Challenges Cassandra and Couchbase Create
Webinar: Overcoming the Storage Challenges Cassandra and Couchbase CreateWebinar: Overcoming the Storage Challenges Cassandra and Couchbase Create
Webinar: Overcoming the Storage Challenges Cassandra and Couchbase CreateStorage Switzerland
 
인메모리 클러스터링 아키텍처
인메모리 클러스터링 아키텍처인메모리 클러스터링 아키텍처
인메모리 클러스터링 아키텍처Jaehong Cheon
 
Best Practices for Virtualizing Apache Hadoop
Best Practices for Virtualizing Apache HadoopBest Practices for Virtualizing Apache Hadoop
Best Practices for Virtualizing Apache HadoopHortonworks
 
VMworld 2013: Virtualizing Databases: Doing IT Right
VMworld 2013: Virtualizing Databases: Doing IT Right VMworld 2013: Virtualizing Databases: Doing IT Right
VMworld 2013: Virtualizing Databases: Doing IT Right VMworld
 
HPC and cloud distributed computing, as a journey
HPC and cloud distributed computing, as a journeyHPC and cloud distributed computing, as a journey
HPC and cloud distributed computing, as a journeyPeter Clapham
 
Spring One 2 GX 2014 - CACHING WITH SPRING: ADVANCED TOPICS AND BEST PRACTICES
Spring One 2 GX 2014 - CACHING WITH SPRING: ADVANCED TOPICS AND BEST PRACTICESSpring One 2 GX 2014 - CACHING WITH SPRING: ADVANCED TOPICS AND BEST PRACTICES
Spring One 2 GX 2014 - CACHING WITH SPRING: ADVANCED TOPICS AND BEST PRACTICESMichael Plöd
 

Similar to Caching principles-solutions (20)

From cache to in-memory data grid. Introduction to Hazelcast.
From cache to in-memory data grid. Introduction to Hazelcast.From cache to in-memory data grid. Introduction to Hazelcast.
From cache to in-memory data grid. Introduction to Hazelcast.
 
Jug Lugano - Scale over the limits
Jug Lugano - Scale over the limitsJug Lugano - Scale over the limits
Jug Lugano - Scale over the limits
 
Distributed applications using Hazelcast
Distributed applications using HazelcastDistributed applications using Hazelcast
Distributed applications using Hazelcast
 
Mini-Training: To cache or not to cache
Mini-Training: To cache or not to cacheMini-Training: To cache or not to cache
Mini-Training: To cache or not to cache
 
Oracle RAC Internals - The Cache Fusion Edition
Oracle RAC Internals - The Cache Fusion EditionOracle RAC Internals - The Cache Fusion Edition
Oracle RAC Internals - The Cache Fusion Edition
 
Caching fundamentals by Shrikant Vashishtha
Caching fundamentals by Shrikant VashishthaCaching fundamentals by Shrikant Vashishtha
Caching fundamentals by Shrikant Vashishtha
 
Inter connect2016 yss1841-cloud-storage-options-v4
Inter connect2016 yss1841-cloud-storage-options-v4Inter connect2016 yss1841-cloud-storage-options-v4
Inter connect2016 yss1841-cloud-storage-options-v4
 
VMworld 2013: Extreme Performance Series: Storage in a Flash
VMworld 2013: Extreme Performance Series: Storage in a Flash VMworld 2013: Extreme Performance Series: Storage in a Flash
VMworld 2013: Extreme Performance Series: Storage in a Flash
 
Data has a better idea the in-memory data grid
Data has a better idea   the in-memory data gridData has a better idea   the in-memory data grid
Data has a better idea the in-memory data grid
 
UNIT IV.pptx
UNIT IV.pptxUNIT IV.pptx
UNIT IV.pptx
 
Azug - successfully breeding rabits
Azug - successfully breeding rabitsAzug - successfully breeding rabits
Azug - successfully breeding rabits
 
Beyond The Data Grid: Coherence, Normalisation, Joins and Linear Scalability
Beyond The Data Grid: Coherence, Normalisation, Joins and Linear ScalabilityBeyond The Data Grid: Coherence, Normalisation, Joins and Linear Scalability
Beyond The Data Grid: Coherence, Normalisation, Joins and Linear Scalability
 
M6d cassandrapresentation
M6d cassandrapresentationM6d cassandrapresentation
M6d cassandrapresentation
 
Webinar: Overcoming the Storage Challenges Cassandra and Couchbase Create
Webinar: Overcoming the Storage Challenges Cassandra and Couchbase CreateWebinar: Overcoming the Storage Challenges Cassandra and Couchbase Create
Webinar: Overcoming the Storage Challenges Cassandra and Couchbase Create
 
인메모리 클러스터링 아키텍처
인메모리 클러스터링 아키텍처인메모리 클러스터링 아키텍처
인메모리 클러스터링 아키텍처
 
Clustering van IT-componenten
Clustering van IT-componentenClustering van IT-componenten
Clustering van IT-componenten
 
Best Practices for Virtualizing Apache Hadoop
Best Practices for Virtualizing Apache HadoopBest Practices for Virtualizing Apache Hadoop
Best Practices for Virtualizing Apache Hadoop
 
VMworld 2013: Virtualizing Databases: Doing IT Right
VMworld 2013: Virtualizing Databases: Doing IT Right VMworld 2013: Virtualizing Databases: Doing IT Right
VMworld 2013: Virtualizing Databases: Doing IT Right
 
HPC and cloud distributed computing, as a journey
HPC and cloud distributed computing, as a journeyHPC and cloud distributed computing, as a journey
HPC and cloud distributed computing, as a journey
 
Spring One 2 GX 2014 - CACHING WITH SPRING: ADVANCED TOPICS AND BEST PRACTICES
Spring One 2 GX 2014 - CACHING WITH SPRING: ADVANCED TOPICS AND BEST PRACTICESSpring One 2 GX 2014 - CACHING WITH SPRING: ADVANCED TOPICS AND BEST PRACTICES
Spring One 2 GX 2014 - CACHING WITH SPRING: ADVANCED TOPICS AND BEST PRACTICES
 

Recently uploaded

Key Features Of Token Development (1).pptx
Key  Features Of Token  Development (1).pptxKey  Features Of Token  Development (1).pptx
Key Features Of Token Development (1).pptxLBM Solutions
 
SIEMENS: RAPUNZEL – A Tale About Knowledge Graph
SIEMENS: RAPUNZEL – A Tale About Knowledge GraphSIEMENS: RAPUNZEL – A Tale About Knowledge Graph
SIEMENS: RAPUNZEL – A Tale About Knowledge GraphNeo4j
 
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
 
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
 
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...HostedbyConfluent
 
Install Stable Diffusion in windows machine
Install Stable Diffusion in windows machineInstall Stable Diffusion in windows machine
Install Stable Diffusion in windows machinePadma Pradeep
 
Snow Chain-Integrated Tire for a Safe Drive on Winter Roads
Snow Chain-Integrated Tire for a Safe Drive on Winter RoadsSnow Chain-Integrated Tire for a Safe Drive on Winter Roads
Snow Chain-Integrated Tire for a Safe Drive on Winter RoadsHyundai Motor Group
 
My Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationMy Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationRidwan Fadjar
 
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking MenDelhi Call girls
 
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
 
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
 
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024BookNet Canada
 
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmaticsKotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmaticscarlostorres15106
 
Pigging Solutions Piggable Sweeping Elbows
Pigging Solutions Piggable Sweeping ElbowsPigging Solutions Piggable Sweeping Elbows
Pigging Solutions Piggable Sweeping ElbowsPigging Solutions
 
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
 
How to Remove Document Management Hurdles with X-Docs?
How to Remove Document Management Hurdles with X-Docs?How to Remove Document Management Hurdles with X-Docs?
How to Remove Document Management Hurdles with X-Docs?XfilesPro
 
Maximizing Board Effectiveness 2024 Webinar.pptx
Maximizing Board Effectiveness 2024 Webinar.pptxMaximizing Board Effectiveness 2024 Webinar.pptx
Maximizing Board Effectiveness 2024 Webinar.pptxOnBoard
 
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
 

Recently uploaded (20)

The transition to renewables in India.pdf
The transition to renewables in India.pdfThe transition to renewables in India.pdf
The transition to renewables in India.pdf
 
Key Features Of Token Development (1).pptx
Key  Features Of Token  Development (1).pptxKey  Features Of Token  Development (1).pptx
Key Features Of Token Development (1).pptx
 
SIEMENS: RAPUNZEL – A Tale About Knowledge Graph
SIEMENS: RAPUNZEL – A Tale About Knowledge GraphSIEMENS: RAPUNZEL – A Tale About Knowledge Graph
SIEMENS: RAPUNZEL – A Tale About Knowledge Graph
 
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
 
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...
 
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...
 
Install Stable Diffusion in windows machine
Install Stable Diffusion in windows machineInstall Stable Diffusion in windows machine
Install Stable Diffusion in windows machine
 
Snow Chain-Integrated Tire for a Safe Drive on Winter Roads
Snow Chain-Integrated Tire for a Safe Drive on Winter RoadsSnow Chain-Integrated Tire for a Safe Drive on Winter Roads
Snow Chain-Integrated Tire for a Safe Drive on Winter Roads
 
My Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationMy Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 Presentation
 
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
 
Vulnerability_Management_GRC_by Sohang Sengupta.pptx
Vulnerability_Management_GRC_by Sohang Sengupta.pptxVulnerability_Management_GRC_by Sohang Sengupta.pptx
Vulnerability_Management_GRC_by Sohang Sengupta.pptx
 
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
 
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
 
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
 
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmaticsKotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
 
Pigging Solutions Piggable Sweeping Elbows
Pigging Solutions Piggable Sweeping ElbowsPigging Solutions Piggable Sweeping Elbows
Pigging Solutions Piggable Sweeping Elbows
 
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
 
How to Remove Document Management Hurdles with X-Docs?
How to Remove Document Management Hurdles with X-Docs?How to Remove Document Management Hurdles with X-Docs?
How to Remove Document Management Hurdles with X-Docs?
 
Maximizing Board Effectiveness 2024 Webinar.pptx
Maximizing Board Effectiveness 2024 Webinar.pptxMaximizing Board Effectiveness 2024 Webinar.pptx
Maximizing Board Effectiveness 2024 Webinar.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
 

Caching principles-solutions

  • 1. Principles of Caching and Distributed Caching (Java) Praveen Manvi
  • 2. whoami Currently working as Senior Technologist @ Thomson Reuters 13 + years java development experience (portals, web services, content management...)
  • 3. Goals of this presentation • Learn about caching/distributed caching basic principles • Get familiar with prominent use cases and the list of solutions available in this space • Be ‘Distributed cache’ related buzzwords compliant
  • 4. TwoHardThings There are only two hard things in Computer Science: cache invalidation and naming things.- - Phil Karlton No other efficient way to increase throughput/scalability than caching.
  • 5. Why distributed Cache 2 minutes video from terracota that explains nicely about caching (http://terracotta.org/video/)
  • 6. Some fundamentals • Cache A temporary storage area where frequently accessed data can be stored for rapid access. Defining frequently accessed data is a matter of judgment and engineering • Why Cache The differences to fetch data from a CPU register , RAM, disk & network are many orders of magnitude, so it makes perfect sense that keeping the most frequently used data in the closest location that reduces latency. There is no better way to improve the performance. • Memory Hierarchy Pictures of pyramids in the next slides should help to remember memory architecture better
  • 8.
  • 9. In terms clock cycles
  • 11. Latency Numbers • L1 cache reference 0.5 ns • L2 cache reference 7 ns • Mutex lock/unlock 25 ns • Main memory reference 100 ns • Send 2K bytes over 1 Gbps network 20,000 ns • Read 1 MB sequentially from memory 250,000 ns • Round trip within same datacenter 500,000 ns • Disk seek 10,000,000 ns • Read 1 MB sequentially from disk 20,000,000 ns 1 ns = 10-9 seconds 1 ms = 10-3 seconds
  • 13. Distributed Cache • One machine cannot manage huge amount of data • 100s of servers need to be treated as single unit managing the partitions, transaction, security & speed of concurrent access • Distributed caching solutions simplifies the all the hard work required by distributed programming
  • 14. Shared Memory In Java No support (direct) memory mapping (sharing memory across the different processes) • Java is designed to be a (virtual) machine unto itself. It doesn't really support the idea of separate processes. It has robust support for lightweight independent execution path through threads sharing same memory space. • Java's memory guarantees are a more fine-grained version of sharing memory, with type and privacy control, and built-in robust concurrency features. • There are ways access through new java nio APIs and through JNI. Why memory mapped IO • memory-mapped IO allows us to map a file on disk to memory byte buffer so that when we read the memory buffer, the data is read from the file. There is no overhead of the system call and the creation and copying of buffers. More importantly, from Java perspective, the memory buffer resides in the native space and not in the JVM's heap. Why its not so important for Java • Java is a general purpose language, programmers are relieved from dealing with page faults, in-appropriate access of disk sector & providing a layer over them memory
  • 15. Use cases • share data/state among many servers for better performance • clustering of application • partition your in-memory data • send/receive messages among applications on demand • distribute workload onto many servers • take advantage of parallel processing • provide fail-safe data management • provide secure communication among servers • better utilization of cpu and network bandwidth
  • 16. & some economics A blade with 64GB RAM for ~$1.5K $30K we can have 1TB of RAM capacity (20 blades) – Gartner estimates that by 2014 at least 40% of large organizations will deploy an IMDG (In Memory Data Grid) product with the market reaching to $1 billion
  • 17. Caching topologies - Partitioned A partitioned cache is a clustered, fault-tolerant cache that has linear scalability. - Replication A replicated cache is a clustered, fault tolerant cache where data is fully replicated to every member in the cluster. - Near Cache A near cache is a hybrid cache; it typically fronts a distributed cache or a remote cache with a local cache.
  • 18. Cache Load techniques • Cache Through – Synchronous • Write Behind – Asynchronous • Read Through (Lazy loading technique) – if(get(Key)) is NULL load it. Else return the result obtained from cache
  • 19. Caching patterns • Minimize the number of hops to locate and access data Separate data and metadata, provide hints, and avoid cache-to-cache transfer • Do not slow down - Cache data close to client Location-hints • Share data among many caches Separate data paths and metadata paths, location-hints and index
  • 20. Cache Performance Characteristics – Application throughput/latency – JVM : Threads, Heap memory, GC & also CPU, Memory, Disk at OS level The main performance characteristic of a cache is a hit/miss ratio. The hit/miss ratio is calculated as number of cache hits divided by number of cache misses. The hit/miss ratio is calculated using hit and miss counters accumulated over a period of time. A high hit/miss ratio means that a cache performs well. A low hit/miss ratio means that the cache is applied to data that should not be cached. Also, the low hit/miss ratio may mean that a cache is too small to capture temporal locality of data access.
  • 21. Sample Usage (Hazelcast) Map<String,User> users = new ConcurrentHashMap<String,User>(); users.put(“praveen", new AdminUser(“praveen", “yahoo123")); users.put(“suresh", new ClientUser(“suresh", “wipro123")); Single change will do the magic & we can get the users in different JVMs and the host Map<String,User> users = Hazelcast.getMap("users"); users.put(“praveen", new AdminUser(“praveen", “yahoo123")); users.put(“suresh", new ClientUser(“suresh", “wipro123"));
  • 22. Stand-alone JVM caching JVM’s inbuilt mechanisms to handle the references are important concepts to understand. • Soft Reference • Weak Reference Ex: MapMarker library from Guava. Map<Key,Graph> graphs = new MapMaker() .concurrencyLevel(4) .weakKeys() .maximumSize(10000) .expireAfterWrite(10, TimeUnit.MINUTES) .makeComputingMap( new Function() { public Graph apply(Key key) { return createExpensiveGraph(key); } });
  • 24. Some non java based options