SlideShare a Scribd company logo
Caching
Memcached vs. Redis
        San Francisco MySQL Meetup

                        Ryan Lowe
                       Erin O’Neill




                                      1
Databases

  WE LOVE THEM
         ...
Except when we don’t




                       2
When Databases Rule
• Many access patterns on the same set of
  data
• Transactions (both monetary and isolated
  units of work)
• Don’t know what the end state access
  patterns will be
• Always :)
                                             3
When Databases Suck

• Lots of concurrent users
• ORMs
• Big Data Sets
• Small Pockets of VERY hot data

                                   4
How Caching Works

• External vs. built-in caching
• MySQL Query Cache
• InnoDB Buffer Pool
• Rails SOMETHING

                                  5
Caching Architecture


     Becomes




                       6
Why Caching Works




                    7
8
9
There are only two hard
problems in Computer
Science: cache invalidation,
naming things, and off-by-
one errors.

            -- Martin Fowler

                               10
Problems with Caching
• Cache Misses
• Thundering Herd
• Stale Data
• Warm-Up Times
• Overly-Aggressive Caching
• Poor Cache Design
                              11
Cache Misses


    Cache Hit: 1 Operation
    Cache Miss: 3 Operations




                               12
Thundering Herd

• Key TOP_10_VIDEOS expires @ 9:00
• Generating the K/V takes three seconds
• Page gets 100 req/s = 100*3 = 300 threads!


                                               13
Stale Data

• Must maintain consistency between the
  database and the cache from within the
  application
• Extremely difficult to validate correctness


                                               14
Cache Warm-Up

• All attempts to read from the cache are
  CACHE MISSES, which require three
  operations.
• This can result in a significant degradation
  of response time.
• Usually accompanied by a Thundering Herd

                                                15
Use Cases
• Sessions           • Tag Clouds
• Popular Items      • Auto-suggest lists
• Full Page Cache    • Relationships
• Profile             • User Information
  Information
                     • Online Users
• User Preferences   • Statistics
                                            16
Memcached

Memcached is an in-memory key-
value store for small chunks of
arbitrary data (strings, objects) from
results of database calls, API calls,
or page rendering.



                                         17
Redis

Redis is an open source, advanced
key-value store. It is often referred
to as a “data structure server” since
keys can contain strings, hashes,
lists, sets and sorted sets.



                                        18
In-Memory Means
We’re Bound By RAM


                     19
Consistent Hashing




• Each Key deterministically goes to a
  particular server. Think (KEY % SERVERS)


                                             20
Memcached

• Dead Simple & Battle Tested
• Fast
• Non-Blocking get()/set()
• Multi-Threaded
• Consistent Hashing

                                21
Memcached Example
employee_id = 1234
employee_json = {
   name => ‘Ryan Lowe’,
   title => ‘Production Engineer’ }
set(employee_id, employee_json)
get(employee_id) [Returns employee_json]


                                           22
But I don’t want all the
         data
