SlideShare a Scribd company logo
Caching – Methodology & Strategies
By Vu Van Tiep
Manager, Head Of Web Platform - VNG
Skype: tiepvv
Scale Up vs Scale Out
Scale UP
Scale Out
Load Balancing
Agenda
• What
• Cache Layer
• Cache Application/Service
• Methodology
• Strategies
• Performance?
• Demo
• Q&A
Cache – What?
• Is a hardware or software
component that stores data so
future requests for that data can
be served faster;
• The data stored in a cache might
be the result of an earlier
computation, or the duplicate
of data stored elsewhere
https://en.wikipedia.org/wiki/Cache_(computing)
Application
Cache
Database
Hit
MissUpdate
Cache
Cache Layer
Client (Browser) Application Caching Database
- Browser
- Proxy
- CDN
- in-memory
- Server Caching
- Distributed in
memory key/value
- Service:
• Memcache
• Membase
• Redis
• …
- Database caching
• Entity In memory
- DB:
• MySQL
• MongoDB
• Casandra, LevelDB
• …
1 2
3
4
5
6
Http Layer Caching
Browser & Proxy
Client
(Browser)
Web Server
1
2
Client
(Browser)
Client
(Browser)
Web ServerProx
y
Client
(Browser) ProxyCache
Cache
1
2
1 2
34
Response Header
• Expires
• Last-Modified
• Etag
• Cache-Control
• Pragram
Browser Caching – Http Header
Browser Caching – Http Header
Browser Caching – Local Storage
Application Layer Caching
Types/Levels of Cache
Level 1 (L1) Cache
It is also called primary or internal cache. It is built
directly into the processor chip. It has small capacity
from 8 Km to 128 Kb.
Level 2 (L2) Cache
It is slower than L1 cache. Its storage capacity is
more, i-e. From 64 Kb to 16 MB. The current
processors contain advanced transfer cache on
processor chip that is a type of L2 cache. The
common size of this cache is from 512 kb to 8 Mb.
Level 3 (L3) Cache
This cache is separate from processor chip on the
motherboard. It exists on the computer that uses L2
advanced transfer cache. It is slower than L1 and L2
cache. The personal computer often has up to 8 MB
of L3 cache.
L1 cache reference 0.5 ns
Branch mispredict 5 ns
L2 cache reference 7 ns
Mutex lock/unlock 100 ns
Main memory reference 100 ns
Compress 1K bytes with Zippy 10,000 ns
Send 2K bytes over 1 Gbps network 20,000 ns (1)
Read 1 MB sequentially from memory 250,000 ns (2)
Round trip within same datacenter 500,000 ns
Disk seek 10,000,000 ns 1 + 2 < (3)
Read 1 MB sequentially from network 10,000,000 ns
Read 1 MB sequentially from disk 30,000,000 ns
Send packet CA->Netherlands->CA 150,000,000 ns
From Jeff Dean - google.com
Latency Numbers
Note: 1 ns = 10^-9 seconds
Cache: Methodology
Data/Object
Data/Object
Serialize
DeSerialize
Compress
DeCompress
Memcache
Or
Redis
Set
Get
1 2 3
123
Serialize
Disk / Network
Java Object PHP Object C# Object
Write ReadSerialize DeSerialize
Performance Comparison
Text Serialize
Json – size: 167 bytes, se: 6ms, de: 3ms
XML – 235 bytes
Binary Serialize
Thrift – size: 64 bytes, se: 53ms, de:1ms
ProtoBuf – size: 31 bytes, se: 34ms, de: 4ms
Binary serialize take less space
XML, Json
ProtoBuf, Thrift
Message Pack
Apache Arvo
…
Framework
Compress/Decompress
Name Ratio C.speed D.speed
MB/s MB/s
zstd 0.8.2 -1 2.877 330 940
zlib 1.2.8 -1 2.73 95 360
brotli 0.4 -0 2.708 320 375
QuickLZ 1.5 2.237 510 605
LZO 2.09 2.106 610 870
LZ4 r131 2.101 620 3100
Snappy 1.1.3 2.091 480 1600
LZF 3.6 2.077 375 790
As a reference, several fast
compression algorithms were tested
and compared on a Core i7-3930K
CPU @ 4.5GHz, using lzbench, an
open-source in-memory benchmark
by @inikep compiled with GCC 5.4.0,
with the Silesia compression corpus.
https://github.com/facebook/zstd
Caching Strategies
Cache Strategies
1. Optimize Data Size
2. Hot Object
3. In-Process
4. Lazy load
5. Distributed
Optimize Data Size
Name Ratio C.speed D.speed
MB/s MB/s
zstd 0.8.2 -1 2.877 330 940
zlib 1.2.8 -1 2.73 95 360
brotli 0.4 -0 2.708 320 375
QuickLZ 1.5 2.237 510 605
LZO 2.09 2.106 610 870
LZ4 r131 2.101 620 3100
Snappy 1.1.3 2.091 480 1600
LZF 3.6 2.077 375 790
CompressSerialize
Method Size (smaller is better)
Thrift — TCompactProtocol 278 (not bad)
Thrift — TBinaryProtocol 460
Protocol Buffers 250 (winner!)
RMI 905
REST — JSON 559
REST — XML 836
High Level Goals:
• Transparent between multiple programming
languages (PHP/Java/Cpp/…)
• Maintain Right balance between:
• Efficiency (how much time/space?)
• Availability of existing libraries
Hot Object => Eviction Algorithms
2G
Ram
10G
Data
ServerData
How to cache?
Eviction Algorithms: Least Frequently Used (LFU)
A B C D E F
7 6 3 2 4 1
A B C D E F
7 6 3 3 4 1
Access
Most Frequently
Used
Least Frequently
Used
Eviction Algorithms: Least Recently Used (LRU)
1 2 3 4 5 6
4 1 2 3 5 6
Access
In-Process
Request
Application
Local cache Backend/Database
Application
Lazy Load
Request
Logic
Caching
(Memory)
Backend/Databas
e
Application
Warmup
Worker
Distributed Cache
Server 1
Server 3
Server 2Server 4
Distributed Cache
Client 1
Client 2
Client 3
Performance: Profiler is the key
Demo
Contact info:
• Name: Vu Van Tiep
• Email: tiepvv@vng.com.vn / vuvantiep@gmail.com
• Skype: tiepvv
Q&A
Thank You!
Reference
• https://en.wikipedia.org/wiki/Cache_(computing)
• http://www.slideshare.net/IgorAnishchenko/pb-vs-thrift-vs-avro
• https://github.com/facebook/zstd
• http://www.codeproject.com/Articles/56138/Consistent-hashing

