SlideShare a Scribd company logo
1 of 36
Download to read offline
REmote DIctionary Server
Chris Keith
James Tavares
Overview
History
Users
Logical Data Model
Atomic Operators
Transactions
Programming Language APIs
System Architecture
Physical Data Structures
Data Persistence
Replication, Consistency, Availability
Benchmarks
History
Early 2009 - Salvatore Sanfilippo, an Italian developer,
started the Redis project
He was working on a real-time web analytics solution and
found that MySQL could not provide the necessary
performance.
June 2009 - Redis was deployed in production for the
LLOOGG real-time web analytics website
March 2010 - VMWare hired Sanfilippo to work full-time on
Redis (remains BSD licensed)
Subsequently, VMWare hired Pieter Noordhuis, a major
Redis contributor, to assist on the project.
Other Users
Logical Data Model
Data Model
Key
Printable ASCII
Value
Primitives
Strings
Containers (of strings)
Hashes
Lists
Sets
Sorted Sets
Logical Data Model
Data Model
Key
Printable ASCII
Value
Primitives
Strings
Containers (of strings)
Hashes
Lists
Sets
Sorted Sets
Logical Data Model
Data Model
Key
Printable ASCII
Value
Primitives
Strings
Containers (of strings)
Hashes
Lists
Sets
Sorted Sets
Logical Data Model
Data Model
Key
Printable ASCII
Value
Primitives
Strings
Containers (of strings)
Hashes
Lists
Sets
Sorted Sets
Logical Data Model
Data Model
Key
Printable ASCII
Value
Primitives
Strings
Containers (of strings)
Hashes
Lists
Sets
Sorted Sets
Logical Data Model
Data Model
Key
Printable ASCII
Value
Primitives
Strings
Containers (of strings)
Hashes
Lists
Sets
Sorted Sets
Shopping Cart Example
Relational Model
carts
cart_lines
UPDATE cart_lines
SET Qty = Qty + 2
WHERE Cart=1 AND Product=28
Cart Product Qty
1 28 1
1 372 2
2 15 1
2 160 5
2 201 7
CartID User
1 james
2 chris
3 james
Shopping Cart Example
Relational Model
carts
cart_lines
UPDATE cart_lines
SET Qty = Qty + 2
WHERE Cart=1 AND Product=28
Redis Model
set carts_james ( 1 3 )
set carts_chris ( 2 )
hash cart_1 {
user : "james"
product_28 : 1
product_372: 2
}
hash cart_2 {
user : "chris"
product_15 : 1
product_160: 5
product_201: 7
}
HINCRBY cart_1 product_28 2
Cart Product Qty
1 28 1
1 372 2
2 15 1
2 160 5
2 201 7
CartID User
1 james
2 chris
3 james
Atomic Operators - KV Store
Strings - O(1)
GET key
SET key value
EXISTS key
DEL key
SETNX key value
Set if not exists
GETSET key value
Get old value, set new
Hashes - O(1)
HGET key field
HSET key field value
HEXISTS key field
HDEL key field
Hashes - O(N)
HMGET key f1 [f2 ...]
Get fields of a hash
KKEYS key | HVALS key
All keys/values of hash
Atomic Operators - Sets
Sets - O(1)
SADD, SREM, SCARD
SPOP key
Return random
member of the set
Sets - O(N)
SDIFF key1 key2
SUNION key1 key2
Sets - O(C)
SINTER key1 key2
Atomic Operators - Sets
Sets - O(1)
SADD, SREM, SCARD
SPOP key
Return random
member of the set
Sets - O(N)
SDIFF key1 key2 ...
SUNION key1 key2 ...
Sets - O(C*M)
SINTER key1 key2 ...
Sorted Sets - O(1)
ZCARD key
Sorted Sets - O(log(N))
ZADD key score member
ZREM key member
ZRANK key member
Sorted Sets - O(log(N)+M))
ZRANGE key start stop
ZRANGEBYSCORE
key min max
Transactions
All commands are serialized and executed sequentially
Either all commands or no commands are processed
Keys must be overtly specified in Redis transactions
Redis commands for transactions:
WATCH
MULTI
DISCARD
EXEC
UNWATCH
Programming Language APIs
ActionScript
C
C#
C++
Clojure
Common Lisp
Erlang
Go
Haskell
haXe
Io
Java
Lua
Objective-C
Perl
PHP
Python
Ruby
Scala
Smalltalk
Tcl
API Examples
System Architecture
Redis Instance
Main memory database
Single-threaded event loop (no locks!)
Virtual Memory
Evicts "values" rather than "pages"
Smarter than OS with complex data structures
May use threads
Sharding: application's job!
Data Persistence
Periodic Dump ("Background Save")
fork() with Copy-on-Write, write entire DB to disk
When?
After every X seconds and Y changes, or,
BGSAVE command
Append Only File
On every write, append change to log file
Flexible fsync() schedule:
Always, Every second, or, Never
Must compact with BGREWRITEAOF
Data Structure Internals
Key-Value Store ("hash table")
Incremental, auto-resize on powers of two
Collisions handled by chaining
Hash Collection
< 512 entries
"zipmap" -- O(N) lookups, O(mem_size) add/delete
> 512 entries
Hash Table
Data Structure Internals
Set Collection
< 512 integers: "intset" -- O(N) lookups
everything else: Hash Table
Sorted Set Collection -- O(log N) insets/deletes
Indexable Skip List: Scores+Key => Values
Hash Table: Key => Score
List Collection
< 512 entries: "ziplist"
O(mem_size) inserts/deletes
> 512 entries: Doubly Linked List
O(1) left/right push/pop
Replication
Topology (Tree)
Master is largely "unaware" of slaves
No quorums (only master need accept the write)
Selection of master left to client!
All nodes accept "writes"
All nodes are master of their own slaves
Writes propagated downstream ONLY (asynchronously)
Slave Roles:
Offload save-to-disk
Offload reads (load
balancing up to client)
Data redundancy
Write Global
Data Here
Write Local
Data Here
Redis & CAP Theorem
C & A
Writes: single master
Reads: any node
Eventually consistent,
no read-your-own-writes
C & P
On failure: inhibit writes
Consequence: decreased availability
A & P
On failure: elect new master
Consequence: inconsistent data,
no easy reconciliation
"Redis Cluster" is in development
but not currently available
Benchmarks - Client Libraries
Benchmarks - Hardware
Questions?
Additional Slides
Motivation
Imagine
lots of data
stored in main memory as:
hash maps, lists, sets, and sorted sets
O(1) -- GET, PUT, PUSH, and POP operations
O(log(N)) -- sorted operations
Imagine 100k requests per second per machine
Imagine Redis!
Our Goal:
Give you an overview of Redis externals & internals
Replication Process
Chronology
SLAVE: Connects to master, sends "SYNC" command
MASTER: Begins "background save" of DB to disk
MASTER: Begins recording all new writes
MASTER: Transfers DB snapshot to slave
SLAVE: Saves snapshot to disk
SLAVE: Loads snapshot into RAM
MASTER: Sends recorded write commands
SLAVE: Applies recorded write commands
SLAVE: Goes live, begins accepting requests
Used in "crowd-sourcing" application for reviewing
documents related to MP's (members of Parliament)
expense reports
Major challenge was providing a random document to a
review
Initial implementation used SQL "ORDER BY RAND()"
command to choose an new document for a reviewer
RAND() statement account for 90% of DB load
Redis implementation leveraged SRANDMEMBER()
command to generate a random element (document id)
from a set
Redis was also used to manage account registration
process for document reviewers
Uses Redis as a three level site-caching solution
"Local-Cache" for 1 server/site pair
user sessions/pending view count updates
"Site-Cache" for all servers in a site
Hot question id lists/user acceptance rates
"Global-Cache" is shared among all sites and servers
Inbox/usage quotas
Cache typically includes approximately 120,000 keys
Most expire within minutes
Number is expected to grow as confidence is gained
Peak load is a few hundred reads/writes per second
CPU Usage on dedicated Redis machine is reported to
be 0%
Memory usage on dedicated Redis machine is < 1/2 GB
Schema
Schema
Informal, free-form "Namespaces"
Example Keys:
user:1000:pwd
User 1000's password
user.next.id
The next user ID to be assigned
Redis and the CAP Theorem
Achieving the ideals of the CAP Theorem depends greatly on
how an instance of Redis is configured. A clustered version of
Redis is in development but not currently available.
Consistency
A single node instance of
Redis would provide the
highest levels of
consistency. Writes
propagate down the
replication tree. Consistent
writes must be written
directly to the master
node. Consistent reads
depend on the speed of the
synchronization process.
Availability
Adding more nodes
increases availability for
reads and writes. However,
adding more nodes greatly
increases the complexity of
maintaining consistent data
due to the "down-hill"
propagation of write
operations.
Partition Tolerance
Tolerating network partitions
is a major weakness of a
Redis system. Logic for
detecting failures and
promoting slave nodes to
master's and reconfiguring
the replication tree must be
handled by the application
developer.

