SlideShare a Scribd company logo
PRESENTED BY
Techniques to Improve
Cache Speed
Zohaib Sibte Hassan
DoorDash, Technical Lead
PRESENTED BY
About me
Zohaib Sibte Hassan
Technical Lead at DoorDash
Dreamer, hacker, philosopher, troublemaker, loves
open source.
@zohaibility
PRESENTED BY
IT’S HARD!
Creating delightful
experience
PRESENTED BY
A tale of reducing tail
latency
Cache Stampede
(aka Cache miss storm)
PRESENTED BY
Cache Stampede
PRESENTED BY
PRESENTED BY
Fixing stampede
● Consider key expired a in fixed random (gap) before expiry time.
● Store timestamp (timestamp) with value.
● Set TTL on key (ttl) on Redis.
● Consider key expired if:
timestamp + ttl + (rand() * gap) > now()
RANDOM AHEAD OF TIME EVICTION
Can we do better?
PRESENTED BY
Optimal Probabilistic Cache Stampede
Prevention
http://www.vldb.org/pvldb/vol8/p886-vattani.pdf
PRESENTED BY
Log
log(rand())
PRESENTED BY
Implementation
def get_if_not_aot_expired(entry, expiry_time_window):
from math import log
from random import random
import time
expiry_ts, value = entry
current_ts = int(time.time())
predictive_expire_gap = expiry_time_window * log(random())
# predictive_expire_delta is always -ve due to log(0 .. 1)
if current_ts - predictive_expire_gap >= expiry_ts:
return None
return value
PRESENTED BY
Typical cache setup
PRESENTED BY
Under high traffic load similar cache
stampede/miss-storm can be observed
between L1 & L2 cache (and so on)
PRESENTED BY
PRESENTED BY
We took inspiration from frontend world
(debounce) and exploited promises*
* Also known as Deferred, Task, Future etc.
PRESENTED BY
How
● Every reader provides a function (L1_MISS_FUNCTION) that returns a promise. Usually this function will
read L2 or DB (if L2 miss happens).
● When invoked via debouncer with a key (ID), only first reader is allowed to execute its
L1_MISS_FUNCTION which immediately returning back a promise.
● Rest of the readers coming in (while promise has not been resolved), are immediately returned back the
promise returned from first call to L1_MISS_FUNCTION.
● All readers await on the returned promise to read the value.
● Subsequent calls with ID will call L1_MISS_FUNCTION as soon as promise has been resolved.
ANATOMY OF OUR DEBOUNCING
PRESENTED BY
Implementation
class Debouncer {
constructor() {
this.pendingBoard = {};
}
async debounce(id, callback) {
if (this.pendingBoard[id] !== undefined) {
return await this.pendingBoard[id];
}
this.pendingBoard[id] = callback(id);
try {
return await this.pendingBoard[id];
} finally {
delete this.pendingBoard[id];
}
}
}
const debouncer = new Debouncer();
async function menuItemLoader(key) {
// Read from Redis/DB
}
// After cache miss
const menu = await debouncer.debounce(
`menu-${id}`,
menuItemLoader
);
We wrote a simulator
https://repl.it/@x0a1b/DebounceSimulator
PRESENTED BY
OTHER IMPLEMENTATIONS
LoadingCache<Key, Graph> graphs = Caffeine.newBuilder()
.maximumSize(10_000)
.expireAfterWrite(5, TimeUnit.MINUTES)
.refreshAfterWrite(1, TimeUnit.MINUTES)
.build(key -> createExpensiveGraph(key));
Caffeine cache
PRESENTED BY
WITHOUT DEBOUNCING
Stress test
Summary:
Count: 1053108
Total: 60769.34 ms
Slowest: 8058.86 ms
Fastest: 0.38 ms
Average: 114.43 ms
Requests/sec: 17329.60
Summary:
Count: 1321340
Total: 60064.00 ms
Slowest: 578.69 ms
Fastest: 36.04 ms
Average: 90.77 ms
Requests/sec: 21998.87
WITH DEBOUNCING
The GRPC endpoint being tested is performing a full read through operation ranging from an L1 cache (5
seconds TTL), an L2 cache (10 seconds TTL) and finally falling back to our Postgres database (1 second AOT
eviction). We used ghz to benchmark our service of 2 pods for 60 seconds with 2000 concurrent connections
and no rate limit.
Large values
PRESENTED BY
Why?
● Caching precompiled payloads (e.g. views, menus).
● ML models.
● Message queues or events.
● Even more use-cases with Redis stream message payloads.
WHY WOULD YOU NEED TO STORE LARGE PAYLOADS
PRESENTED BY
Took a page from HTTP, and decided to
use compression.
PRESENTED BY
Considerations
COMPRESSION RATIO
Should provide a decent
compression ratio.
LIGHTWEIGHT
Light on CPU and footprint
STABLE
Stable, well tested, and
well maintained
PRESENTED BY
Meet lzbench
● https://github.com/inikep/lzbench
● https://morotti.github.io/lzbench-web/ - Nice UI with set of
pre-benchmarked results.
● Compression is dependent upon data.
BENCHMARKING COMPRESSORS
Techniques to Improve Cache Speed
Our scenario
● 64,220 bytes of Chick-fil-A menu (serialized JSON)
● 350,333 bytes of Cheesecake factory (serialized JSON)
Techniques to Improve Cache Speed
Observations
● On average LZ4 had slightly higher compression ratio than Snappy i.e. while compressing our serialized
payloads, on average LZ4 was 38.54% vs. 39.71% of Snappy compression ratio.
● Compression speeds of LZ4, and Snappy were almost the same. LZ4 was fractionally slower than Snappy.
● LZ4 was hands down faster than Snappy for decompression. In some cases we found it to be 2x faster
than Snappy.
Techniques to Improve Cache Speed
Redis Operation No Compression (seconds) Snappy (seconds) LZ4 (seconds)
Set (10000) 16.526179 12.635553 12.802149
Get (10000) 12.047090 07.560119 06.434711
Benchmarks
Techniques to Improve Cache Speed
Results
Techniques to Improve Cache Speed
Results
PRESENTED BY
Conclusion
Thank you!
PRESENTED BY