More Related Content

PDF
Redis for horizontally scaled data processing at jFrog bintray
PDF
Using Redis at Facebook
PPTX
Redis on NVMe SSD - Zvika Guz, Samsung
PDF
Troubleshooting redis
PDF
Development to Production with Sharded MongoDB Clusters
PDF
Basic and Advanced Analysis of Ceph Volume Backend Driver in Cinder - John Haan
PPTX
HBaseCon 2012 | Base Metrics: What They Mean to You - Cloudera
PPTX
Introducing MongoDB in a multi-site HA environment
Redis for horizontally scaled data processing at jFrog bintray
Using Redis at Facebook
Redis on NVMe SSD - Zvika Guz, Samsung
Troubleshooting redis
Development to Production with Sharded MongoDB Clusters
Basic and Advanced Analysis of Ceph Volume Backend Driver in Cinder - John Haan
HBaseCon 2012 | Base Metrics: What They Mean to You - Cloudera
Introducing MongoDB in a multi-site HA environment

What's hot (19)

PDF
Kafka Summit SF 2017 - Infrastructure for Streaming Applications
PDF
Advanced Administration, Monitoring and Backup
PPTX
Apache HBase, Accelerated: In-Memory Flush and Compaction
PPTX
Webinar: Backups + Disaster Recovery
PPTX
Backup, Restore, and Disaster Recovery
PDF
Accelerating Ceph Performance with High Speed Networks and Protocols - Qingch...
PPTX
Perforce BTrees: The Arcane and the Profane
PDF
Володимир Цап "Constraint driven infrastructure - scale or tune?"
PPTX
Day 2 General Session Presentations RedisConf
PDF
Optimizing MongoDB: Lessons Learned at Localytics
PPTX
Capacity Planning For Your Growing MongoDB Cluster
PPTX
Jumbo Mumbo in OpenStack
PDF
MongoDB memory management demystified
PPTX
Redis Developers Day 2014 - Redis Labs Talks
PDF
HBaseConAsia2018 Track1-7: HDFS optimizations for HBase at Xiaomi
PPT
GFS - Google File System
PDF
Accelerating HBase with NVMe and Bucket Cache
PPTX
Let the Tiger Roar! - MongoDB 3.0 + WiredTiger
PPTX
Date-tiered Compaction Policy for Time-series Data
Kafka Summit SF 2017 - Infrastructure for Streaming Applications
Advanced Administration, Monitoring and Backup
Apache HBase, Accelerated: In-Memory Flush and Compaction
Webinar: Backups + Disaster Recovery
Backup, Restore, and Disaster Recovery
Accelerating Ceph Performance with High Speed Networks and Protocols - Qingch...
Perforce BTrees: The Arcane and the Profane
Володимир Цап "Constraint driven infrastructure - scale or tune?"
Day 2 General Session Presentations RedisConf
Optimizing MongoDB: Lessons Learned at Localytics
Capacity Planning For Your Growing MongoDB Cluster
Jumbo Mumbo in OpenStack
MongoDB memory management demystified
Redis Developers Day 2014 - Redis Labs Talks
HBaseConAsia2018 Track1-7: HDFS optimizations for HBase at Xiaomi
GFS - Google File System
Accelerating HBase with NVMe and Bucket Cache
Let the Tiger Roar! - MongoDB 3.0 + WiredTiger
Date-tiered Compaction Policy for Time-series Data
Ad