More Related Content

Similar to mar07-redis.pdf

Scaling with MongoDB
Scaling with MongoDBScaling with MongoDB
Scaling with MongoDBMongoDB
 
Processing massive amount of data with Map Reduce using Apache Hadoop - Indi...
Processing massive amount of data with Map Reduce using Apache Hadoop  - Indi...Processing massive amount of data with Map Reduce using Apache Hadoop  - Indi...
Processing massive amount of data with Map Reduce using Apache Hadoop - Indi...IndicThreads
 
Unified Big Data Processing with Apache Spark (QCON 2014)
Unified Big Data Processing with Apache Spark (QCON 2014)Unified Big Data Processing with Apache Spark (QCON 2014)
Unified Big Data Processing with Apache Spark (QCON 2014)Databricks
 
SQL Server 2014 In-Memory Tables (XTP, Hekaton)
SQL Server 2014 In-Memory Tables (XTP, Hekaton)SQL Server 2014 In-Memory Tables (XTP, Hekaton)
SQL Server 2014 In-Memory Tables (XTP, Hekaton)Tony Rogerson
 
Stanford CS347 Guest Lecture: Apache Spark
Stanford CS347 Guest Lecture: Apache SparkStanford CS347 Guest Lecture: Apache Spark
Stanford CS347 Guest Lecture: Apache SparkReynold Xin
 