• What if I just want the name?
• 64 Bytes for the object vs. 10 for just the
  name :-(
• 6x network traffic
• More work for the application
• Fatter applications
                                                23
Redis

• Advanced Data Types
• Replication
• Persistence
• Usually Fast
• Very Cool Atomic Operations

                                24
Redis: The Bad
• Single-Threaded
• Limited client support for consistent
  hashing
• Significant overhead for persistence (do be
  discussed later)
• Not widely deployed (compared to
  Memcached)


                                               25
Redis: Datatypes

• Strings (just like Memcached)
• Lists
• Sets
• Sorted Sets
• Hashes

                                  26
Redis: Lists

• Stored in sorted order
• Can push/pop
• Fast head/tail access
• Index access (yay)

                           27
Redis: Lists
r.lpush(‘employees’, ‘Ryan Lowe’)

r.lpush(‘employees’, ‘Dave Apgar’)

r.lrange(‘employees’, 0, -1)

      (‘Dave Apgar’, ‘Ryan Lowe’)

r.rpush(‘employees’, ‘Evan Miller’)

r.lrange(‘employees’, 0, -1)

      (‘Dave Apgar’, ‘Ryan Lowe’, ‘Evan Miller’)




                                                   28
Redis: Sets

• Un-ordered collections of strings
• Unique (no repeated members)
• diff, intersect, merge


                                      29
Redis: Sets

sadd(‘employees’, ‘Ryan Lowe’)

sadd(‘former_employees’, ‘Bryan Lowe’)

sdiff(‘former_employees’, ‘employees’)

      (‘Ryan Lowe’,‘Bryan Lowe’)




                                         30
Redis: Sorted Sets


• Same as Sets but ordered by a score



                                        31
Redis: Hashes
r.hset(‘employees’, ‘count’, 1234)

r.hset(‘employees’,‘females’, 1000)

r.hset(‘employees’,‘males’, 234)

hget(‘employees’,‘count’)

      “1234”

hgetall(‘employees’)

      {   ‘count’ => 1234,

          ‘females’ => 1000,

          ‘males’ => 234 }




                                      32
Memcached vs. Redis
                 Memcached   Redis
  (multi)get        ✓         ✓
  (multi)set        ✓         ✓
   incr/decr        ✓         ✓
    delete          ✓         ✓
  Expiration        ✓         ✓
prepend/append      ✓
Range Queries                 ✓
  Data Types!                 ✓
  Persistence     (sorta)     ✓
Multi-Threaded      ✓
  Replication    (sorta)      ✓



                                     33
Instrumentation
• Redis: info
• Memcached: stats

• Both give system information, connections,
  hits, misses, etc.
• Graphite most of the metrics!!!
                                               34
Benchmarks



             35
About the Benchmarks
• 1 Hour
• Redis 2.6 & Memcached 1.4.5
• 64,000,000 Keys
  "KEY_#{i.to_s}"


• 51-Character Values
  (0...50).map{ ('a'..'z').to_a[rand(26)] }.join




                                                   36
Redis Benchmarks



                   37
Redis Set (1 Server)
        1 Client     2 Clients    4 Clients    8 Clients
        12 Clients   16 Clients   24 Clients   32 Clients

12000
10500
 9000
 7500
 6000
 4500
 3000
 1500
    0




                                                            38
Redis Set (1 Server)
        1 Client     2 Clients    4 Clients    8 Clients
        12 Clients   16 Clients   24 Clients   32 Clients

12000
                WTF?!
10500
 9000
 7500
 6000
 4500
 3000
 1500
    0




                                                            39
Redis Set (1 Server)
        1 Client     2 Clients    4 Clients    8 Clients
        12 Clients   16 Clients   24 Clients

10000

 8000

 6000

 4000

 2000

    0




                                                           40
Redis Set (2 Servers)
        1 Client     2 Clients    4 Clients    8 Clients
        12 Clients   16 Clients   24 Clients   32 Clients

16000


12000


 8000


 4000


    0




                                                            41
Redis Set (2 Servers)
        1 Client     2 Clients    4 Clients    8 Clients
        12 Clients   16 Clients   24 Clients   32 Clients

16000


12000


 8000                                          WTF?!

 4000


    0




                                                            42
Redis Set (4 Servers)
        1 Client     2 Clients    4 Clients    8 Clients
        12 Clients   16 Clients   24 Clients   32 Clients

16000


12000


 8000


 4000


    0




                                                            43
Redis Set (8 Servers)
        1 Client     2 Clients    4 Clients    8 Clients
        12 Clients   16 Clients   24 Clients   32 Clients

16000


12000


 8000


 4000


    0




                                                            44
Hash Ring Balance (%)
                          Server 1   Server 2
100




 50




  0
      Redis   Memcached




                                                45
Hash Ring Balance (%)
     Server 1       Server 2       Server 3   Server 4
50




25




 0
            Redis          Memcached




                                                         46
Hash Ring Balance (%)
  Server 1      Server 2    Server 3   Server 4   Server 5
  Server 6      Server 7    Server 8
 25




12.5




  0
             Redis         Memcached




                                                             47
Redis Get (1 Server)
         1 Client     2 Clients    4 Clients    8 Clients
         12 Clients   16 Clients   24 Clients   32 Clients

125000

100000

 75000

 50000

 25000

     0




                                                             48
Redis Get (2 Servers)
         1 Client     2 Clients    4 Clients    8 Clients
         12 Clients   16 Clients   24 Clients   32 Clients

125000

100000

 75000

 50000

 25000

     0




                                                             49
Redis Get (4 Servers)
         1 Client     2 Clients    4 Clients    8 Clients
         12 Clients   16 Clients   24 Clients   32 Clients

125000

100000

 75000

 50000

 25000

     0




                                                             50
Redis Get (8 Servers)
         1 Client     2 Clients    4 Clients    8 Clients
         12 Clients   16 Clients   24 Clients   32 Clients

125000

100000

 75000

 50000

 25000

     0




                                                             51
The Cost of
                    Persistence
        Redis No Persistence   Redis BGSAVE (FIO)   Redis AOF



12000


10000


 8000


 6000


 4000




                                                                52
Redis & Memcached
   Benchmarks


                    53
Set Operations
        (1 Server, 24 Clients)
                      Memcached   Redis

10000

 9825

 9650

 9475

 9300




                                          54
Get Operations
         (1 Server, 24 Clients)
                       Memcached   Redis

130000

117500

105000

 92500

 80000




                                           55
Set Operations
        (2 Servers, 24 Clients)
                      Memcached   Redis

13000

11750

10500

 9250

 8000




                                          56
Get Operations
         (2 Servers, 24 Clients)
                       Memcached   Redis

140000

107000

 74000

 41000

  8000




                                           57
Set Operations
        (4 Servers, 24 Clients)
                      Memcached   Redis

13000

11750

10500

 9250

 8000




                                          58
Get Operations
         (4 Servers, 24 Clients)
                       Memcached   Redis

140000

107000

 74000

 41000

  8000




                                           59
Set Operations
        (8 Servers, 24 Clients)
                      Memcached   Redis

12000

11000

10000

 9000

 8000




                                          60
Get Operations
         (8 Servers, 24 Clients)
                       Memcached   Redis

150000

114500

 79000

 43500

  8000




                                           61
Conclusions

• Redis inconsistent under heavy load
• We need more benchmarks!
 • (Redis) Datatype-specific
 • Big Memory
 • (Redis) Big Keys

                                        62
Questions?



             63

More Related Content

What's hot

Boosting Machine Learning with Redis Modules and Spark
Boosting Machine Learning with Redis Modules and SparkBoosting Machine Learning with Redis Modules and Spark
Boosting Machine Learning with Redis Modules and Spark
Dvir Volk
 
Cassandra as Memcache
Cassandra as MemcacheCassandra as Memcache
Cassandra as Memcache
Edward Capriolo
 
Everything you always wanted to know about Redis but were afraid to ask
Everything you always wanted to know about Redis but were afraid to askEverything you always wanted to know about Redis but were afraid to ask
Everything you always wanted to know about Redis but were afraid to ask
Carlos Abalde
 
Introduction to Redis
Introduction to RedisIntroduction to Redis
Introduction to RedisDvir Volk
 
Bulk Loading into Cassandra
Bulk Loading into CassandraBulk Loading into Cassandra
Bulk Loading into Cassandra
Brian Hess
 
Implementing High Availability Caching with Memcached
Implementing High Availability Caching with MemcachedImplementing High Availability Caching with Memcached
Implementing High Availability Caching with Memcached
Gear6
 
Redis Functions, Data Structures for Web Scale Apps
Redis Functions, Data Structures for Web Scale AppsRedis Functions, Data Structures for Web Scale Apps
Redis Functions, Data Structures for Web Scale Apps
Dave Nielsen
 
How Prometheus Store the Data
How Prometheus Store the DataHow Prometheus Store the Data
How Prometheus Store the Data
Hao Chen
 
Building better Node.js applications on MariaDB
Building better Node.js applications on MariaDBBuilding better Node.js applications on MariaDB
Building better Node.js applications on MariaDB
MariaDB plc
 
Building Scalable, Distributed Job Queues with Redis and Redis::Client
Building Scalable, Distributed Job Queues with Redis and Redis::ClientBuilding Scalable, Distributed Job Queues with Redis and Redis::Client
Building Scalable, Distributed Job Queues with Redis and Redis::Client
Mike Friedman
 
Evaluating NoSQL Performance: Time for Benchmarking
Evaluating NoSQL Performance: Time for BenchmarkingEvaluating NoSQL Performance: Time for Benchmarking
Evaluating NoSQL Performance: Time for BenchmarkingSergey Bushik
 
This is redis - feature and usecase
This is redis - feature and usecaseThis is redis - feature and usecase
This is redis - feature and usecase
Kris Jeong
 
Redis modules 101
Redis modules 101Redis modules 101
Redis modules 101
Dvir Volk
 
The Google Chubby lock service for loosely-coupled distributed systems
The Google Chubby lock service for loosely-coupled distributed systemsThe Google Chubby lock service for loosely-coupled distributed systems
The Google Chubby lock service for loosely-coupled distributed systems
Romain Jacotin
 
Using advanced options in MariaDB Connector/J
Using advanced options in MariaDB Connector/JUsing advanced options in MariaDB Connector/J
Using advanced options in MariaDB Connector/J
MariaDB plc
 
Hadoop - Lessons Learned
Hadoop - Lessons LearnedHadoop - Lessons Learned
Hadoop - Lessons Learned
tcurdt
 
HBaseCon 2015: HBase Performance Tuning @ Salesforce
HBaseCon 2015: HBase Performance Tuning @ SalesforceHBaseCon 2015: HBase Performance Tuning @ Salesforce
HBaseCon 2015: HBase Performance Tuning @ Salesforce
HBaseCon
 
Plny12 galera-cluster-best-practices
Plny12 galera-cluster-best-practicesPlny12 galera-cluster-best-practices
Plny12 galera-cluster-best-practicesDimas Prasetyo
 

What's hot (20)

Boosting Machine Learning with Redis Modules and Spark
Boosting Machine Learning with Redis Modules and SparkBoosting Machine Learning with Redis Modules and Spark
Boosting Machine Learning with Redis Modules and Spark
 
Cassandra as Memcache
Cassandra as MemcacheCassandra as Memcache
Cassandra as Memcache
 
Memcached
MemcachedMemcached
Memcached
 
Everything you always wanted to know about Redis but were afraid to ask
Everything you always wanted to know about Redis but were afraid to askEverything you always wanted to know about Redis but were afraid to ask
Everything you always wanted to know about Redis but were afraid to ask
 
Introduction to Redis
Introduction to RedisIntroduction to Redis
Introduction to Redis
 
Bulk Loading into Cassandra
Bulk Loading into CassandraBulk Loading into Cassandra
Bulk Loading into Cassandra
 
Implementing High Availability Caching with Memcached
Implementing High Availability Caching with MemcachedImplementing High Availability Caching with Memcached
Implementing High Availability Caching with Memcached
 
Redis Functions, Data Structures for Web Scale Apps
Redis Functions, Data Structures for Web Scale AppsRedis Functions, Data Structures for Web Scale Apps
Redis Functions, Data Structures for Web Scale Apps
 
How Prometheus Store the Data
How Prometheus Store the DataHow Prometheus Store the Data
How Prometheus Store the Data
 
Building better Node.js applications on MariaDB
Building better Node.js applications on MariaDBBuilding better Node.js applications on MariaDB
Building better Node.js applications on MariaDB
 
Building Scalable, Distributed Job Queues with Redis and Redis::Client
Building Scalable, Distributed Job Queues with Redis and Redis::ClientBuilding Scalable, Distributed Job Queues with Redis and Redis::Client
Building Scalable, Distributed Job Queues with Redis and Redis::Client
 
Redis acc
Redis accRedis acc
Redis acc
 
Evaluating NoSQL Performance: Time for Benchmarking
Evaluating NoSQL Performance: Time for BenchmarkingEvaluating NoSQL Performance: Time for Benchmarking
Evaluating NoSQL Performance: Time for Benchmarking
 
This is redis - feature and usecase
This is redis - feature and usecaseThis is redis - feature and usecase
This is redis - feature and usecase
 
Redis modules 101
Redis modules 101Redis modules 101
Redis modules 101
 
The Google Chubby lock service for loosely-coupled distributed systems
The Google Chubby lock service for loosely-coupled distributed systemsThe Google Chubby lock service for loosely-coupled distributed systems
The Google Chubby lock service for loosely-coupled distributed systems
 
Using advanced options in MariaDB Connector/J
Using advanced options in MariaDB Connector/JUsing advanced options in MariaDB Connector/J
Using advanced options in MariaDB Connector/J
 
Hadoop - Lessons Learned
Hadoop - Lessons LearnedHadoop - Lessons Learned
Hadoop - Lessons Learned
 
HBaseCon 2015: HBase Performance Tuning @ Salesforce
HBaseCon 2015: HBase Performance Tuning @ SalesforceHBaseCon 2015: HBase Performance Tuning @ Salesforce
HBaseCon 2015: HBase Performance Tuning @ Salesforce
 
Plny12 galera-cluster-best-practices
Plny12 galera-cluster-best-practicesPlny12 galera-cluster-best-practices
Plny12 galera-cluster-best-practices
 

Similar to Redis memcached pdf

Cassandra under the hood
Cassandra under the hoodCassandra under the hood
Cassandra under the hood
Andriy Rymar
 
Introduction to NoSQL
Introduction to NoSQLIntroduction to NoSQL
Introduction to NoSQL
Yan Cui
 
What's new with enterprise Redis - Leena Joshi, Redis Labs
What's new with enterprise Redis - Leena Joshi, Redis LabsWhat's new with enterprise Redis - Leena Joshi, Redis Labs
What's new with enterprise Redis - Leena Joshi, Redis Labs
Redis Labs
 
MySQL Cluster Scaling to a Billion Queries
MySQL Cluster Scaling to a Billion QueriesMySQL Cluster Scaling to a Billion Queries
MySQL Cluster Scaling to a Billion Queries
Bernd Ocklin
 
Troubleshooting Redis- DaeMyung Kang, Kakao
Troubleshooting Redis- DaeMyung Kang, KakaoTroubleshooting Redis- DaeMyung Kang, Kakao
Troubleshooting Redis- DaeMyung Kang, Kakao
Redis Labs
 
Troubleshooting redis
Troubleshooting redisTroubleshooting redis
Troubleshooting redis
DaeMyung Kang
 
Redis - N✮SQL Berlin
Redis - N✮SQL BerlinRedis - N✮SQL Berlin
Redis - N✮SQL Berlin
mattmatt
 
Hadoop Overview kdd2011
Hadoop Overview kdd2011Hadoop Overview kdd2011
Hadoop Overview kdd2011
Milind Bhandarkar
 
20140614 introduction to spark-ben white
20140614 introduction to spark-ben white20140614 introduction to spark-ben white
20140614 introduction to spark-ben white
Data Con LA
 
Redis Everywhere - Sunshine PHP
Redis Everywhere - Sunshine PHPRedis Everywhere - Sunshine PHP
Redis Everywhere - Sunshine PHPRicard Clau
 
Hadoop Robot from eBay at China Hadoop Summit 2015
Hadoop Robot from eBay at China Hadoop Summit 2015Hadoop Robot from eBay at China Hadoop Summit 2015
Hadoop Robot from eBay at China Hadoop Summit 2015
polo li
 
High-Performance Storage Services with HailDB and Java
High-Performance Storage Services with HailDB and JavaHigh-Performance Storage Services with HailDB and Java
High-Performance Storage Services with HailDB and Java
sunnygleason
 
Hadoop & no sql new generation database systems
Hadoop & no sql   new generation database systemsHadoop & no sql   new generation database systems
Hadoop & no sql new generation database systemsramazan fırın
 
Introduction to Hadoop
Introduction to HadoopIntroduction to Hadoop
Introduction to Hadoop
York University
 
KeyValue Stores
KeyValue StoresKeyValue Stores
KeyValue Stores
Mauro Pompilio
 
Fixing twitter
Fixing twitterFixing twitter
Fixing twitter
Roger Xia
 
Fixing Twitter Improving The Performance And Scalability Of The Worlds Most ...
Fixing Twitter  Improving The Performance And Scalability Of The Worlds Most ...Fixing Twitter  Improving The Performance And Scalability Of The Worlds Most ...
Fixing Twitter Improving The Performance And Scalability Of The Worlds Most ...
smallerror
 
Fixing Twitter Improving The Performance And Scalability Of The Worlds Most ...
Fixing Twitter  Improving The Performance And Scalability Of The Worlds Most ...Fixing Twitter  Improving The Performance And Scalability Of The Worlds Most ...
Fixing Twitter Improving The Performance And Scalability Of The Worlds Most ...xlight
 
10 Ways to Scale with Redis - LA Redis Meetup 2019
10 Ways to Scale with Redis - LA Redis Meetup 201910 Ways to Scale with Redis - LA Redis Meetup 2019
10 Ways to Scale with Redis - LA Redis Meetup 2019
Dave Nielsen
 

Similar to Redis memcached pdf (20)

Cassandra under the hood
Cassandra under the hoodCassandra under the hood
Cassandra under the hood
 
Introduction to NoSQL
Introduction to NoSQLIntroduction to NoSQL
Introduction to NoSQL
 
What's new with enterprise Redis - Leena Joshi, Redis Labs
What's new with enterprise Redis - Leena Joshi, Redis LabsWhat's new with enterprise Redis - Leena Joshi, Redis Labs
What's new with enterprise Redis - Leena Joshi, Redis Labs
 
MySQL Cluster Scaling to a Billion Queries
MySQL Cluster Scaling to a Billion QueriesMySQL Cluster Scaling to a Billion Queries
MySQL Cluster Scaling to a Billion Queries
 
Troubleshooting Redis- DaeMyung Kang, Kakao
Troubleshooting Redis- DaeMyung Kang, KakaoTroubleshooting Redis- DaeMyung Kang, Kakao
Troubleshooting Redis- DaeMyung Kang, Kakao
 
Troubleshooting redis
Troubleshooting redisTroubleshooting redis
Troubleshooting redis
 
Redis - N✮SQL Berlin
Redis - N✮SQL BerlinRedis - N✮SQL Berlin
Redis - N✮SQL Berlin
 
Hadoop Overview kdd2011
Hadoop Overview kdd2011Hadoop Overview kdd2011
Hadoop Overview kdd2011
 
20140614 introduction to spark-ben white
20140614 introduction to spark-ben white20140614 introduction to spark-ben white
20140614 introduction to spark-ben white
 
Redis Everywhere - Sunshine PHP
Redis Everywhere - Sunshine PHPRedis Everywhere - Sunshine PHP
Redis Everywhere - Sunshine PHP
 
Hadoop Robot from eBay at China Hadoop Summit 2015
Hadoop Robot from eBay at China Hadoop Summit 2015Hadoop Robot from eBay at China Hadoop Summit 2015
Hadoop Robot from eBay at China Hadoop Summit 2015
 
High-Performance Storage Services with HailDB and Java
High-Performance Storage Services with HailDB and JavaHigh-Performance Storage Services with HailDB and Java
High-Performance Storage Services with HailDB and Java
 
Hadoop & no sql new generation database systems
Hadoop & no sql   new generation database systemsHadoop & no sql   new generation database systems
Hadoop & no sql new generation database systems
 
Introduction to Hadoop
Introduction to HadoopIntroduction to Hadoop
Introduction to Hadoop
 
KeyValue Stores
KeyValue StoresKeyValue Stores
KeyValue Stores
 
Fixing twitter
Fixing twitterFixing twitter
Fixing twitter
 
Fixing_Twitter
Fixing_TwitterFixing_Twitter
Fixing_Twitter
 
Fixing Twitter Improving The Performance And Scalability Of The Worlds Most ...
Fixing Twitter  Improving The Performance And Scalability Of The Worlds Most ...Fixing Twitter  Improving The Performance And Scalability Of The Worlds Most ...
Fixing Twitter Improving The Performance And Scalability Of The Worlds Most ...
 
Fixing Twitter Improving The Performance And Scalability Of The Worlds Most ...
Fixing Twitter  Improving The Performance And Scalability Of The Worlds Most ...Fixing Twitter  Improving The Performance And Scalability Of The Worlds Most ...
Fixing Twitter Improving The Performance And Scalability Of The Worlds Most ...
 
10 Ways to Scale with Redis - LA Redis Meetup 2019
10 Ways to Scale with Redis - LA Redis Meetup 201910 Ways to Scale with Redis - LA Redis Meetup 2019
10 Ways to Scale with Redis - LA Redis Meetup 2019
 

Recently uploaded

Assuring Contact Center Experiences for Your Customers With ThousandEyes
Assuring Contact Center Experiences for Your Customers With ThousandEyesAssuring Contact Center Experiences for Your Customers With ThousandEyes
Assuring Contact Center Experiences for Your Customers With ThousandEyes
ThousandEyes
 
Transcript: Selling digital books in 2024: Insights from industry leaders - T...
Transcript: Selling digital books in 2024: Insights from industry leaders - T...Transcript: Selling digital books in 2024: Insights from industry leaders - T...
Transcript: Selling digital books in 2024: Insights from industry leaders - T...
BookNet Canada
 
Epistemic Interaction - tuning interfaces to provide information for AI support
Epistemic Interaction - tuning interfaces to provide information for AI supportEpistemic Interaction - tuning interfaces to provide information for AI support
Epistemic Interaction - tuning interfaces to provide information for AI support
Alan Dix
 
The Future of Platform Engineering
The Future of Platform EngineeringThe Future of Platform Engineering
The Future of Platform Engineering
Jemma Hussein Allen
 
Accelerate your Kubernetes clusters with Varnish Caching
Accelerate your Kubernetes clusters with Varnish CachingAccelerate your Kubernetes clusters with Varnish Caching
Accelerate your Kubernetes clusters with Varnish Caching
Thijs Feryn
 
Unsubscribed: Combat Subscription Fatigue With a Membership Mentality by Head...
Unsubscribed: Combat Subscription Fatigue With a Membership Mentality by Head...Unsubscribed: Combat Subscription Fatigue With a Membership Mentality by Head...
Unsubscribed: Combat Subscription Fatigue With a Membership Mentality by Head...
Product School
 
FIDO Alliance Osaka Seminar: FIDO Security Aspects.pdf
FIDO Alliance Osaka Seminar: FIDO Security Aspects.pdfFIDO Alliance Osaka Seminar: FIDO Security Aspects.pdf
FIDO Alliance Osaka Seminar: FIDO Security Aspects.pdf
FIDO Alliance
 
JMeter webinar - integration with InfluxDB and Grafana
JMeter webinar - integration with InfluxDB and GrafanaJMeter webinar - integration with InfluxDB and Grafana
JMeter webinar - integration with InfluxDB and Grafana
RTTS
 
Leading Change strategies and insights for effective change management pdf 1.pdf
Leading Change strategies and insights for effective change management pdf 1.pdfLeading Change strategies and insights for effective change management pdf 1.pdf
Leading Change strategies and insights for effective change management pdf 1.pdf
OnBoard
 
DevOps and Testing slides at DASA Connect
DevOps and Testing slides at DASA ConnectDevOps and Testing slides at DASA Connect
DevOps and Testing slides at DASA Connect
Kari Kakkonen
 
State of ICS and IoT Cyber Threat Landscape Report 2024 preview
State of ICS and IoT Cyber Threat Landscape Report 2024 previewState of ICS and IoT Cyber Threat Landscape Report 2024 preview
State of ICS and IoT Cyber Threat Landscape Report 2024 preview
Prayukth K V
 
AI for Every Business: Unlocking Your Product's Universal Potential by VP of ...
AI for Every Business: Unlocking Your Product's Universal Potential by VP of ...AI for Every Business: Unlocking Your Product's Universal Potential by VP of ...
AI for Every Business: Unlocking Your Product's Universal Potential by VP of ...
Product School
 
UiPath Test Automation using UiPath Test Suite series, part 4
UiPath Test Automation using UiPath Test Suite series, part 4UiPath Test Automation using UiPath Test Suite series, part 4
UiPath Test Automation using UiPath Test Suite series, part 4
DianaGray10
 
Bits & Pixels using AI for Good.........
Bits & Pixels using AI for Good.........Bits & Pixels using AI for Good.........
Bits & Pixels using AI for Good.........
Alison B. Lowndes
 
LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...
LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...
LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...
DanBrown980551
 
To Graph or Not to Graph Knowledge Graph Architectures and LLMs
To Graph or Not to Graph Knowledge Graph Architectures and LLMsTo Graph or Not to Graph Knowledge Graph Architectures and LLMs
To Graph or Not to Graph Knowledge Graph Architectures and LLMs
Paul Groth
 
Encryption in Microsoft 365 - ExpertsLive Netherlands 2024
Encryption in Microsoft 365 - ExpertsLive Netherlands 2024Encryption in Microsoft 365 - ExpertsLive Netherlands 2024
Encryption in Microsoft 365 - ExpertsLive Netherlands 2024
Albert Hoitingh
 
FIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdf
FIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdfFIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdf
FIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdf
FIDO Alliance
 
PCI PIN Basics Webinar from the Controlcase Team
PCI PIN Basics Webinar from the Controlcase TeamPCI PIN Basics Webinar from the Controlcase Team
PCI PIN Basics Webinar from the Controlcase Team
ControlCase
 
Elevating Tactical DDD Patterns Through Object Calisthenics
Elevating Tactical DDD Patterns Through Object CalisthenicsElevating Tactical DDD Patterns Through Object Calisthenics
Elevating Tactical DDD Patterns Through Object Calisthenics
Dorra BARTAGUIZ
 

Recently uploaded (20)

Assuring Contact Center Experiences for Your Customers With ThousandEyes
Assuring Contact Center Experiences for Your Customers With ThousandEyesAssuring Contact Center Experiences for Your Customers With ThousandEyes
Assuring Contact Center Experiences for Your Customers With ThousandEyes
 
Transcript: Selling digital books in 2024: Insights from industry leaders - T...
Transcript: Selling digital books in 2024: Insights from industry leaders - T...Transcript: Selling digital books in 2024: Insights from industry leaders - T...
Transcript: Selling digital books in 2024: Insights from industry leaders - T...
 
Epistemic Interaction - tuning interfaces to provide information for AI support
Epistemic Interaction - tuning interfaces to provide information for AI supportEpistemic Interaction - tuning interfaces to provide information for AI support
Epistemic Interaction - tuning interfaces to provide information for AI support
 
The Future of Platform Engineering
The Future of Platform EngineeringThe Future of Platform Engineering
The Future of Platform Engineering
 
Accelerate your Kubernetes clusters with Varnish Caching
Accelerate your Kubernetes clusters with Varnish CachingAccelerate your Kubernetes clusters with Varnish Caching
Accelerate your Kubernetes clusters with Varnish Caching
 
Unsubscribed: Combat Subscription Fatigue With a Membership Mentality by Head...
Unsubscribed: Combat Subscription Fatigue With a Membership Mentality by Head...Unsubscribed: Combat Subscription Fatigue With a Membership Mentality by Head...
Unsubscribed: Combat Subscription Fatigue With a Membership Mentality by Head...
 
FIDO Alliance Osaka Seminar: FIDO Security Aspects.pdf
FIDO Alliance Osaka Seminar: FIDO Security Aspects.pdfFIDO Alliance Osaka Seminar: FIDO Security Aspects.pdf
FIDO Alliance Osaka Seminar: FIDO Security Aspects.pdf
 
JMeter webinar - integration with InfluxDB and Grafana
JMeter webinar - integration with InfluxDB and GrafanaJMeter webinar - integration with InfluxDB and Grafana
JMeter webinar - integration with InfluxDB and Grafana
 
Leading Change strategies and insights for effective change management pdf 1.pdf
Leading Change strategies and insights for effective change management pdf 1.pdfLeading Change strategies and insights for effective change management pdf 1.pdf
Leading Change strategies and insights for effective change management pdf 1.pdf
 
DevOps and Testing slides at DASA Connect
DevOps and Testing slides at DASA ConnectDevOps and Testing slides at DASA Connect
DevOps and Testing slides at DASA Connect
 
State of ICS and IoT Cyber Threat Landscape Report 2024 preview
State of ICS and IoT Cyber Threat Landscape Report 2024 previewState of ICS and IoT Cyber Threat Landscape Report 2024 preview
State of ICS and IoT Cyber Threat Landscape Report 2024 preview
 
AI for Every Business: Unlocking Your Product's Universal Potential by VP of ...
AI for Every Business: Unlocking Your Product's Universal Potential by VP of ...AI for Every Business: Unlocking Your Product's Universal Potential by VP of ...
AI for Every Business: Unlocking Your Product's Universal Potential by VP of ...
 
UiPath Test Automation using UiPath Test Suite series, part 4
UiPath Test Automation using UiPath Test Suite series, part 4UiPath Test Automation using UiPath Test Suite series, part 4
UiPath Test Automation using UiPath Test Suite series, part 4
 
Bits & Pixels using AI for Good.........
Bits & Pixels using AI for Good.........Bits & Pixels using AI for Good.........
Bits & Pixels using AI for Good.........
 
LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...
LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...
LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...
 
To Graph or Not to Graph Knowledge Graph Architectures and LLMs
To Graph or Not to Graph Knowledge Graph Architectures and LLMsTo Graph or Not to Graph Knowledge Graph Architectures and LLMs
To Graph or Not to Graph Knowledge Graph Architectures and LLMs
 
Encryption in Microsoft 365 - ExpertsLive Netherlands 2024
Encryption in Microsoft 365 - ExpertsLive Netherlands 2024Encryption in Microsoft 365 - ExpertsLive Netherlands 2024
Encryption in Microsoft 365 - ExpertsLive Netherlands 2024
 
FIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdf
FIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdfFIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdf
FIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdf
 
PCI PIN Basics Webinar from the Controlcase Team
PCI PIN Basics Webinar from the Controlcase TeamPCI PIN Basics Webinar from the Controlcase Team
PCI PIN Basics Webinar from the Controlcase Team
 
Elevating Tactical DDD Patterns Through Object Calisthenics
Elevating Tactical DDD Patterns Through Object CalisthenicsElevating Tactical DDD Patterns Through Object Calisthenics
Elevating Tactical DDD Patterns Through Object Calisthenics
 

Redis memcached pdf

  • 1. Caching Memcached vs. Redis San Francisco MySQL Meetup Ryan Lowe Erin O’Neill 1
  • 2. Databases WE LOVE THEM ... Except when we don’t 2
  • 3. When Databases Rule • Many access patterns on the same set of data • Transactions (both monetary and isolated units of work) • Don’t know what the end state access patterns will be • Always :) 3
  • 4. When Databases Suck • Lots of concurrent users • ORMs • Big Data Sets • Small Pockets of VERY hot data 4
  • 5. How Caching Works • External vs. built-in caching • MySQL Query Cache • InnoDB Buffer Pool • Rails SOMETHING 5
  • 8. 8
  • 9. 9
  • 10. There are only two hard problems in Computer Science: cache invalidation, naming things, and off-by- one errors. -- Martin Fowler 10
  • 11. Problems with Caching • Cache Misses • Thundering Herd • Stale Data • Warm-Up Times • Overly-Aggressive Caching • Poor Cache Design 11
  • 12. Cache Misses Cache Hit: 1 Operation Cache Miss: 3 Operations 12
  • 13. Thundering Herd • Key TOP_10_VIDEOS expires @ 9:00 • Generating the K/V takes three seconds • Page gets 100 req/s = 100*3 = 300 threads! 13
  • 14. Stale Data • Must maintain consistency between the database and the cache from within the application • Extremely difficult to validate correctness 14
  • 15. Cache Warm-Up • All attempts to read from the cache are CACHE MISSES, which require three operations. • This can result in a significant degradation of response time. • Usually accompanied by a Thundering Herd 15
  • 16. Use Cases • Sessions • Tag Clouds • Popular Items • Auto-suggest lists • Full Page Cache • Relationships • Profile • User Information Information • Online Users • User Preferences • Statistics 16
  • 17. Memcached Memcached is an in-memory key- value store for small chunks of arbitrary data (strings, objects) from results of database calls, API calls, or page rendering. 17
  • 18. Redis Redis is an open source, advanced key-value store. It is often referred to as a “data structure server” since keys can contain strings, hashes, lists, sets and sorted sets. 18
  • 20. Consistent Hashing • Each Key deterministically goes to a particular server. Think (KEY % SERVERS) 20
  • 21. Memcached • Dead Simple & Battle Tested • Fast • Non-Blocking get()/set() • Multi-Threaded • Consistent Hashing 21
  • 22. Memcached Example employee_id = 1234 employee_json = { name => ‘Ryan Lowe’, title => ‘Production Engineer’ } set(employee_id, employee_json) get(employee_id) [Returns employee_json] 22
  • 23. But I don’t want all the data • What if I just want the name? • 64 Bytes for the object vs. 10 for just the name :-( • 6x network traffic • More work for the application • Fatter applications 23
  • 24. Redis • Advanced Data Types • Replication • Persistence • Usually Fast • Very Cool Atomic Operations 24
  • 25. Redis: The Bad • Single-Threaded • Limited client support for consistent hashing • Significant overhead for persistence (do be discussed later) • Not widely deployed (compared to Memcached) 25
  • 26. Redis: Datatypes • Strings (just like Memcached) • Lists • Sets • Sorted Sets • Hashes 26
  • 27. Redis: Lists • Stored in sorted order • Can push/pop • Fast head/tail access • Index access (yay) 27
  • 28. Redis: Lists r.lpush(‘employees’, ‘Ryan Lowe’) r.lpush(‘employees’, ‘Dave Apgar’) r.lrange(‘employees’, 0, -1) (‘Dave Apgar’, ‘Ryan Lowe’) r.rpush(‘employees’, ‘Evan Miller’) r.lrange(‘employees’, 0, -1) (‘Dave Apgar’, ‘Ryan Lowe’, ‘Evan Miller’) 28
  • 29. Redis: Sets • Un-ordered collections of strings • Unique (no repeated members) • diff, intersect, merge 29
  • 30. Redis: Sets sadd(‘employees’, ‘Ryan Lowe’) sadd(‘former_employees’, ‘Bryan Lowe’) sdiff(‘former_employees’, ‘employees’) (‘Ryan Lowe’,‘Bryan Lowe’) 30
  • 31. Redis: Sorted Sets • Same as Sets but ordered by a score 31
  • 32. Redis: Hashes r.hset(‘employees’, ‘count’, 1234) r.hset(‘employees’,‘females’, 1000) r.hset(‘employees’,‘males’, 234) hget(‘employees’,‘count’) “1234” hgetall(‘employees’) { ‘count’ => 1234, ‘females’ => 1000, ‘males’ => 234 } 32
  • 33. Memcached vs. Redis Memcached Redis (multi)get ✓ ✓ (multi)set ✓ ✓ incr/decr ✓ ✓ delete ✓ ✓ Expiration ✓ ✓ prepend/append ✓ Range Queries ✓ Data Types! ✓ Persistence (sorta) ✓ Multi-Threaded ✓ Replication (sorta) ✓ 33
  • 34. Instrumentation • Redis: info • Memcached: stats • Both give system information, connections, hits, misses, etc. • Graphite most of the metrics!!! 34
  • 36. About the Benchmarks • 1 Hour • Redis 2.6 & Memcached 1.4.5 • 64,000,000 Keys "KEY_#{i.to_s}" • 51-Character Values (0...50).map{ ('a'..'z').to_a[rand(26)] }.join 36
  • 38. Redis Set (1 Server) 1 Client 2 Clients 4 Clients 8 Clients 12 Clients 16 Clients 24 Clients 32 Clients 12000 10500 9000 7500 6000 4500 3000 1500 0 38
  • 39. Redis Set (1 Server) 1 Client 2 Clients 4 Clients 8 Clients 12 Clients 16 Clients 24 Clients 32 Clients 12000 WTF?! 10500 9000 7500 6000 4500 3000 1500 0 39
  • 40. Redis Set (1 Server) 1 Client 2 Clients 4 Clients 8 Clients 12 Clients 16 Clients 24 Clients 10000 8000 6000 4000 2000 0 40
  • 41. Redis Set (2 Servers) 1 Client 2 Clients 4 Clients 8 Clients 12 Clients 16 Clients 24 Clients 32 Clients 16000 12000 8000 4000 0 41
  • 42. Redis Set (2 Servers) 1 Client 2 Clients 4 Clients 8 Clients 12 Clients 16 Clients 24 Clients 32 Clients 16000 12000 8000 WTF?! 4000 0 42
  • 43. Redis Set (4 Servers) 1 Client 2 Clients 4 Clients 8 Clients 12 Clients 16 Clients 24 Clients 32 Clients 16000 12000 8000 4000 0 43
  • 44. Redis Set (8 Servers) 1 Client 2 Clients 4 Clients 8 Clients 12 Clients 16 Clients 24 Clients 32 Clients 16000 12000 8000 4000 0 44
  • 45. Hash Ring Balance (%) Server 1 Server 2 100 50 0 Redis Memcached 45
  • 46. Hash Ring Balance (%) Server 1 Server 2 Server 3 Server 4 50 25 0 Redis Memcached 46
  • 47. Hash Ring Balance (%) Server 1 Server 2 Server 3 Server 4 Server 5 Server 6 Server 7 Server 8 25 12.5 0 Redis Memcached 47
  • 48. Redis Get (1 Server) 1 Client 2 Clients 4 Clients 8 Clients 12 Clients 16 Clients 24 Clients 32 Clients 125000 100000 75000 50000 25000 0 48
  • 49. Redis Get (2 Servers) 1 Client 2 Clients 4 Clients 8 Clients 12 Clients 16 Clients 24 Clients 32 Clients 125000 100000 75000 50000 25000 0 49
  • 50. Redis Get (4 Servers) 1 Client 2 Clients 4 Clients 8 Clients 12 Clients 16 Clients 24 Clients 32 Clients 125000 100000 75000 50000 25000 0 50
  • 51. Redis Get (8 Servers) 1 Client 2 Clients 4 Clients 8 Clients 12 Clients 16 Clients 24 Clients 32 Clients 125000 100000 75000 50000 25000 0 51
  • 52. The Cost of Persistence Redis No Persistence Redis BGSAVE (FIO) Redis AOF 12000 10000 8000 6000 4000 52
  • 53. Redis & Memcached Benchmarks 53
  • 54. Set Operations (1 Server, 24 Clients) Memcached Redis 10000 9825 9650 9475 9300 54
  • 55. Get Operations (1 Server, 24 Clients) Memcached Redis 130000 117500 105000 92500 80000 55
  • 56. Set Operations (2 Servers, 24 Clients) Memcached Redis 13000 11750 10500 9250 8000 56
  • 57. Get Operations (2 Servers, 24 Clients) Memcached Redis 140000 107000 74000 41000 8000 57
  • 58. Set Operations (4 Servers, 24 Clients) Memcached Redis 13000 11750 10500 9250 8000 58
  • 59. Get Operations (4 Servers, 24 Clients) Memcached Redis 140000 107000 74000 41000 8000 59
  • 60. Set Operations (8 Servers, 24 Clients) Memcached Redis 12000 11000 10000 9000 8000 60
  • 61. Get Operations (8 Servers, 24 Clients) Memcached Redis 150000 114500 79000 43500 8000 61
  • 62. Conclusions • Redis inconsistent under heavy load • We need more benchmarks! • (Redis) Datatype-specific • Big Memory • (Redis) Big Keys 62