Similar to Caching methodology and strategies (20)

PDF
Implementing data and databases on K8s within the Dutch government
ODP
Experience In Building Scalable Web Sites Through Infrastructure's View
PDF
Building a High Performance Analytics Platform
PDF
Performance
PPTX
In-memory Caching in HDFS: Lower Latency, Same Great Taste
PDF
Cómo se diseña una base de datos que pueda ingerir más de cuatro millones de ...
ODP
Caching and tuning fun for high scalability
PDF
Offloading for Databases - Deep Dive
PPTX
openSUSE storage workshop 2016
PDF
User-space Network Processing
PPTX
IMC Summit 2016 Breakout - Per Minoborg - Work with Multiple Hot Terabytes in...
PDF
Comparison of foss distributed storage
PDF
Primitive Pursuits: Slaying Latency with Low-Level Primitives and Instructions
PPTX
Mini-Training: To cache or not to cache
PPTX
Red Hat Ceph Storage Acceleration Utilizing Flash Technology
PPTX
Cloud computing UNIT 2.1 presentation in
PDF
IMCSummit 2015 - Day 1 Developer Session - The Science and Engineering Behind...
PPTX
Oracle Open World 2014: Lies, Damned Lies, and I/O Statistics [ CON3671]
PDF
Where Django Caching Bust at the Seams
PDF
Optimizing Performance and Computing Resource Efficiency of In-Memory Big Dat...
Implementing data and databases on K8s within the Dutch government
Experience In Building Scalable Web Sites Through Infrastructure's View
Building a High Performance Analytics Platform
Performance
In-memory Caching in HDFS: Lower Latency, Same Great Taste
Cómo se diseña una base de datos que pueda ingerir más de cuatro millones de ...
Caching and tuning fun for high scalability
Offloading for Databases - Deep Dive
openSUSE storage workshop 2016
User-space Network Processing
IMC Summit 2016 Breakout - Per Minoborg - Work with Multiple Hot Terabytes in...
Comparison of foss distributed storage
Primitive Pursuits: Slaying Latency with Low-Level Primitives and Instructions
Mini-Training: To cache or not to cache
Red Hat Ceph Storage Acceleration Utilizing Flash Technology
Cloud computing UNIT 2.1 presentation in
IMCSummit 2015 - Day 1 Developer Session - The Science and Engineering Behind...
Oracle Open World 2014: Lies, Damned Lies, and I/O Statistics [ CON3671]
Where Django Caching Bust at the Seams
Optimizing Performance and Computing Resource Efficiency of In-Memory Big Dat...
Ad

Recently uploaded (20)