Five major tips to maximize performance on a 200+ SQL HBase/Phoenix cluster
Five major tips to maximize performance on a 200+ SQL HBase/Phoenix clusterFive major tips to maximize performance on a 200+ SQL HBase/Phoenix cluster
Five major tips to maximize performance on a 200+ SQL HBase/Phoenix clustermas4share
 
Ds8000 Practical Performance Analysis P04 20060718
Ds8000 Practical Performance Analysis P04 20060718Ds8000 Practical Performance Analysis P04 20060718
Ds8000 Practical Performance Analysis P04 20060718brettallison
 
Boston Spark Meetup event Slides Update
Boston Spark Meetup event Slides UpdateBoston Spark Meetup event Slides Update
Boston Spark Meetup event Slides Updatevithakur
 
NOSQL and Cassandra
NOSQL and CassandraNOSQL and Cassandra
NOSQL and Cassandrarantav
 
Spark Study Notes
Spark Study NotesSpark Study Notes
Spark Study NotesRichard Kuo
 
Introduction to Apache Spark
Introduction to Apache SparkIntroduction to Apache Spark
Introduction to Apache SparkVincent Poncet
 
Unified Big Data Processing with Apache Spark
Unified Big Data Processing with Apache SparkUnified Big Data Processing with Apache Spark
Unified Big Data Processing with Apache SparkC4Media
 
Redis - for duplicate detection on real time stream
Redis - for duplicate detection on real time streamRedis - for duplicate detection on real time stream
Redis - for duplicate detection on real time streamCodemotion
 
Redis for duplicate detection on real time stream
Redis for duplicate detection on real time streamRedis for duplicate detection on real time stream
Redis for duplicate detection on real time streamRoberto Franchini
 
Rpc (Distributed computing)
Rpc (Distributed computing)Rpc (Distributed computing)
Rpc (Distributed computing)Sri Prasanna
 
Best Practices for Migrating your Data Warehouse to Amazon Redshift
Best Practices for Migrating your Data Warehouse to Amazon RedshiftBest Practices for Migrating your Data Warehouse to Amazon Redshift
Best Practices for Migrating your Data Warehouse to Amazon RedshiftAmazon Web Services
 
Scylla Summit 2022: ScyllaDB Rust Driver: One Driver to Rule Them All
Scylla Summit 2022: ScyllaDB Rust Driver: One Driver to Rule Them AllScylla Summit 2022: ScyllaDB Rust Driver: One Driver to Rule Them All
Scylla Summit 2022: ScyllaDB Rust Driver: One Driver to Rule Them AllScyllaDB
 
PASS Summit - SQL Server 2017 Deep Dive
PASS Summit - SQL Server 2017 Deep DivePASS Summit - SQL Server 2017 Deep Dive
PASS Summit - SQL Server 2017 Deep DiveTravis Wright
 

Similar to mar07-redis.pdf (20)

Scaling with MongoDB
Scaling with MongoDBScaling with MongoDB
Scaling with MongoDB
 
Processing massive amount of data with Map Reduce using Apache Hadoop - Indi...
Processing massive amount of data with Map Reduce using Apache Hadoop  - Indi...Processing massive amount of data with Map Reduce using Apache Hadoop  - Indi...
Processing massive amount of data with Map Reduce using Apache Hadoop - Indi...
 