More Related Content

What's hot

Streams are Awesome - (Node.js) TimesOpen Sep 2012
Streams are Awesome - (Node.js) TimesOpen Sep 2012 Streams are Awesome - (Node.js) TimesOpen Sep 2012
Streams are Awesome - (Node.js) TimesOpen Sep 2012
Tom Croucher
 
Как построить видеоплатформу на 200 Гбитс / Ольховченков Вячеслав (Integros)
Как построить видеоплатформу на 200 Гбитс / Ольховченков Вячеслав (Integros)Как построить видеоплатформу на 200 Гбитс / Ольховченков Вячеслав (Integros)
Как построить видеоплатформу на 200 Гбитс / Ольховченков Вячеслав (Integros)
Ontico
 
Scaling WordPress
Scaling WordPressScaling WordPress
Scaling WordPress
Mark Jaquith
 
vert.x 3.1 - be reactive on the JVM but not only in Java
vert.x 3.1 - be reactive on the JVM but not only in Javavert.x 3.1 - be reactive on the JVM but not only in Java
vert.x 3.1 - be reactive on the JVM but not only in Java
Clément Escoffier
 
PostgreSQL Configuration for Humans / Alvaro Hernandez (OnGres)
PostgreSQL Configuration for Humans / Alvaro Hernandez (OnGres)PostgreSQL Configuration for Humans / Alvaro Hernandez (OnGres)
PostgreSQL Configuration for Humans / Alvaro Hernandez (OnGres)
Ontico
 
HighLoad Solutions On MySQL / Xiaobin Lin (Alibaba)
HighLoad Solutions On MySQL / Xiaobin Lin (Alibaba)HighLoad Solutions On MySQL / Xiaobin Lin (Alibaba)
HighLoad Solutions On MySQL / Xiaobin Lin (Alibaba)
Ontico
 
Server side JavaScript: going all the way
Server side JavaScript: going all the wayServer side JavaScript: going all the way
Server side JavaScript: going all the way
Oleg Podsechin
 
Servers with Event Machine - David Troy - RailsConf 2011
Servers with Event Machine - David Troy - RailsConf 2011Servers with Event Machine - David Troy - RailsConf 2011
Servers with Event Machine - David Troy - RailsConf 2011
David Troy
 