PDF
Diabetes mellitus diagnosis method based random forest with bat algorithm
PPTX
Understanding_Digital_Forensics_Presentation.pptx
PDF
Encapsulation theory and applications.pdf
PDF
Machine learning based COVID-19 study performance prediction
PPTX
Detection-First SIEM: Rule Types, Dashboards, and Threat-Informed Strategy
PDF
Empathic Computing: Creating Shared Understanding
DOCX
The AUB Centre for AI in Media Proposal.docx
PDF
Blue Purple Modern Animated Computer Science Presentation.pdf.pdf
PDF
TokAI - TikTok AI Agent : The First AI Application That Analyzes 10,000+ Vira...
PPT
Teaching material agriculture food technology
PDF
Electronic commerce courselecture one. Pdf
PDF
7 ChatGPT Prompts to Help You Define Your Ideal Customer Profile.pdf
PDF
Reach Out and Touch Someone: Haptics and Empathic Computing
PDF
cuic standard and advanced reporting.pdf
PDF
Advanced methodologies resolving dimensionality complications for autism neur...
PDF
Bridging biosciences and deep learning for revolutionary discoveries: a compr...
PDF
NewMind AI Weekly Chronicles - August'25 Week I
PDF
Per capita expenditure prediction using model stacking based on satellite ima...
PDF
Dropbox Q2 2025 Financial Results & Investor Presentation
PDF
The Rise and Fall of 3GPP – Time for a Sabbatical?
Diabetes mellitus diagnosis method based random forest with bat algorithm
Understanding_Digital_Forensics_Presentation.pptx
Encapsulation theory and applications.pdf
Machine learning based COVID-19 study performance prediction
Detection-First SIEM: Rule Types, Dashboards, and Threat-Informed Strategy
Empathic Computing: Creating Shared Understanding
The AUB Centre for AI in Media Proposal.docx
Blue Purple Modern Animated Computer Science Presentation.pdf.pdf
TokAI - TikTok AI Agent : The First AI Application That Analyzes 10,000+ Vira...
Teaching material agriculture food technology
Electronic commerce courselecture one. Pdf
7 ChatGPT Prompts to Help You Define Your Ideal Customer Profile.pdf
Reach Out and Touch Someone: Haptics and Empathic Computing
cuic standard and advanced reporting.pdf
Advanced methodologies resolving dimensionality complications for autism neur...
Bridging biosciences and deep learning for revolutionary discoveries: a compr...
NewMind AI Weekly Chronicles - August'25 Week I
Per capita expenditure prediction using model stacking based on satellite ima...
Dropbox Q2 2025 Financial Results & Investor Presentation
The Rise and Fall of 3GPP – Time for a Sabbatical?