Unified Big Data Processing with Apache Spark (QCON 2014)
Unified Big Data Processing with Apache Spark (QCON 2014)Unified Big Data Processing with Apache Spark (QCON 2014)
Unified Big Data Processing with Apache Spark (QCON 2014)
 
SQL Server 2014 In-Memory Tables (XTP, Hekaton)
SQL Server 2014 In-Memory Tables (XTP, Hekaton)SQL Server 2014 In-Memory Tables (XTP, Hekaton)
SQL Server 2014 In-Memory Tables (XTP, Hekaton)
 
Stanford CS347 Guest Lecture: Apache Spark
Stanford CS347 Guest Lecture: Apache SparkStanford CS347 Guest Lecture: Apache Spark
Stanford CS347 Guest Lecture: Apache Spark
 
Data Science
Data ScienceData Science
Data Science
 
Five major tips to maximize performance on a 200+ SQL HBase/Phoenix cluster
Five major tips to maximize performance on a 200+ SQL HBase/Phoenix clusterFive major tips to maximize performance on a 200+ SQL HBase/Phoenix cluster
Five major tips to maximize performance on a 200+ SQL HBase/Phoenix cluster
 
Ds8000 Practical Performance Analysis P04 20060718
Ds8000 Practical Performance Analysis P04 20060718Ds8000 Practical Performance Analysis P04 20060718
Ds8000 Practical Performance Analysis P04 20060718
 
Boston Spark Meetup event Slides Update
Boston Spark Meetup event Slides UpdateBoston Spark Meetup event Slides Update
Boston Spark Meetup event Slides Update
 
NOSQL and Cassandra
NOSQL and CassandraNOSQL and Cassandra
NOSQL and Cassandra
 
SparkNotes
SparkNotesSparkNotes
SparkNotes
 
Spark Study Notes
Spark Study NotesSpark Study Notes
Spark Study Notes
 
Introduction to Apache Spark
Introduction to Apache SparkIntroduction to Apache Spark
Introduction to Apache Spark
 
Unified Big Data Processing with Apache Spark
Unified Big Data Processing with Apache SparkUnified Big Data Processing with Apache Spark
Unified Big Data Processing with Apache Spark
 
Redis - for duplicate detection on real time stream
Redis - for duplicate detection on real time streamRedis - for duplicate detection on real time stream
Redis - for duplicate detection on real time stream
 
Redis for duplicate detection on real time stream
Redis for duplicate detection on real time streamRedis for duplicate detection on real time stream
Redis for duplicate detection on real time stream
 
Rpc (Distributed computing)
Rpc (Distributed computing)Rpc (Distributed computing)
Rpc (Distributed computing)
 
Best Practices for Migrating your Data Warehouse to Amazon Redshift
Best Practices for Migrating your Data Warehouse to Amazon RedshiftBest Practices for Migrating your Data Warehouse to Amazon Redshift
Best Practices for Migrating your Data Warehouse to Amazon Redshift
 
Scylla Summit 2022: ScyllaDB Rust Driver: One Driver to Rule Them All
Scylla Summit 2022: ScyllaDB Rust Driver: One Driver to Rule Them AllScylla Summit 2022: ScyllaDB Rust Driver: One Driver to Rule Them All
Scylla Summit 2022: ScyllaDB Rust Driver: One Driver to Rule Them All
 
PASS Summit - SQL Server 2017 Deep Dive
PASS Summit - SQL Server 2017 Deep DivePASS Summit - SQL Server 2017 Deep Dive
PASS Summit - SQL Server 2017 Deep Dive
 

More from AnisSalhi3

Bar Graph Infographicsaaaaaaaaaaaaaaaaaaa
Bar Graph InfographicsaaaaaaaaaaaaaaaaaaaBar Graph Infographicsaaaaaaaaaaaaaaaaaaa
Bar Graph InfographicsaaaaaaaaaaaaaaaaaaaAnisSalhi3
 
Copie de Robotic Workshop Infographics by Slidesgo.pptx
Copie de Robotic Workshop Infographics by Slidesgo.pptxCopie de Robotic Workshop Infographics by Slidesgo.pptx
Copie de Robotic Workshop Infographics by Slidesgo.pptxAnisSalhi3
 
Research Proposal Business Presentation in Dark Green Orange Geometric Style.pdf
Research Proposal Business Presentation in Dark Green Orange Geometric Style.pdfResearch Proposal Business Presentation in Dark Green Orange Geometric Style.pdf
Research Proposal Business Presentation in Dark Green Orange Geometric Style.pdfAnisSalhi3
 