Как понять, что происходит на сервере? / Александр Крижановский (NatSys Lab.,...
Как понять, что происходит на сервере? / Александр Крижановский (NatSys Lab.,...Как понять, что происходит на сервере? / Александр Крижановский (NatSys Lab.,...
Как понять, что происходит на сервере? / Александр Крижановский (NatSys Lab.,...
Ontico
 
Масштабируемая конфигурация Nginx, Игорь Сысоев (Nginx)
Масштабируемая конфигурация Nginx, Игорь Сысоев (Nginx)Масштабируемая конфигурация Nginx, Игорь Сысоев (Nginx)
Масштабируемая конфигурация Nginx, Игорь Сысоев (Nginx)
Ontico
 
Node.js - A Quick Tour
Node.js - A Quick TourNode.js - A Quick Tour
Node.js - A Quick Tour
Felix Geisendörfer
 
Nodejs in Production
Nodejs in ProductionNodejs in Production
Nodejs in Production
William Bruno Moraes
 
Java Memory Management Tricks
Java Memory Management Tricks Java Memory Management Tricks
Java Memory Management Tricks
GlobalLogic Ukraine
 
play framework async with scala
play framework async with scalaplay framework async with scala
play framework async with scala
vuhaininh88
 
Buffer overflow for Beginners
Buffer overflow for BeginnersBuffer overflow for Beginners
Buffer overflow for Beginners
Ajin Abraham
 
Tarantool как платформа для микросервисов / Антон Резников, Владимир Перепели...
Tarantool как платформа для микросервисов / Антон Резников, Владимир Перепели...Tarantool как платформа для микросервисов / Антон Резников, Владимир Перепели...
Tarantool как платформа для микросервисов / Антон Резников, Владимир Перепели...
Ontico
 
Node.js - Best practices
Node.js  - Best practicesNode.js  - Best practices
Node.js - Best practices
Felix Geisendörfer
 
Distributed app development with nodejs and zeromq
Distributed app development with nodejs and zeromqDistributed app development with nodejs and zeromq
Distributed app development with nodejs and zeromq
Ruben Tan
 
Odoo Online platform: architecture and challenges
Odoo Online platform: architecture and challengesOdoo Online platform: architecture and challenges
Odoo Online platform: architecture and challenges
Odoo
 
tdc2012
tdc2012tdc2012
tdc2012
Juan Lopes
 

What's hot (20)

Streams are Awesome - (Node.js) TimesOpen Sep 2012
Streams are Awesome - (Node.js) TimesOpen Sep 2012 Streams are Awesome - (Node.js) TimesOpen Sep 2012
Streams are Awesome - (Node.js) TimesOpen Sep 2012
 
Как построить видеоплатформу на 200 Гбитс / Ольховченков Вячеслав (Integros)
Как построить видеоплатформу на 200 Гбитс / Ольховченков Вячеслав (Integros)Как построить видеоплатформу на 200 Гбитс / Ольховченков Вячеслав (Integros)
Как построить видеоплатформу на 200 Гбитс / Ольховченков Вячеслав (Integros)
 
Scaling WordPress
Scaling WordPressScaling WordPress
Scaling WordPress
 
vert.x 3.1 - be reactive on the JVM but not only in Java
vert.x 3.1 - be reactive on the JVM but not only in Javavert.x 3.1 - be reactive on the JVM but not only in Java
vert.x 3.1 - be reactive on the JVM but not only in Java
 
PostgreSQL Configuration for Humans / Alvaro Hernandez (OnGres)
PostgreSQL Configuration for Humans / Alvaro Hernandez (OnGres)PostgreSQL Configuration for Humans / Alvaro Hernandez (OnGres)
PostgreSQL Configuration for Humans / Alvaro Hernandez (OnGres)
 
HighLoad Solutions On MySQL / Xiaobin Lin (Alibaba)
HighLoad Solutions On MySQL / Xiaobin Lin (Alibaba)HighLoad Solutions On MySQL / Xiaobin Lin (Alibaba)
HighLoad Solutions On MySQL / Xiaobin Lin (Alibaba)
 
Server side JavaScript: going all the way
Server side JavaScript: going all the wayServer side JavaScript: going all the way
Server side JavaScript: going all the way
 
Servers with Event Machine - David Troy - RailsConf 2011
Servers with Event Machine - David Troy - RailsConf 2011Servers with Event Machine - David Troy - RailsConf 2011
Servers with Event Machine - David Troy - RailsConf 2011
 
Как понять, что происходит на сервере? / Александр Крижановский (NatSys Lab.,...
Как понять, что происходит на сервере? / Александр Крижановский (NatSys Lab.,...Как понять, что происходит на сервере? / Александр Крижановский (NatSys Lab.,...
Как понять, что происходит на сервере? / Александр Крижановский (NatSys Lab.,...
 
Масштабируемая конфигурация Nginx, Игорь Сысоев (Nginx)
Масштабируемая конфигурация Nginx, Игорь Сысоев (Nginx)Масштабируемая конфигурация Nginx, Игорь Сысоев (Nginx)
Масштабируемая конфигурация Nginx, Игорь Сысоев (Nginx)
 
Node.js - A Quick Tour
Node.js - A Quick TourNode.js - A Quick Tour
Node.js - A Quick Tour
 
Nodejs in Production
Nodejs in ProductionNodejs in Production
Nodejs in Production
 
Java Memory Management Tricks
Java Memory Management Tricks Java Memory Management Tricks
Java Memory Management Tricks
 
play framework async with scala
play framework async with scalaplay framework async with scala
play framework async with scala
 
Buffer overflow for Beginners
Buffer overflow for BeginnersBuffer overflow for Beginners
Buffer overflow for Beginners
 
Tarantool как платформа для микросервисов / Антон Резников, Владимир Перепели...
Tarantool как платформа для микросервисов / Антон Резников, Владимир Перепели...Tarantool как платформа для микросервисов / Антон Резников, Владимир Перепели...
Tarantool как платформа для микросервисов / Антон Резников, Владимир Перепели...
 
Node.js - Best practices
Node.js  - Best practicesNode.js  - Best practices
Node.js - Best practices
 
Distributed app development with nodejs and zeromq
Distributed app development with nodejs and zeromqDistributed app development with nodejs and zeromq
Distributed app development with nodejs and zeromq
 
Odoo Online platform: architecture and challenges
Odoo Online platform: architecture and challengesOdoo Online platform: architecture and challenges
Odoo Online platform: architecture and challenges
 
tdc2012
tdc2012tdc2012
tdc2012
 

Similar to Techniques to Improve Cache Speed

Dragoncraft Architectural Overview
Dragoncraft Architectural OverviewDragoncraft Architectural Overview
Dragoncraft Architectural Overview
jessesanford
 
Complex Made Simple: Sleep Better with TorqueBox
Complex Made Simple: Sleep Better with TorqueBoxComplex Made Simple: Sleep Better with TorqueBox
Complex Made Simple: Sleep Better with TorqueBox
bobmcwhirter
 
Python, async web frameworks, and MongoDB
Python, async web frameworks, and MongoDBPython, async web frameworks, and MongoDB
Python, async web frameworks, and MongoDB
emptysquare
 
Zend Server Data Caching
Zend Server Data CachingZend Server Data Caching
Zend Server Data Caching
El Taller Web
 
Challenges when building high profile editorial sites
Challenges when building high profile editorial sitesChallenges when building high profile editorial sites
Challenges when building high profile editorial sites
Yann Malet
 
Java one 2015 [con3339]
Java one 2015 [con3339]Java one 2015 [con3339]
Java one 2015 [con3339]
Arshal Ameen
 
Java Memory Model
Java Memory ModelJava Memory Model
Java Memory Model
Łukasz Koniecki
 
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
Wim Godden
 
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
Wim Godden
 
What the CRaC - Superfast JVM startup
What the CRaC - Superfast JVM startupWhat the CRaC - Superfast JVM startup
What the CRaC - Superfast JVM startup
Gerrit Grunwald
 
A Life of breakpoint
A Life of breakpointA Life of breakpoint
A Life of breakpoint
Hajime Morrita
 
Web Optimization Level: Paranoid
Web Optimization Level: ParanoidWeb Optimization Level: Paranoid
Web Optimization Level: Paranoid
robin_sy
 
Customize and Secure the Runtime and Dependencies of Your Procedural Language...
Customize and Secure the Runtime and Dependencies of Your Procedural Language...Customize and Secure the Runtime and Dependencies of Your Procedural Language...
Customize and Secure the Runtime and Dependencies of Your Procedural Language...
VMware Tanzu
 
Silicon Valley JUG: JVM Mechanics
Silicon Valley JUG: JVM MechanicsSilicon Valley JUG: JVM Mechanics
Silicon Valley JUG: JVM Mechanics
Azul Systems, Inc.
 
Docker and-containers-for-development-and-deployment-scale12x
Docker and-containers-for-development-and-deployment-scale12xDocker and-containers-for-development-and-deployment-scale12x
Docker and-containers-for-development-and-deployment-scale12x
rkr10
 
Clug 2012 March web server optimisation
Clug 2012 March   web server optimisationClug 2012 March   web server optimisation
Clug 2012 March web server optimisation
grooverdan
 
Where Django Caching Bust at the Seams
Where Django Caching Bust at the SeamsWhere Django Caching Bust at the Seams
Where Django Caching Bust at the Seams
Concentric Sky
 
How to make a high-quality Node.js app, Nikita Galkin
How to make a high-quality Node.js app, Nikita GalkinHow to make a high-quality Node.js app, Nikita Galkin
How to make a high-quality Node.js app, Nikita Galkin
Sigma Software
 
EVCache & Moneta (GoSF)
EVCache & Moneta (GoSF)EVCache & Moneta (GoSF)
EVCache & Moneta (GoSF)
Scott Mansfield
 
The Future starts with a Promise
The Future starts with a PromiseThe Future starts with a Promise
The Future starts with a Promise
Alexandru Nedelcu
 

Similar to Techniques to Improve Cache Speed (20)

Dragoncraft Architectural Overview
Dragoncraft Architectural OverviewDragoncraft Architectural Overview
Dragoncraft Architectural Overview
 
Complex Made Simple: Sleep Better with TorqueBox
Complex Made Simple: Sleep Better with TorqueBoxComplex Made Simple: Sleep Better with TorqueBox
Complex Made Simple: Sleep Better with TorqueBox
 
Python, async web frameworks, and MongoDB
Python, async web frameworks, and MongoDBPython, async web frameworks, and MongoDB
Python, async web frameworks, and MongoDB
 
Zend Server Data Caching
Zend Server Data CachingZend Server Data Caching
Zend Server Data Caching
 
Challenges when building high profile editorial sites
Challenges when building high profile editorial sitesChallenges when building high profile editorial sites
Challenges when building high profile editorial sites
 
Java one 2015 [con3339]
Java one 2015 [con3339]Java one 2015 [con3339]
Java one 2015 [con3339]
 
Java Memory Model
Java Memory ModelJava Memory Model
Java Memory Model
 
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
 
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
 
What the CRaC - Superfast JVM startup
What the CRaC - Superfast JVM startupWhat the CRaC - Superfast JVM startup
What the CRaC - Superfast JVM startup
 
A Life of breakpoint
A Life of breakpointA Life of breakpoint
A Life of breakpoint
 
Web Optimization Level: Paranoid
Web Optimization Level: ParanoidWeb Optimization Level: Paranoid
Web Optimization Level: Paranoid
 
Customize and Secure the Runtime and Dependencies of Your Procedural Language...
Customize and Secure the Runtime and Dependencies of Your Procedural Language...Customize and Secure the Runtime and Dependencies of Your Procedural Language...
Customize and Secure the Runtime and Dependencies of Your Procedural Language...
 
Silicon Valley JUG: JVM Mechanics
Silicon Valley JUG: JVM MechanicsSilicon Valley JUG: JVM Mechanics
Silicon Valley JUG: JVM Mechanics
 
Docker and-containers-for-development-and-deployment-scale12x
Docker and-containers-for-development-and-deployment-scale12xDocker and-containers-for-development-and-deployment-scale12x
Docker and-containers-for-development-and-deployment-scale12x
 
Clug 2012 March web server optimisation
Clug 2012 March   web server optimisationClug 2012 March   web server optimisation
Clug 2012 March web server optimisation
 
Where Django Caching Bust at the Seams
Where Django Caching Bust at the SeamsWhere Django Caching Bust at the Seams
Where Django Caching Bust at the Seams
 
How to make a high-quality Node.js app, Nikita Galkin
How to make a high-quality Node.js app, Nikita GalkinHow to make a high-quality Node.js app, Nikita Galkin
How to make a high-quality Node.js app, Nikita Galkin
 
EVCache & Moneta (GoSF)
EVCache & Moneta (GoSF)EVCache & Moneta (GoSF)
EVCache & Moneta (GoSF)
 
The Future starts with a Promise
The Future starts with a PromiseThe Future starts with a Promise
The Future starts with a Promise
 

Recently uploaded

Use PyCharm for remote debugging of WSL on a Windo cf5c162d672e4e58b4dde5d797...
Use PyCharm for remote debugging of WSL on a Windo cf5c162d672e4e58b4dde5d797...Use PyCharm for remote debugging of WSL on a Windo cf5c162d672e4e58b4dde5d797...
Use PyCharm for remote debugging of WSL on a Windo cf5c162d672e4e58b4dde5d797...
shadow0702a
 
BRAIN TUMOR DETECTION for seminar ppt.pdf
BRAIN TUMOR DETECTION for seminar ppt.pdfBRAIN TUMOR DETECTION for seminar ppt.pdf
BRAIN TUMOR DETECTION for seminar ppt.pdf
LAXMAREDDY22
 
The Python for beginners. This is an advance computer language.
The Python for beginners. This is an advance computer language.The Python for beginners. This is an advance computer language.
The Python for beginners. This is an advance computer language.
sachin chaurasia
 
Properties Railway Sleepers and Test.pptx
Properties Railway Sleepers and Test.pptxProperties Railway Sleepers and Test.pptx
Properties Railway Sleepers and Test.pptx
MDSABBIROJJAMANPAYEL
 
LLM Fine Tuning with QLoRA Cassandra Lunch 4, presented by Anant
LLM Fine Tuning with QLoRA Cassandra Lunch 4, presented by AnantLLM Fine Tuning with QLoRA Cassandra Lunch 4, presented by Anant
LLM Fine Tuning with QLoRA Cassandra Lunch 4, presented by Anant
Anant Corporation
 
ACEP Magazine edition 4th launched on 05.06.2024
ACEP Magazine edition 4th launched on 05.06.2024ACEP Magazine edition 4th launched on 05.06.2024
ACEP Magazine edition 4th launched on 05.06.2024
Rahul
 
Curve Fitting in Numerical Methods Regression
Curve Fitting in Numerical Methods RegressionCurve Fitting in Numerical Methods Regression
Curve Fitting in Numerical Methods Regression
Nada Hikmah
 
Certificates - Mahmoud Mohamed Moursi Ahmed
Certificates - Mahmoud Mohamed Moursi AhmedCertificates - Mahmoud Mohamed Moursi Ahmed
Certificates - Mahmoud Mohamed Moursi Ahmed
Mahmoud Morsy
 
一比一原版(CalArts毕业证)加利福尼亚艺术学院毕业证如何办理
一比一原版(CalArts毕业证)加利福尼亚艺术学院毕业证如何办理一比一原版(CalArts毕业证)加利福尼亚艺术学院毕业证如何办理
一比一原版(CalArts毕业证)加利福尼亚艺术学院毕业证如何办理
ecqow
 
CHINA’S GEO-ECONOMIC OUTREACH IN CENTRAL ASIAN COUNTRIES AND FUTURE PROSPECT
CHINA’S GEO-ECONOMIC OUTREACH IN CENTRAL ASIAN COUNTRIES AND FUTURE PROSPECTCHINA’S GEO-ECONOMIC OUTREACH IN CENTRAL ASIAN COUNTRIES AND FUTURE PROSPECT
CHINA’S GEO-ECONOMIC OUTREACH IN CENTRAL ASIAN COUNTRIES AND FUTURE PROSPECT
jpsjournal1
 
john krisinger-the science and history of the alcoholic beverage.pptx
john krisinger-the science and history of the alcoholic beverage.pptxjohn krisinger-the science and history of the alcoholic beverage.pptx
john krisinger-the science and history of the alcoholic beverage.pptx
Madan Karki
 
Literature Review Basics and Understanding Reference Management.pptx
Literature Review Basics and Understanding Reference Management.pptxLiterature Review Basics and Understanding Reference Management.pptx
Literature Review Basics and Understanding Reference Management.pptx
Dr Ramhari Poudyal
 
Manufacturing Process of molasses based distillery ppt.pptx
Manufacturing Process of molasses based distillery ppt.pptxManufacturing Process of molasses based distillery ppt.pptx
Manufacturing Process of molasses based distillery ppt.pptx
Madan Karki
 
CompEx~Manual~1210 (2).pdf COMPEX GAS AND VAPOURS
CompEx~Manual~1210 (2).pdf COMPEX GAS AND VAPOURSCompEx~Manual~1210 (2).pdf COMPEX GAS AND VAPOURS
CompEx~Manual~1210 (2).pdf COMPEX GAS AND VAPOURS
RamonNovais6
 
Hematology Analyzer Machine - Complete Blood Count
Hematology Analyzer Machine - Complete Blood CountHematology Analyzer Machine - Complete Blood Count
Hematology Analyzer Machine - Complete Blood Count
shahdabdulbaset
 
Introduction to AI Safety (public presentation).pptx
Introduction to AI Safety (public presentation).pptxIntroduction to AI Safety (public presentation).pptx
Introduction to AI Safety (public presentation).pptx
MiscAnnoy1
 
学校原版美国波士顿大学毕业证学历学位证书原版一模一样
学校原版美国波士顿大学毕业证学历学位证书原版一模一样学校原版美国波士顿大学毕业证学历学位证书原版一模一样
学校原版美国波士顿大学毕业证学历学位证书原版一模一样
171ticu
 
Computational Engineering IITH Presentation
Computational Engineering IITH PresentationComputational Engineering IITH Presentation
Computational Engineering IITH Presentation
co23btech11018
 
Transformers design and coooling methods
Transformers design and coooling methodsTransformers design and coooling methods
Transformers design and coooling methods
Roger Rozario
 
Comparative analysis between traditional aquaponics and reconstructed aquapon...
Comparative analysis between traditional aquaponics and reconstructed aquapon...Comparative analysis between traditional aquaponics and reconstructed aquapon...
Comparative analysis between traditional aquaponics and reconstructed aquapon...
bijceesjournal
 

Recently uploaded (20)

Use PyCharm for remote debugging of WSL on a Windo cf5c162d672e4e58b4dde5d797...
Use PyCharm for remote debugging of WSL on a Windo cf5c162d672e4e58b4dde5d797...Use PyCharm for remote debugging of WSL on a Windo cf5c162d672e4e58b4dde5d797...
Use PyCharm for remote debugging of WSL on a Windo cf5c162d672e4e58b4dde5d797...
 
BRAIN TUMOR DETECTION for seminar ppt.pdf
BRAIN TUMOR DETECTION for seminar ppt.pdfBRAIN TUMOR DETECTION for seminar ppt.pdf
BRAIN TUMOR DETECTION for seminar ppt.pdf
 
The Python for beginners. This is an advance computer language.
The Python for beginners. This is an advance computer language.The Python for beginners. This is an advance computer language.
The Python for beginners. This is an advance computer language.
 
Properties Railway Sleepers and Test.pptx
Properties Railway Sleepers and Test.pptxProperties Railway Sleepers and Test.pptx
Properties Railway Sleepers and Test.pptx
 
LLM Fine Tuning with QLoRA Cassandra Lunch 4, presented by Anant
LLM Fine Tuning with QLoRA Cassandra Lunch 4, presented by AnantLLM Fine Tuning with QLoRA Cassandra Lunch 4, presented by Anant
LLM Fine Tuning with QLoRA Cassandra Lunch 4, presented by Anant
 
ACEP Magazine edition 4th launched on 05.06.2024
ACEP Magazine edition 4th launched on 05.06.2024ACEP Magazine edition 4th launched on 05.06.2024
ACEP Magazine edition 4th launched on 05.06.2024
 
Curve Fitting in Numerical Methods Regression
Curve Fitting in Numerical Methods RegressionCurve Fitting in Numerical Methods Regression
Curve Fitting in Numerical Methods Regression
 
Certificates - Mahmoud Mohamed Moursi Ahmed
Certificates - Mahmoud Mohamed Moursi AhmedCertificates - Mahmoud Mohamed Moursi Ahmed
Certificates - Mahmoud Mohamed Moursi Ahmed
 
一比一原版(CalArts毕业证)加利福尼亚艺术学院毕业证如何办理
一比一原版(CalArts毕业证)加利福尼亚艺术学院毕业证如何办理一比一原版(CalArts毕业证)加利福尼亚艺术学院毕业证如何办理
一比一原版(CalArts毕业证)加利福尼亚艺术学院毕业证如何办理
 
CHINA’S GEO-ECONOMIC OUTREACH IN CENTRAL ASIAN COUNTRIES AND FUTURE PROSPECT
CHINA’S GEO-ECONOMIC OUTREACH IN CENTRAL ASIAN COUNTRIES AND FUTURE PROSPECTCHINA’S GEO-ECONOMIC OUTREACH IN CENTRAL ASIAN COUNTRIES AND FUTURE PROSPECT
CHINA’S GEO-ECONOMIC OUTREACH IN CENTRAL ASIAN COUNTRIES AND FUTURE PROSPECT
 
john krisinger-the science and history of the alcoholic beverage.pptx
john krisinger-the science and history of the alcoholic beverage.pptxjohn krisinger-the science and history of the alcoholic beverage.pptx
john krisinger-the science and history of the alcoholic beverage.pptx
 
Literature Review Basics and Understanding Reference Management.pptx
Literature Review Basics and Understanding Reference Management.pptxLiterature Review Basics and Understanding Reference Management.pptx
Literature Review Basics and Understanding Reference Management.pptx
 
Manufacturing Process of molasses based distillery ppt.pptx
Manufacturing Process of molasses based distillery ppt.pptxManufacturing Process of molasses based distillery ppt.pptx
Manufacturing Process of molasses based distillery ppt.pptx
 
CompEx~Manual~1210 (2).pdf COMPEX GAS AND VAPOURS
CompEx~Manual~1210 (2).pdf COMPEX GAS AND VAPOURSCompEx~Manual~1210 (2).pdf COMPEX GAS AND VAPOURS
CompEx~Manual~1210 (2).pdf COMPEX GAS AND VAPOURS
 
Hematology Analyzer Machine - Complete Blood Count
Hematology Analyzer Machine - Complete Blood CountHematology Analyzer Machine - Complete Blood Count
Hematology Analyzer Machine - Complete Blood Count
 
Introduction to AI Safety (public presentation).pptx
Introduction to AI Safety (public presentation).pptxIntroduction to AI Safety (public presentation).pptx
Introduction to AI Safety (public presentation).pptx
 
学校原版美国波士顿大学毕业证学历学位证书原版一模一样
学校原版美国波士顿大学毕业证学历学位证书原版一模一样学校原版美国波士顿大学毕业证学历学位证书原版一模一样
学校原版美国波士顿大学毕业证学历学位证书原版一模一样
 
Computational Engineering IITH Presentation
Computational Engineering IITH PresentationComputational Engineering IITH Presentation
Computational Engineering IITH Presentation
 
Transformers design and coooling methods
Transformers design and coooling methodsTransformers design and coooling methods
Transformers design and coooling methods
 
Comparative analysis between traditional aquaponics and reconstructed aquapon...
Comparative analysis between traditional aquaponics and reconstructed aquapon...Comparative analysis between traditional aquaponics and reconstructed aquapon...
Comparative analysis between traditional aquaponics and reconstructed aquapon...
 

Techniques to Improve Cache Speed

  • 1. PRESENTED BY Techniques to Improve Cache Speed Zohaib Sibte Hassan DoorDash, Technical Lead
  • 2. PRESENTED BY About me Zohaib Sibte Hassan Technical Lead at DoorDash Dreamer, hacker, philosopher, troublemaker, loves open source. @zohaibility
  • 5. PRESENTED BY A tale of reducing tail latency
  • 9. PRESENTED BY Fixing stampede ● Consider key expired a in fixed random (gap) before expiry time. ● Store timestamp (timestamp) with value. ● Set TTL on key (ttl) on Redis. ● Consider key expired if: timestamp + ttl + (rand() * gap) > now() RANDOM AHEAD OF TIME EVICTION
  • 10. Can we do better?
  • 11. PRESENTED BY Optimal Probabilistic Cache Stampede Prevention http://www.vldb.org/pvldb/vol8/p886-vattani.pdf
  • 14. PRESENTED BY Implementation def get_if_not_aot_expired(entry, expiry_time_window): from math import log from random import random import time expiry_ts, value = entry current_ts = int(time.time()) predictive_expire_gap = expiry_time_window * log(random()) # predictive_expire_delta is always -ve due to log(0 .. 1) if current_ts - predictive_expire_gap >= expiry_ts: return None return value
  • 15.
  • 17. PRESENTED BY Under high traffic load similar cache stampede/miss-storm can be observed between L1 & L2 cache (and so on)
  • 19. PRESENTED BY We took inspiration from frontend world (debounce) and exploited promises* * Also known as Deferred, Task, Future etc.
  • 20. PRESENTED BY How ● Every reader provides a function (L1_MISS_FUNCTION) that returns a promise. Usually this function will read L2 or DB (if L2 miss happens). ● When invoked via debouncer with a key (ID), only first reader is allowed to execute its L1_MISS_FUNCTION which immediately returning back a promise. ● Rest of the readers coming in (while promise has not been resolved), are immediately returned back the promise returned from first call to L1_MISS_FUNCTION. ● All readers await on the returned promise to read the value. ● Subsequent calls with ID will call L1_MISS_FUNCTION as soon as promise has been resolved. ANATOMY OF OUR DEBOUNCING
  • 21. PRESENTED BY Implementation class Debouncer { constructor() { this.pendingBoard = {}; } async debounce(id, callback) { if (this.pendingBoard[id] !== undefined) { return await this.pendingBoard[id]; } this.pendingBoard[id] = callback(id); try { return await this.pendingBoard[id]; } finally { delete this.pendingBoard[id]; } } } const debouncer = new Debouncer(); async function menuItemLoader(key) { // Read from Redis/DB } // After cache miss const menu = await debouncer.debounce( `menu-${id}`, menuItemLoader );
  • 22. We wrote a simulator https://repl.it/@x0a1b/DebounceSimulator
  • 23. PRESENTED BY OTHER IMPLEMENTATIONS LoadingCache<Key, Graph> graphs = Caffeine.newBuilder() .maximumSize(10_000) .expireAfterWrite(5, TimeUnit.MINUTES) .refreshAfterWrite(1, TimeUnit.MINUTES) .build(key -> createExpensiveGraph(key)); Caffeine cache
  • 24. PRESENTED BY WITHOUT DEBOUNCING Stress test Summary: Count: 1053108 Total: 60769.34 ms Slowest: 8058.86 ms Fastest: 0.38 ms Average: 114.43 ms Requests/sec: 17329.60 Summary: Count: 1321340 Total: 60064.00 ms Slowest: 578.69 ms Fastest: 36.04 ms Average: 90.77 ms Requests/sec: 21998.87 WITH DEBOUNCING The GRPC endpoint being tested is performing a full read through operation ranging from an L1 cache (5 seconds TTL), an L2 cache (10 seconds TTL) and finally falling back to our Postgres database (1 second AOT eviction). We used ghz to benchmark our service of 2 pods for 60 seconds with 2000 concurrent connections and no rate limit.
  • 26. PRESENTED BY Why? ● Caching precompiled payloads (e.g. views, menus). ● ML models. ● Message queues or events. ● Even more use-cases with Redis stream message payloads. WHY WOULD YOU NEED TO STORE LARGE PAYLOADS
  • 27. PRESENTED BY Took a page from HTTP, and decided to use compression.
  • 28. PRESENTED BY Considerations COMPRESSION RATIO Should provide a decent compression ratio. LIGHTWEIGHT Light on CPU and footprint STABLE Stable, well tested, and well maintained
  • 29. PRESENTED BY Meet lzbench ● https://github.com/inikep/lzbench ● https://morotti.github.io/lzbench-web/ - Nice UI with set of pre-benchmarked results. ● Compression is dependent upon data. BENCHMARKING COMPRESSORS
  • 30. Techniques to Improve Cache Speed Our scenario ● 64,220 bytes of Chick-fil-A menu (serialized JSON) ● 350,333 bytes of Cheesecake factory (serialized JSON)
  • 31. Techniques to Improve Cache Speed Observations ● On average LZ4 had slightly higher compression ratio than Snappy i.e. while compressing our serialized payloads, on average LZ4 was 38.54% vs. 39.71% of Snappy compression ratio. ● Compression speeds of LZ4, and Snappy were almost the same. LZ4 was fractionally slower than Snappy. ● LZ4 was hands down faster than Snappy for decompression. In some cases we found it to be 2x faster than Snappy.
  • 32. Techniques to Improve Cache Speed Redis Operation No Compression (seconds) Snappy (seconds) LZ4 (seconds) Set (10000) 16.526179 12.635553 12.802149 Get (10000) 12.047090 07.560119 06.434711 Benchmarks
  • 33. Techniques to Improve Cache Speed Results
  • 34. Techniques to Improve Cache Speed Results

Editor's Notes

  1. Strong commitment to quality and operational excellence Merchant first approach Making consumers keep coming back
  2. For write through cache, imagine two servers reading out same key, resulting in a cache miss and then going to database not only doing duplicate reads but also doing duplicate writes to update the read entry.