Caching methodology and strategies

  • 1. Caching – Methodology & Strategies By Vu Van Tiep Manager, Head Of Web Platform - VNG Skype: tiepvv
  • 2. Scale Up vs Scale Out Scale UP Scale Out
  • 4. Agenda • What • Cache Layer • Cache Application/Service • Methodology • Strategies • Performance? • Demo • Q&A
  • 5. Cache – What? • Is a hardware or software component that stores data so future requests for that data can be served faster; • The data stored in a cache might be the result of an earlier computation, or the duplicate of data stored elsewhere https://en.wikipedia.org/wiki/Cache_(computing) Application Cache Database Hit MissUpdate Cache
  • 6. Cache Layer Client (Browser) Application Caching Database - Browser - Proxy - CDN - in-memory - Server Caching - Distributed in memory key/value - Service: • Memcache • Membase • Redis • … - Database caching • Entity In memory - DB: • MySQL • MongoDB • Casandra, LevelDB • … 1 2 3 4 5 6
  • 8. Browser & Proxy Client (Browser) Web Server 1 2 Client (Browser) Client (Browser) Web ServerProx y Client (Browser) ProxyCache Cache 1 2 1 2 34 Response Header • Expires • Last-Modified • Etag • Cache-Control • Pragram
  • 9. Browser Caching – Http Header
  • 10. Browser Caching – Http Header
  • 11. Browser Caching – Local Storage
  • 13. Types/Levels of Cache Level 1 (L1) Cache It is also called primary or internal cache. It is built directly into the processor chip. It has small capacity from 8 Km to 128 Kb. Level 2 (L2) Cache It is slower than L1 cache. Its storage capacity is more, i-e. From 64 Kb to 16 MB. The current processors contain advanced transfer cache on processor chip that is a type of L2 cache. The common size of this cache is from 512 kb to 8 Mb. Level 3 (L3) Cache This cache is separate from processor chip on the motherboard. It exists on the computer that uses L2 advanced transfer cache. It is slower than L1 and L2 cache. The personal computer often has up to 8 MB of L3 cache.
  • 14. L1 cache reference 0.5 ns Branch mispredict 5 ns L2 cache reference 7 ns Mutex lock/unlock 100 ns Main memory reference 100 ns Compress 1K bytes with Zippy 10,000 ns Send 2K bytes over 1 Gbps network 20,000 ns (1) Read 1 MB sequentially from memory 250,000 ns (2) Round trip within same datacenter 500,000 ns Disk seek 10,000,000 ns 1 + 2 < (3) Read 1 MB sequentially from network 10,000,000 ns Read 1 MB sequentially from disk 30,000,000 ns Send packet CA->Netherlands->CA 150,000,000 ns From Jeff Dean - google.com Latency Numbers Note: 1 ns = 10^-9 seconds
  • 16. Serialize Disk / Network Java Object PHP Object C# Object Write ReadSerialize DeSerialize
  • 17. Performance Comparison Text Serialize Json – size: 167 bytes, se: 6ms, de: 3ms XML – 235 bytes Binary Serialize Thrift – size: 64 bytes, se: 53ms, de:1ms ProtoBuf – size: 31 bytes, se: 34ms, de: 4ms Binary serialize take less space XML, Json ProtoBuf, Thrift Message Pack Apache Arvo … Framework
  • 18. Compress/Decompress Name Ratio C.speed D.speed MB/s MB/s zstd 0.8.2 -1 2.877 330 940 zlib 1.2.8 -1 2.73 95 360 brotli 0.4 -0 2.708 320 375 QuickLZ 1.5 2.237 510 605 LZO 2.09 2.106 610 870 LZ4 r131 2.101 620 3100 Snappy 1.1.3 2.091 480 1600 LZF 3.6 2.077 375 790 As a reference, several fast compression algorithms were tested and compared on a Core i7-3930K CPU @ 4.5GHz, using lzbench, an open-source in-memory benchmark by @inikep compiled with GCC 5.4.0, with the Silesia compression corpus. https://github.com/facebook/zstd
  • 20. Cache Strategies 1. Optimize Data Size 2. Hot Object 3. In-Process 4. Lazy load 5. Distributed
  • 21. Optimize Data Size Name Ratio C.speed D.speed MB/s MB/s zstd 0.8.2 -1 2.877 330 940 zlib 1.2.8 -1 2.73 95 360 brotli 0.4 -0 2.708 320 375 QuickLZ 1.5 2.237 510 605 LZO 2.09 2.106 610 870 LZ4 r131 2.101 620 3100 Snappy 1.1.3 2.091 480 1600 LZF 3.6 2.077 375 790 CompressSerialize Method Size (smaller is better) Thrift — TCompactProtocol 278 (not bad) Thrift — TBinaryProtocol 460 Protocol Buffers 250 (winner!) RMI 905 REST — JSON 559 REST — XML 836 High Level Goals: • Transparent between multiple programming languages (PHP/Java/Cpp/…) • Maintain Right balance between: • Efficiency (how much time/space?) • Availability of existing libraries
  • 22. Hot Object => Eviction Algorithms 2G Ram 10G Data ServerData How to cache?
  • 23. Eviction Algorithms: Least Frequently Used (LFU) A B C D E F 7 6 3 2 4 1 A B C D E F 7 6 3 3 4 1 Access Most Frequently Used Least Frequently Used
  • 24. Eviction Algorithms: Least Recently Used (LRU) 1 2 3 4 5 6 4 1 2 3 5 6 Access
  • 27. Distributed Cache Server 1 Server 3 Server 2Server 4 Distributed Cache Client 1 Client 2 Client 3
  • 29. Demo
  • 30. Contact info: • Name: Vu Van Tiep • Email: tiepvv@vng.com.vn / vuvantiep@gmail.com • Skype: tiepvv Q&A Thank You!
  • 31. Reference • https://en.wikipedia.org/wiki/Cache_(computing) • http://www.slideshare.net/IgorAnishchenko/pb-vs-thrift-vs-avro • https://github.com/facebook/zstd • http://www.codeproject.com/Articles/56138/Consistent-hashing