Copie de Introduction to Coding Workshop by Slidesgo.pptx
Copie de Introduction to Coding Workshop by Slidesgo.pptxCopie de Introduction to Coding Workshop by Slidesgo.pptx
Copie de Introduction to Coding Workshop by Slidesgo.pptxAnisSalhi3
 
JFTL-2018-Comment-mettre-en-place-des-plateformes-de-test-gr__ce-__-Docker.pptx
JFTL-2018-Comment-mettre-en-place-des-plateformes-de-test-gr__ce-__-Docker.pptxJFTL-2018-Comment-mettre-en-place-des-plateformes-de-test-gr__ce-__-Docker.pptx
JFTL-2018-Comment-mettre-en-place-des-plateformes-de-test-gr__ce-__-Docker.pptxAnisSalhi3
 
Emplois informatiques.pdf
Emplois informatiques.pdfEmplois informatiques.pdf
Emplois informatiques.pdfAnisSalhi3
 
Cours Firewalls.pdf
Cours Firewalls.pdfCours Firewalls.pdf
Cours Firewalls.pdfAnisSalhi3
 
Cloud-Azure.pdf
Cloud-Azure.pdfCloud-Azure.pdf
Cloud-Azure.pdfAnisSalhi3
 

More from AnisSalhi3 (9)

Bar Graph Infographicsaaaaaaaaaaaaaaaaaaa
Bar Graph InfographicsaaaaaaaaaaaaaaaaaaaBar Graph Infographicsaaaaaaaaaaaaaaaaaaa
Bar Graph Infographicsaaaaaaaaaaaaaaaaaaa
 
Copie de Robotic Workshop Infographics by Slidesgo.pptx
Copie de Robotic Workshop Infographics by Slidesgo.pptxCopie de Robotic Workshop Infographics by Slidesgo.pptx
Copie de Robotic Workshop Infographics by Slidesgo.pptx
 
Research Proposal Business Presentation in Dark Green Orange Geometric Style.pdf
Research Proposal Business Presentation in Dark Green Orange Geometric Style.pdfResearch Proposal Business Presentation in Dark Green Orange Geometric Style.pdf
Research Proposal Business Presentation in Dark Green Orange Geometric Style.pdf
 
Copie de Introduction to Coding Workshop by Slidesgo.pptx
Copie de Introduction to Coding Workshop by Slidesgo.pptxCopie de Introduction to Coding Workshop by Slidesgo.pptx
Copie de Introduction to Coding Workshop by Slidesgo.pptx
 
JFTL-2018-Comment-mettre-en-place-des-plateformes-de-test-gr__ce-__-Docker.pptx
JFTL-2018-Comment-mettre-en-place-des-plateformes-de-test-gr__ce-__-Docker.pptxJFTL-2018-Comment-mettre-en-place-des-plateformes-de-test-gr__ce-__-Docker.pptx
JFTL-2018-Comment-mettre-en-place-des-plateformes-de-test-gr__ce-__-Docker.pptx
 
Emplois informatiques.pdf
Emplois informatiques.pdfEmplois informatiques.pdf
Emplois informatiques.pdf
 
Cours Firewalls.pdf
Cours Firewalls.pdfCours Firewalls.pdf
Cours Firewalls.pdf
 
SSH.pdf
SSH.pdfSSH.pdf
SSH.pdf
 
Cloud-Azure.pdf
Cloud-Azure.pdfCloud-Azure.pdf
Cloud-Azure.pdf
 

Recently uploaded

Introduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher EducationIntroduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher Educationpboyjonauth
 
Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)eniolaolutunde
 
History Class XII Ch. 3 Kinship, Caste and Class (1).pptx
History Class XII Ch. 3 Kinship, Caste and Class (1).pptxHistory Class XII Ch. 3 Kinship, Caste and Class (1).pptx
History Class XII Ch. 3 Kinship, Caste and Class (1).pptxsocialsciencegdgrohi
 
Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111Sapana Sha
 
How to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptxHow to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptxmanuelaromero2013
 
Blooming Together_ Growing a Community Garden Worksheet.docx
Blooming Together_ Growing a Community Garden Worksheet.docxBlooming Together_ Growing a Community Garden Worksheet.docx
Blooming Together_ Growing a Community Garden Worksheet.docxUnboundStockton
 
Class 11 Legal Studies Ch-1 Concept of State .pdf
Class 11 Legal Studies Ch-1 Concept of State .pdfClass 11 Legal Studies Ch-1 Concept of State .pdf
Class 11 Legal Studies Ch-1 Concept of State .pdfakmcokerachita
 
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPTECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPTiammrhaywood
 
Crayon Activity Handout For the Crayon A
Crayon Activity Handout For the Crayon ACrayon Activity Handout For the Crayon A
Crayon Activity Handout For the Crayon AUnboundStockton
 
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdfssuser54595a
 
Biting mechanism of poisonous snakes.pdf
Biting mechanism of poisonous snakes.pdfBiting mechanism of poisonous snakes.pdf
Biting mechanism of poisonous snakes.pdfadityarao40181
 
Final demo Grade 9 for demo Plan dessert.pptx
Final demo Grade 9 for demo Plan dessert.pptxFinal demo Grade 9 for demo Plan dessert.pptx
Final demo Grade 9 for demo Plan dessert.pptxAvyJaneVismanos
 
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...Marc Dusseiller Dusjagr
 
Painted Grey Ware.pptx, PGW Culture of India
Painted Grey Ware.pptx, PGW Culture of IndiaPainted Grey Ware.pptx, PGW Culture of India
Painted Grey Ware.pptx, PGW Culture of IndiaVirag Sontakke
 
internship ppt on smartinternz platform as salesforce developer
internship ppt on smartinternz platform as salesforce developerinternship ppt on smartinternz platform as salesforce developer
internship ppt on smartinternz platform as salesforce developerunnathinaik
 
Pharmacognosy Flower 3. Compositae 2023.pdf
Pharmacognosy Flower 3. Compositae 2023.pdfPharmacognosy Flower 3. Compositae 2023.pdf
Pharmacognosy Flower 3. Compositae 2023.pdfMahmoud M. Sallam
 
ENGLISH5 QUARTER4 MODULE1 WEEK1-3 How Visual and Multimedia Elements.pptx
ENGLISH5 QUARTER4 MODULE1 WEEK1-3 How Visual and Multimedia Elements.pptxENGLISH5 QUARTER4 MODULE1 WEEK1-3 How Visual and Multimedia Elements.pptx
ENGLISH5 QUARTER4 MODULE1 WEEK1-3 How Visual and Multimedia Elements.pptxAnaBeatriceAblay2
 
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...Krashi Coaching
 
Alper Gobel In Media Res Media Component
Alper Gobel In Media Res Media ComponentAlper Gobel In Media Res Media Component
Alper Gobel In Media Res Media ComponentInMediaRes1
 
CARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptxCARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptxGaneshChakor2
 

Recently uploaded (20)

Introduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher EducationIntroduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher Education
 
Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)
 
History Class XII Ch. 3 Kinship, Caste and Class (1).pptx
History Class XII Ch. 3 Kinship, Caste and Class (1).pptxHistory Class XII Ch. 3 Kinship, Caste and Class (1).pptx
History Class XII Ch. 3 Kinship, Caste and Class (1).pptx
 
Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111
 
How to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptxHow to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptx
 
Blooming Together_ Growing a Community Garden Worksheet.docx
Blooming Together_ Growing a Community Garden Worksheet.docxBlooming Together_ Growing a Community Garden Worksheet.docx
Blooming Together_ Growing a Community Garden Worksheet.docx
 
Class 11 Legal Studies Ch-1 Concept of State .pdf
Class 11 Legal Studies Ch-1 Concept of State .pdfClass 11 Legal Studies Ch-1 Concept of State .pdf
Class 11 Legal Studies Ch-1 Concept of State .pdf
 
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPTECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
 
Crayon Activity Handout For the Crayon A
Crayon Activity Handout For the Crayon ACrayon Activity Handout For the Crayon A
Crayon Activity Handout For the Crayon A
 
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
 
Biting mechanism of poisonous snakes.pdf
Biting mechanism of poisonous snakes.pdfBiting mechanism of poisonous snakes.pdf
Biting mechanism of poisonous snakes.pdf
 
Final demo Grade 9 for demo Plan dessert.pptx
Final demo Grade 9 for demo Plan dessert.pptxFinal demo Grade 9 for demo Plan dessert.pptx
Final demo Grade 9 for demo Plan dessert.pptx
 
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
 
Painted Grey Ware.pptx, PGW Culture of India
Painted Grey Ware.pptx, PGW Culture of IndiaPainted Grey Ware.pptx, PGW Culture of India
Painted Grey Ware.pptx, PGW Culture of India
 
internship ppt on smartinternz platform as salesforce developer
internship ppt on smartinternz platform as salesforce developerinternship ppt on smartinternz platform as salesforce developer
internship ppt on smartinternz platform as salesforce developer
 
Pharmacognosy Flower 3. Compositae 2023.pdf
Pharmacognosy Flower 3. Compositae 2023.pdfPharmacognosy Flower 3. Compositae 2023.pdf
Pharmacognosy Flower 3. Compositae 2023.pdf
 
ENGLISH5 QUARTER4 MODULE1 WEEK1-3 How Visual and Multimedia Elements.pptx
ENGLISH5 QUARTER4 MODULE1 WEEK1-3 How Visual and Multimedia Elements.pptxENGLISH5 QUARTER4 MODULE1 WEEK1-3 How Visual and Multimedia Elements.pptx
ENGLISH5 QUARTER4 MODULE1 WEEK1-3 How Visual and Multimedia Elements.pptx
 
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
 
Alper Gobel In Media Res Media Component
Alper Gobel In Media Res Media ComponentAlper Gobel In Media Res Media Component
Alper Gobel In Media Res Media Component
 
CARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptxCARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptx
 

mar07-redis.pdf

  • 1. REmote DIctionary Server Chris Keith James Tavares
  • 2. Overview History Users Logical Data Model Atomic Operators Transactions Programming Language APIs System Architecture Physical Data Structures Data Persistence Replication, Consistency, Availability Benchmarks
  • 3. History Early 2009 - Salvatore Sanfilippo, an Italian developer, started the Redis project He was working on a real-time web analytics solution and found that MySQL could not provide the necessary performance. June 2009 - Redis was deployed in production for the LLOOGG real-time web analytics website March 2010 - VMWare hired Sanfilippo to work full-time on Redis (remains BSD licensed) Subsequently, VMWare hired Pieter Noordhuis, a major Redis contributor, to assist on the project.
  • 5.
  • 6.
  • 7. Logical Data Model Data Model Key Printable ASCII Value Primitives Strings Containers (of strings) Hashes Lists Sets Sorted Sets
  • 8. Logical Data Model Data Model Key Printable ASCII Value Primitives Strings Containers (of strings) Hashes Lists Sets Sorted Sets
  • 9. Logical Data Model Data Model Key Printable ASCII Value Primitives Strings Containers (of strings) Hashes Lists Sets Sorted Sets
  • 10. Logical Data Model Data Model Key Printable ASCII Value Primitives Strings Containers (of strings) Hashes Lists Sets Sorted Sets
  • 11. Logical Data Model Data Model Key Printable ASCII Value Primitives Strings Containers (of strings) Hashes Lists Sets Sorted Sets
  • 12. Logical Data Model Data Model Key Printable ASCII Value Primitives Strings Containers (of strings) Hashes Lists Sets Sorted Sets
  • 13. Shopping Cart Example Relational Model carts cart_lines UPDATE cart_lines SET Qty = Qty + 2 WHERE Cart=1 AND Product=28 Cart Product Qty 1 28 1 1 372 2 2 15 1 2 160 5 2 201 7 CartID User 1 james 2 chris 3 james
  • 14. Shopping Cart Example Relational Model carts cart_lines UPDATE cart_lines SET Qty = Qty + 2 WHERE Cart=1 AND Product=28 Redis Model set carts_james ( 1 3 ) set carts_chris ( 2 ) hash cart_1 { user : "james" product_28 : 1 product_372: 2 } hash cart_2 { user : "chris" product_15 : 1 product_160: 5 product_201: 7 } HINCRBY cart_1 product_28 2 Cart Product Qty 1 28 1 1 372 2 2 15 1 2 160 5 2 201 7 CartID User 1 james 2 chris 3 james
  • 15. Atomic Operators - KV Store Strings - O(1) GET key SET key value EXISTS key DEL key SETNX key value Set if not exists GETSET key value Get old value, set new Hashes - O(1) HGET key field HSET key field value HEXISTS key field HDEL key field Hashes - O(N) HMGET key f1 [f2 ...] Get fields of a hash KKEYS key | HVALS key All keys/values of hash
  • 16. Atomic Operators - Sets Sets - O(1) SADD, SREM, SCARD SPOP key Return random member of the set Sets - O(N) SDIFF key1 key2 SUNION key1 key2 Sets - O(C) SINTER key1 key2
  • 17. Atomic Operators - Sets Sets - O(1) SADD, SREM, SCARD SPOP key Return random member of the set Sets - O(N) SDIFF key1 key2 ... SUNION key1 key2 ... Sets - O(C*M) SINTER key1 key2 ... Sorted Sets - O(1) ZCARD key Sorted Sets - O(log(N)) ZADD key score member ZREM key member ZRANK key member Sorted Sets - O(log(N)+M)) ZRANGE key start stop ZRANGEBYSCORE key min max
  • 18. Transactions All commands are serialized and executed sequentially Either all commands or no commands are processed Keys must be overtly specified in Redis transactions Redis commands for transactions: WATCH MULTI DISCARD EXEC UNWATCH
  • 19. Programming Language APIs ActionScript C C# C++ Clojure Common Lisp Erlang Go Haskell haXe Io Java Lua Objective-C Perl PHP Python Ruby Scala Smalltalk Tcl
  • 21. System Architecture Redis Instance Main memory database Single-threaded event loop (no locks!) Virtual Memory Evicts "values" rather than "pages" Smarter than OS with complex data structures May use threads Sharding: application's job!
  • 22. Data Persistence Periodic Dump ("Background Save") fork() with Copy-on-Write, write entire DB to disk When? After every X seconds and Y changes, or, BGSAVE command Append Only File On every write, append change to log file Flexible fsync() schedule: Always, Every second, or, Never Must compact with BGREWRITEAOF
  • 23. Data Structure Internals Key-Value Store ("hash table") Incremental, auto-resize on powers of two Collisions handled by chaining Hash Collection < 512 entries "zipmap" -- O(N) lookups, O(mem_size) add/delete > 512 entries Hash Table
  • 24. Data Structure Internals Set Collection < 512 integers: "intset" -- O(N) lookups everything else: Hash Table Sorted Set Collection -- O(log N) insets/deletes Indexable Skip List: Scores+Key => Values Hash Table: Key => Score List Collection < 512 entries: "ziplist" O(mem_size) inserts/deletes > 512 entries: Doubly Linked List O(1) left/right push/pop
  • 25. Replication Topology (Tree) Master is largely "unaware" of slaves No quorums (only master need accept the write) Selection of master left to client! All nodes accept "writes" All nodes are master of their own slaves Writes propagated downstream ONLY (asynchronously) Slave Roles: Offload save-to-disk Offload reads (load balancing up to client) Data redundancy Write Global Data Here Write Local Data Here
  • 26. Redis & CAP Theorem C & A Writes: single master Reads: any node Eventually consistent, no read-your-own-writes C & P On failure: inhibit writes Consequence: decreased availability A & P On failure: elect new master Consequence: inconsistent data, no easy reconciliation "Redis Cluster" is in development but not currently available
  • 27. Benchmarks - Client Libraries
  • 31. Motivation Imagine lots of data stored in main memory as: hash maps, lists, sets, and sorted sets O(1) -- GET, PUT, PUSH, and POP operations O(log(N)) -- sorted operations Imagine 100k requests per second per machine Imagine Redis! Our Goal: Give you an overview of Redis externals & internals
  • 32. Replication Process Chronology SLAVE: Connects to master, sends "SYNC" command MASTER: Begins "background save" of DB to disk MASTER: Begins recording all new writes MASTER: Transfers DB snapshot to slave SLAVE: Saves snapshot to disk SLAVE: Loads snapshot into RAM MASTER: Sends recorded write commands SLAVE: Applies recorded write commands SLAVE: Goes live, begins accepting requests
  • 33. Used in "crowd-sourcing" application for reviewing documents related to MP's (members of Parliament) expense reports Major challenge was providing a random document to a review Initial implementation used SQL "ORDER BY RAND()" command to choose an new document for a reviewer RAND() statement account for 90% of DB load Redis implementation leveraged SRANDMEMBER() command to generate a random element (document id) from a set Redis was also used to manage account registration process for document reviewers
  • 34. Uses Redis as a three level site-caching solution "Local-Cache" for 1 server/site pair user sessions/pending view count updates "Site-Cache" for all servers in a site Hot question id lists/user acceptance rates "Global-Cache" is shared among all sites and servers Inbox/usage quotas Cache typically includes approximately 120,000 keys Most expire within minutes Number is expected to grow as confidence is gained Peak load is a few hundred reads/writes per second CPU Usage on dedicated Redis machine is reported to be 0% Memory usage on dedicated Redis machine is < 1/2 GB
  • 35. Schema Schema Informal, free-form "Namespaces" Example Keys: user:1000:pwd User 1000's password user.next.id The next user ID to be assigned
  • 36. Redis and the CAP Theorem Achieving the ideals of the CAP Theorem depends greatly on how an instance of Redis is configured. A clustered version of Redis is in development but not currently available. Consistency A single node instance of Redis would provide the highest levels of consistency. Writes propagate down the replication tree. Consistent writes must be written directly to the master node. Consistent reads depend on the speed of the synchronization process. Availability Adding more nodes increases availability for reads and writes. However, adding more nodes greatly increases the complexity of maintaining consistent data due to the "down-hill" propagation of write operations. Partition Tolerance Tolerating network partitions is a major weakness of a Redis system. Logic for detecting failures and promoting slave nodes to master's and reconfiguring the replication tree must be handled by the application developer.