SlideShare a Scribd company logo
Class 9:
                    Consistent
                    Hashing




cs1120 Fall 2011
David Evans
12 September 2011
Charlottesville Airport, 23 December 2001
Daniel Lewin
Internet Circa 1998

Client   Router



Client                     Router
         Router
                                    Yahoo.com
Client
                      Router


         Router
Client
                  Router
google.com, November 1998 from archive.org
Caching the Internet
                                      Cache

Client           Router



Client                                     Router
                 Router
                                                           Yahoo.com
Client                   Cache
                                       Router
                                                    A Cache stores previous results.
                                                    If the result is already known
                Router                              from the same request recently,
Client
                                  Router            it returns that result.

         Problem: how do Clients and Routers know which cache to try?
Lookup Table
               Key                                   Value
“University of Virginia”                 “Wahoos”
“Virginia Tech”                          “Turkeys”
“University of Michigan”                 “Wolverines”
“MIT”                                    “Beavers”
…                                        …
    Each entry is a (Key . Value) pair. To look up the Value associated
    with a given Key, search the Keys in order until you find one that
    matches, and then the value is the associated Value.
Examples
(define schools
 (list (cons "University of Virginia" "Wahoos")
       (cons "Virginia Tech" "Turkeys")
       (cons "MIT" "Beavers")
       (cons "UC Santa Cruz" "Banana Slugs")))
> (table-lookup schools "University of Virginia")
"Wahoos"
> (table-lookup schools "MIT")
"Beavers"
> (table-lookup schools "UC Irvine")
#f
Simple Lookup Table
Define a procedure, table-lookup, that takes as inputs a table and a
key. If the table contains an entry (key . value), the output is value.
If there is no entry whose first part matches key, the output is false.

                               1. Be very optimistic! Since lists are defined
                                  recursively, most problems involving lists can
                                  be solved with recursive procedures.
                               2. Think of the simplest input, something you can
                                  already solve. This is the base case. For lists, it
                                  is often when the list is null.
                               3. Consider how you would solve the problem
                                  using the result for a slightly smaller version of
                                  the problem. For lists, the smaller version of
                                  the problem is usually the cdr of the list.
Simple Lookup Table
Define a procedure, table-lookup, that takes as inputs a table and a
key. If the table contains an entry (key . value), the output is value.
If there is no entry whose first part matches key, the output is false.
Simple Lookup Table
Define a procedure, table-lookup, that takes as inputs a table and a
key. If the table contains an entry (key . value), the output is value.
If there is no entry whose first part matches key, the output is false.

     (define (table-lookup table key)
       (if (null? table)
           false
           (if (equal? (car (car table)) key)
               (cdr (car table))
               (table-lookup (cdr table) key))))
   This works…but if the table is big (or there are many caches) it is very slow!
Regular Hash Table
                                               Index            Key                    Value
   compute-hash:
                                                0
     Key, Size Number
                                                1
    Maps a key (which could be any              2
    value) and a table size to a
    number between 0 and Size – 1.              3
    This is the position in the table           4
    where the Key should be stored.             5
                                                6
> (compute-hash “University of Virginia” 12)
8                                               7
> (compute-hash “Virginia Tech” 12)             8      “University of Virginia”    “Wahoos”
9
….                                              9      “Virginia Tech”            “Turkeys”

                                                10
                                                11
Typical compute-hash Function
Convert input to a string
  (format “~a” x) converts any value x to a string
             > (format "~a" 23)
             "23"
             > (format "~a" "University of Virginia")
             "University of Virginia"
             > (format "~a" (cons 1 (cons 2 null)))
             "(1 2)"
Typical compute-hash Function
Convert input to a string
  (format “~a” x) converts any value x to a string
Convert each character in the string to a number
  (char->integer c) converts any character to a
  number.            > (char->integer #A)
                    65
                    > (char->integer #U)
                    85
                    > (char->integer #space)
                    32
Typical compute-hash Function
Convert input to a string
  (format “~a” x) converts any value x to a string
Convert each character in the string to a number
  (char->integer c) converts any character to a
  number.
Compute the sum of all the numbers, modulo the
  size of the table.
Defining compute-hash
(define (compute-hash key size)
  (modulo
   (sum-chars
     (string->list (format "~a" key)))
   size))
Defining sum-chars
Define a procedure, sum-chars, that takes as input a list of
characters, and outputs the sum of all the character values
(as converted by char->integer) in the list.
                                1. Be very optimistic! Since lists are
                                   defined recursively, most problems
                                   involving lists can be solved with
                                   recursive procedures.
                                2. Think of the simplest input, something
                                   you can already solve. This is the base
                                   case. For lists, it is often when the list
                                   is null.
                                3. Consider how you would solve the
                                   problem using the result for a slightly
                                   smaller version of the problem. For
                                   lists, the smaller version of the
                                   problem is usually the cdr of the list.
Defining sum-chars
Define a procedure, sum-chars, that takes as input a list of
characters, and outputs the sum of all the character values
(as converted by char->integer) in the list.

   (define (sum-chars p)
    (if (null? p)
       0
       (+(char->integer (car p))
                (sum-chars (cdr p)))))
(define (sum-chars p)
 (apply + (map char->integer p)))
Use of Hash Table in PS2
                                         Note: this uses several things
(define (memoize f)                      you haven’t seen yet. I won’t
                                         try to explain them all now.
 (let ((ht (make-hash)))
   (lambda (s1 s2)
     (let ((key (format "~a#~a" s1 s2)))
       (hash-ref ht key              Look up the value of key in the
         (lambda ()                  hash table, ht. If it has a value,
                                     that is the value. If it has no
           (let ((res (f s1 s2)))    value yet, apply this procedure
                                     which finds the value by
              (hash-set! ht key res) applying (f s1 s2) and stores it
                                     in the table at the location
              res)))))))             associated with this key.
Problem with Regular Hashing
                                     Index            Key                    Value
                                      0
 > (compute-hash “University of Virginia” 12)
                                  1
 8
                                  2
 > (compute-hash “Virginia Tech” 12)
                                  3
 9
                                  4
 ….
                                  5
 > (compute-hash “Virginia Tech” 13)
 10                               6
                                      7
To work, everyone needs to have       8      “University of Virginia”    “Wahoos”
exactly the same table! This is
                                      9      “Virginia Tech”            “Turkeys”
really hard on the Internet, where
nodes leave and join all the time.    10
                                      11
Cache

  Client       Router



  Client                                 Router
                Router
                                                  Yahoo.com
  Client                Cache
                                    Router


               Router
  Client
                                Router


(find-cache caches url)
=> evaluates to address of the cache likely to have request cached.
29th ACM Symposium on Theory of Computing, 1997
Consistent Hashing
           0



       1




        ½
Akamai




    Akamai Headquarters, Cambridge, MA
Charge
Enjoy Today’s Fast Internet and
  remember Danny Lewin’s
  contribution (see today’s class
  post for links to articles)

PS2 Due Wednesday
            Upcoming Help
Today, noon-1:30pm (Kristina, Rice 1st)
Today, 1:15-2:00pm (Dave, Rice 507)
Tuesday, 11am-noon (Dave, Rice 507)       Daniel Lewin
Tuesday, 5-6:30pm (Valerie, Rice 1st)       14 May 1970 –
Tuesday, 6:30-8pm (Jonathan, Rice 1st)    11 September 2001

More Related Content

What's hot

Purely Functional Data Structures in Scala
Purely Functional Data Structures in ScalaPurely Functional Data Structures in Scala
Purely Functional Data Structures in Scala
Vladimir Kostyukov
 
Data Structures In Scala
Data Structures In ScalaData Structures In Scala
Data Structures In Scala
Knoldus Inc.
 
R Cheat Sheet – Data Management
R Cheat Sheet – Data ManagementR Cheat Sheet – Data Management
R Cheat Sheet – Data Management
Dr. Volkan OBAN
 
Data Analysis and Programming in R
Data Analysis and Programming in RData Analysis and Programming in R
Data Analysis and Programming in REshwar Sai
 
The Logical Burrito - pattern matching, term rewriting and unification
The Logical Burrito - pattern matching, term rewriting and unificationThe Logical Burrito - pattern matching, term rewriting and unification
The Logical Burrito - pattern matching, term rewriting and unificationNorman Richards
 
R Programming: Importing Data In R
R Programming: Importing Data In RR Programming: Importing Data In R
R Programming: Importing Data In R
Rsquared Academy
 
Adv. python regular expression by Rj
Adv. python regular expression by RjAdv. python regular expression by Rj
Adv. python regular expression by Rj
Shree M.L.Kakadiya MCA mahila college, Amreli
 
R Workshop for Beginners
R Workshop for BeginnersR Workshop for Beginners
R Workshop for Beginners
Metamarkets
 
Data structures in scala
Data structures in scalaData structures in scala
Data structures in scalaMeetu Maltiar
 
Introduction to Scala
Introduction to ScalaIntroduction to Scala
Introduction to Scala
Aleksandar Prokopec
 
Introduction to R programming
Introduction to R programmingIntroduction to R programming
Introduction to R programming
Alberto Labarga
 
Introduction to Python and TensorFlow
Introduction to Python and TensorFlowIntroduction to Python and TensorFlow
Introduction to Python and TensorFlow
Bayu Aldi Yansyah
 
Programming in R
Programming in RProgramming in R
Programming in R
Smruti Sarangi
 
ScalaBlitz
ScalaBlitzScalaBlitz
Introduction to R Programming
Introduction to R ProgrammingIntroduction to R Programming
Introduction to R Programming
izahn
 
Datatypes in python
Datatypes in pythonDatatypes in python
Datatypes in python
eShikshak
 
Stata Cheat Sheets (all)
Stata Cheat Sheets (all)Stata Cheat Sheets (all)
Stata Cheat Sheets (all)
Laura Hughes
 
Python-Tuples
Python-TuplesPython-Tuples
Python-Tuples
Krishna Nanda
 
R workshop
R workshopR workshop
R workshop
Revanth19921
 

What's hot (20)

Purely Functional Data Structures in Scala
Purely Functional Data Structures in ScalaPurely Functional Data Structures in Scala
Purely Functional Data Structures in Scala
 
Data Structures In Scala
Data Structures In ScalaData Structures In Scala
Data Structures In Scala
 
R Cheat Sheet – Data Management
R Cheat Sheet – Data ManagementR Cheat Sheet – Data Management
R Cheat Sheet – Data Management
 
Data Analysis and Programming in R
Data Analysis and Programming in RData Analysis and Programming in R
Data Analysis and Programming in R
 
The Logical Burrito - pattern matching, term rewriting and unification
The Logical Burrito - pattern matching, term rewriting and unificationThe Logical Burrito - pattern matching, term rewriting and unification
The Logical Burrito - pattern matching, term rewriting and unification
 
R Programming: Importing Data In R
R Programming: Importing Data In RR Programming: Importing Data In R
R Programming: Importing Data In R
 
Adv. python regular expression by Rj
Adv. python regular expression by RjAdv. python regular expression by Rj
Adv. python regular expression by Rj
 
R Workshop for Beginners
R Workshop for BeginnersR Workshop for Beginners
R Workshop for Beginners
 
Data structures in scala
Data structures in scalaData structures in scala
Data structures in scala
 
Introduction to Scala
Introduction to ScalaIntroduction to Scala
Introduction to Scala
 
Introduction to R programming
Introduction to R programmingIntroduction to R programming
Introduction to R programming
 
Introduction to Python and TensorFlow
Introduction to Python and TensorFlowIntroduction to Python and TensorFlow
Introduction to Python and TensorFlow
 
Programming in R
Programming in RProgramming in R
Programming in R
 
Sql server lab_2
Sql server lab_2Sql server lab_2
Sql server lab_2
 
ScalaBlitz
ScalaBlitzScalaBlitz
ScalaBlitz
 
Introduction to R Programming
Introduction to R ProgrammingIntroduction to R Programming
Introduction to R Programming
 
Datatypes in python
Datatypes in pythonDatatypes in python
Datatypes in python
 
Stata Cheat Sheets (all)
Stata Cheat Sheets (all)Stata Cheat Sheets (all)
Stata Cheat Sheets (all)
 
Python-Tuples
Python-TuplesPython-Tuples
Python-Tuples
 
R workshop
R workshopR workshop
R workshop
 

Similar to Class 9: Consistent Hashing

Real Time Big Data Management
Real Time Big Data ManagementReal Time Big Data Management
Real Time Big Data Management
Albert Bifet
 
4.4 hashing02
4.4 hashing024.4 hashing02
4.4 hashing02
Krish_ver2
 
presentation on important DAG,TRIE,Hashing.pptx
presentation on important DAG,TRIE,Hashing.pptxpresentation on important DAG,TRIE,Hashing.pptx
presentation on important DAG,TRIE,Hashing.pptx
jainaaru59
 
Algorithms notes tutorials duniya
Algorithms notes   tutorials duniyaAlgorithms notes   tutorials duniya
Algorithms notes tutorials duniya
TutorialsDuniya.com
 
R language introduction
R language introductionR language introduction
R language introduction
Shashwat Shriparv
 
Presentation.pptx
Presentation.pptxPresentation.pptx
Presentation.pptx
AgonySingh
 
Meet scala
Meet scalaMeet scala
Meet scala
Wojciech Pituła
 
Statistics lab 1
Statistics lab 1Statistics lab 1
Statistics lab 1
University of Salerno
 
R Basics
R BasicsR Basics
Query Optimization - Brandon Latronica
Query Optimization - Brandon LatronicaQuery Optimization - Brandon Latronica
Query Optimization - Brandon Latronica
"FENG "GEORGE"" YU
 
Hive Functions Cheat Sheet
Hive Functions Cheat SheetHive Functions Cheat Sheet
Hive Functions Cheat Sheet
Hortonworks
 
Hashing In Data Structure Download PPT i
Hashing In Data Structure Download PPT iHashing In Data Structure Download PPT i
Hashing In Data Structure Download PPT i
cajiwol341
 
(How) can we benefit from adopting scala?
(How) can we benefit from adopting scala?(How) can we benefit from adopting scala?
(How) can we benefit from adopting scala?Tomasz Wrobel
 
Monads and Monoids by Oleksiy Dyagilev
Monads and Monoids by Oleksiy DyagilevMonads and Monoids by Oleksiy Dyagilev
Monads and Monoids by Oleksiy Dyagilev
JavaDayUA
 
Rcommands-for those who interested in R.
Rcommands-for those who interested in R.Rcommands-for those who interested in R.
Rcommands-for those who interested in R.
Dr. Volkan OBAN
 
Hash presentation
Hash presentationHash presentation
Hash presentation
omercode
 
Aggregate.pptx
Aggregate.pptxAggregate.pptx
Aggregate.pptx
Ramakrishna Reddy Bijjam
 
18. Dictionaries, Hash-Tables and Set
18. Dictionaries, Hash-Tables and Set18. Dictionaries, Hash-Tables and Set
18. Dictionaries, Hash-Tables and Set
Intro C# Book
 

Similar to Class 9: Consistent Hashing (20)

Real Time Big Data Management
Real Time Big Data ManagementReal Time Big Data Management
Real Time Big Data Management
 
Hashing
HashingHashing
Hashing
 
4.4 hashing02
4.4 hashing024.4 hashing02
4.4 hashing02
 
presentation on important DAG,TRIE,Hashing.pptx
presentation on important DAG,TRIE,Hashing.pptxpresentation on important DAG,TRIE,Hashing.pptx
presentation on important DAG,TRIE,Hashing.pptx
 
Algorithms notes tutorials duniya
Algorithms notes   tutorials duniyaAlgorithms notes   tutorials duniya
Algorithms notes tutorials duniya
 
R language introduction
R language introductionR language introduction
R language introduction
 
Presentation.pptx
Presentation.pptxPresentation.pptx
Presentation.pptx
 
Meet scala
Meet scalaMeet scala
Meet scala
 
Statistics lab 1
Statistics lab 1Statistics lab 1
Statistics lab 1
 
R Basics
R BasicsR Basics
R Basics
 
Query Optimization - Brandon Latronica
Query Optimization - Brandon LatronicaQuery Optimization - Brandon Latronica
Query Optimization - Brandon Latronica
 
Hive Functions Cheat Sheet
Hive Functions Cheat SheetHive Functions Cheat Sheet
Hive Functions Cheat Sheet
 
Hashing In Data Structure Download PPT i
Hashing In Data Structure Download PPT iHashing In Data Structure Download PPT i
Hashing In Data Structure Download PPT i
 
(How) can we benefit from adopting scala?
(How) can we benefit from adopting scala?(How) can we benefit from adopting scala?
(How) can we benefit from adopting scala?
 
Monads and Monoids by Oleksiy Dyagilev
Monads and Monoids by Oleksiy DyagilevMonads and Monoids by Oleksiy Dyagilev
Monads and Monoids by Oleksiy Dyagilev
 
Rcommands-for those who interested in R.
Rcommands-for those who interested in R.Rcommands-for those who interested in R.
Rcommands-for those who interested in R.
 
Hash presentation
Hash presentationHash presentation
Hash presentation
 
Q
QQ
Q
 
Aggregate.pptx
Aggregate.pptxAggregate.pptx
Aggregate.pptx
 
18. Dictionaries, Hash-Tables and Set
18. Dictionaries, Hash-Tables and Set18. Dictionaries, Hash-Tables and Set
18. Dictionaries, Hash-Tables and Set
 

More from David Evans

Cryptocurrency Jeopardy!
Cryptocurrency Jeopardy!Cryptocurrency Jeopardy!
Cryptocurrency Jeopardy!
David Evans
 
Trick or Treat?: Bitcoin for Non-Believers, Cryptocurrencies for Cypherpunks
Trick or Treat?: Bitcoin for Non-Believers, Cryptocurrencies for CypherpunksTrick or Treat?: Bitcoin for Non-Believers, Cryptocurrencies for Cypherpunks
Trick or Treat?: Bitcoin for Non-Believers, Cryptocurrencies for Cypherpunks
David Evans
 
Hidden Services, Zero Knowledge
Hidden Services, Zero KnowledgeHidden Services, Zero Knowledge
Hidden Services, Zero Knowledge
David Evans
 
Anonymity in Bitcoin
Anonymity in BitcoinAnonymity in Bitcoin
Anonymity in Bitcoin
David Evans
 
Midterm Confirmations
Midterm ConfirmationsMidterm Confirmations
Midterm Confirmations
David Evans
 
Scripting Transactions
Scripting TransactionsScripting Transactions
Scripting Transactions
David Evans
 
How to Live in Paradise
How to Live in ParadiseHow to Live in Paradise
How to Live in Paradise
David Evans
 
Bitcoin Script
Bitcoin ScriptBitcoin Script
Bitcoin Script
David Evans
 
Mining Economics
Mining EconomicsMining Economics
Mining Economics
David Evans
 
Mining
MiningMining
Mining
David Evans
 
The Blockchain
The BlockchainThe Blockchain
The Blockchain
David Evans
 
Becoming More Paranoid
Becoming More ParanoidBecoming More Paranoid
Becoming More Paranoid
David Evans
 
Asymmetric Key Signatures
Asymmetric Key SignaturesAsymmetric Key Signatures
Asymmetric Key Signatures
David Evans
 
Introduction to Cryptography
Introduction to CryptographyIntroduction to Cryptography
Introduction to Cryptography
David Evans
 
Class 1: What is Money?
Class 1: What is Money?Class 1: What is Money?
Class 1: What is Money?
David Evans
 
Multi-Party Computation for the Masses
Multi-Party Computation for the MassesMulti-Party Computation for the Masses
Multi-Party Computation for the Masses
David Evans
 
Proof of Reserve
Proof of ReserveProof of Reserve
Proof of Reserve
David Evans
 
Silk Road
Silk RoadSilk Road
Silk Road
David Evans
 
Blooming Sidechains!
Blooming Sidechains!Blooming Sidechains!
Blooming Sidechains!
David Evans
 
Useful Proofs of Work, Permacoin
Useful Proofs of Work, PermacoinUseful Proofs of Work, Permacoin
Useful Proofs of Work, Permacoin
David Evans
 

More from David Evans (20)

Cryptocurrency Jeopardy!
Cryptocurrency Jeopardy!Cryptocurrency Jeopardy!
Cryptocurrency Jeopardy!
 
Trick or Treat?: Bitcoin for Non-Believers, Cryptocurrencies for Cypherpunks
Trick or Treat?: Bitcoin for Non-Believers, Cryptocurrencies for CypherpunksTrick or Treat?: Bitcoin for Non-Believers, Cryptocurrencies for Cypherpunks
Trick or Treat?: Bitcoin for Non-Believers, Cryptocurrencies for Cypherpunks
 
Hidden Services, Zero Knowledge
Hidden Services, Zero KnowledgeHidden Services, Zero Knowledge
Hidden Services, Zero Knowledge
 
Anonymity in Bitcoin
Anonymity in BitcoinAnonymity in Bitcoin
Anonymity in Bitcoin
 
Midterm Confirmations
Midterm ConfirmationsMidterm Confirmations
Midterm Confirmations
 
Scripting Transactions
Scripting TransactionsScripting Transactions
Scripting Transactions
 
How to Live in Paradise
How to Live in ParadiseHow to Live in Paradise
How to Live in Paradise
 
Bitcoin Script
Bitcoin ScriptBitcoin Script
Bitcoin Script
 
Mining Economics
Mining EconomicsMining Economics
Mining Economics
 
Mining
MiningMining
Mining
 
The Blockchain
The BlockchainThe Blockchain
The Blockchain
 
Becoming More Paranoid
Becoming More ParanoidBecoming More Paranoid
Becoming More Paranoid
 
Asymmetric Key Signatures
Asymmetric Key SignaturesAsymmetric Key Signatures
Asymmetric Key Signatures
 
Introduction to Cryptography
Introduction to CryptographyIntroduction to Cryptography
Introduction to Cryptography
 
Class 1: What is Money?
Class 1: What is Money?Class 1: What is Money?
Class 1: What is Money?
 
Multi-Party Computation for the Masses
Multi-Party Computation for the MassesMulti-Party Computation for the Masses
Multi-Party Computation for the Masses
 
Proof of Reserve
Proof of ReserveProof of Reserve
Proof of Reserve
 
Silk Road
Silk RoadSilk Road
Silk Road
 
Blooming Sidechains!
Blooming Sidechains!Blooming Sidechains!
Blooming Sidechains!
 
Useful Proofs of Work, Permacoin
Useful Proofs of Work, PermacoinUseful Proofs of Work, Permacoin
Useful Proofs of Work, Permacoin
 

Recently uploaded

Overview on Edible Vaccine: Pros & Cons with Mechanism
Overview on Edible Vaccine: Pros & Cons with MechanismOverview on Edible Vaccine: Pros & Cons with Mechanism
Overview on Edible Vaccine: Pros & Cons with Mechanism
DeeptiGupta154
 
CLASS 11 CBSE B.St Project AIDS TO TRADE - INSURANCE
CLASS 11 CBSE B.St Project AIDS TO TRADE - INSURANCECLASS 11 CBSE B.St Project AIDS TO TRADE - INSURANCE
CLASS 11 CBSE B.St Project AIDS TO TRADE - INSURANCE
BhavyaRajput3
 
Supporting (UKRI) OA monographs at Salford.pptx
Supporting (UKRI) OA monographs at Salford.pptxSupporting (UKRI) OA monographs at Salford.pptx
Supporting (UKRI) OA monographs at Salford.pptx
Jisc
 
Digital Tools and AI for Teaching Learning and Research
Digital Tools and AI for Teaching Learning and ResearchDigital Tools and AI for Teaching Learning and Research
Digital Tools and AI for Teaching Learning and Research
Vikramjit Singh
 
Phrasal Verbs.XXXXXXXXXXXXXXXXXXXXXXXXXX
Phrasal Verbs.XXXXXXXXXXXXXXXXXXXXXXXXXXPhrasal Verbs.XXXXXXXXXXXXXXXXXXXXXXXXXX
Phrasal Verbs.XXXXXXXXXXXXXXXXXXXXXXXXXX
MIRIAMSALINAS13
 
Acetabularia Information For Class 9 .docx
Acetabularia Information For Class 9  .docxAcetabularia Information For Class 9  .docx
Acetabularia Information For Class 9 .docx
vaibhavrinwa19
 
Francesca Gottschalk - How can education support child empowerment.pptx
Francesca Gottschalk - How can education support child empowerment.pptxFrancesca Gottschalk - How can education support child empowerment.pptx
Francesca Gottschalk - How can education support child empowerment.pptx
EduSkills OECD
 
Language Across the Curriculm LAC B.Ed.
Language Across the  Curriculm LAC B.Ed.Language Across the  Curriculm LAC B.Ed.
Language Across the Curriculm LAC B.Ed.
Atul Kumar Singh
 
Welcome to TechSoup New Member Orientation and Q&A (May 2024).pdf
Welcome to TechSoup   New Member Orientation and Q&A (May 2024).pdfWelcome to TechSoup   New Member Orientation and Q&A (May 2024).pdf
Welcome to TechSoup New Member Orientation and Q&A (May 2024).pdf
TechSoup
 
Chapter 3 - Islamic Banking Products and Services.pptx
Chapter 3 - Islamic Banking Products and Services.pptxChapter 3 - Islamic Banking Products and Services.pptx
Chapter 3 - Islamic Banking Products and Services.pptx
Mohd Adib Abd Muin, Senior Lecturer at Universiti Utara Malaysia
 
The approach at University of Liverpool.pptx
The approach at University of Liverpool.pptxThe approach at University of Liverpool.pptx
The approach at University of Liverpool.pptx
Jisc
 
The Roman Empire A Historical Colossus.pdf
The Roman Empire A Historical Colossus.pdfThe Roman Empire A Historical Colossus.pdf
The Roman Empire A Historical Colossus.pdf
kaushalkr1407
 
Honest Reviews of Tim Han LMA Course Program.pptx
Honest Reviews of Tim Han LMA Course Program.pptxHonest Reviews of Tim Han LMA Course Program.pptx
Honest Reviews of Tim Han LMA Course Program.pptx
timhan337
 
Unit 8 - Information and Communication Technology (Paper I).pdf
Unit 8 - Information and Communication Technology (Paper I).pdfUnit 8 - Information and Communication Technology (Paper I).pdf
Unit 8 - Information and Communication Technology (Paper I).pdf
Thiyagu K
 
CACJapan - GROUP Presentation 1- Wk 4.pdf
CACJapan - GROUP Presentation 1- Wk 4.pdfCACJapan - GROUP Presentation 1- Wk 4.pdf
CACJapan - GROUP Presentation 1- Wk 4.pdf
camakaiclarkmusic
 
Home assignment II on Spectroscopy 2024 Answers.pdf
Home assignment II on Spectroscopy 2024 Answers.pdfHome assignment II on Spectroscopy 2024 Answers.pdf
Home assignment II on Spectroscopy 2024 Answers.pdf
Tamralipta Mahavidyalaya
 
Biological Screening of Herbal Drugs in detailed.
Biological Screening of Herbal Drugs in detailed.Biological Screening of Herbal Drugs in detailed.
Biological Screening of Herbal Drugs in detailed.
Ashokrao Mane college of Pharmacy Peth-Vadgaon
 
Unit 2- Research Aptitude (UGC NET Paper I).pdf
Unit 2- Research Aptitude (UGC NET Paper I).pdfUnit 2- Research Aptitude (UGC NET Paper I).pdf
Unit 2- Research Aptitude (UGC NET Paper I).pdf
Thiyagu K
 
Model Attribute Check Company Auto Property
Model Attribute  Check Company Auto PropertyModel Attribute  Check Company Auto Property
Model Attribute Check Company Auto Property
Celine George
 
2024.06.01 Introducing a competency framework for languag learning materials ...
2024.06.01 Introducing a competency framework for languag learning materials ...2024.06.01 Introducing a competency framework for languag learning materials ...
2024.06.01 Introducing a competency framework for languag learning materials ...
Sandy Millin
 

Recently uploaded (20)

Overview on Edible Vaccine: Pros & Cons with Mechanism
Overview on Edible Vaccine: Pros & Cons with MechanismOverview on Edible Vaccine: Pros & Cons with Mechanism
Overview on Edible Vaccine: Pros & Cons with Mechanism
 
CLASS 11 CBSE B.St Project AIDS TO TRADE - INSURANCE
CLASS 11 CBSE B.St Project AIDS TO TRADE - INSURANCECLASS 11 CBSE B.St Project AIDS TO TRADE - INSURANCE
CLASS 11 CBSE B.St Project AIDS TO TRADE - INSURANCE
 
Supporting (UKRI) OA monographs at Salford.pptx
Supporting (UKRI) OA monographs at Salford.pptxSupporting (UKRI) OA monographs at Salford.pptx
Supporting (UKRI) OA monographs at Salford.pptx
 
Digital Tools and AI for Teaching Learning and Research
Digital Tools and AI for Teaching Learning and ResearchDigital Tools and AI for Teaching Learning and Research
Digital Tools and AI for Teaching Learning and Research
 
Phrasal Verbs.XXXXXXXXXXXXXXXXXXXXXXXXXX
Phrasal Verbs.XXXXXXXXXXXXXXXXXXXXXXXXXXPhrasal Verbs.XXXXXXXXXXXXXXXXXXXXXXXXXX
Phrasal Verbs.XXXXXXXXXXXXXXXXXXXXXXXXXX
 
Acetabularia Information For Class 9 .docx
Acetabularia Information For Class 9  .docxAcetabularia Information For Class 9  .docx
Acetabularia Information For Class 9 .docx
 
Francesca Gottschalk - How can education support child empowerment.pptx
Francesca Gottschalk - How can education support child empowerment.pptxFrancesca Gottschalk - How can education support child empowerment.pptx
Francesca Gottschalk - How can education support child empowerment.pptx
 
Language Across the Curriculm LAC B.Ed.
Language Across the  Curriculm LAC B.Ed.Language Across the  Curriculm LAC B.Ed.
Language Across the Curriculm LAC B.Ed.
 
Welcome to TechSoup New Member Orientation and Q&A (May 2024).pdf
Welcome to TechSoup   New Member Orientation and Q&A (May 2024).pdfWelcome to TechSoup   New Member Orientation and Q&A (May 2024).pdf
Welcome to TechSoup New Member Orientation and Q&A (May 2024).pdf
 
Chapter 3 - Islamic Banking Products and Services.pptx
Chapter 3 - Islamic Banking Products and Services.pptxChapter 3 - Islamic Banking Products and Services.pptx
Chapter 3 - Islamic Banking Products and Services.pptx
 
The approach at University of Liverpool.pptx
The approach at University of Liverpool.pptxThe approach at University of Liverpool.pptx
The approach at University of Liverpool.pptx
 
The Roman Empire A Historical Colossus.pdf
The Roman Empire A Historical Colossus.pdfThe Roman Empire A Historical Colossus.pdf
The Roman Empire A Historical Colossus.pdf
 
Honest Reviews of Tim Han LMA Course Program.pptx
Honest Reviews of Tim Han LMA Course Program.pptxHonest Reviews of Tim Han LMA Course Program.pptx
Honest Reviews of Tim Han LMA Course Program.pptx
 
Unit 8 - Information and Communication Technology (Paper I).pdf
Unit 8 - Information and Communication Technology (Paper I).pdfUnit 8 - Information and Communication Technology (Paper I).pdf
Unit 8 - Information and Communication Technology (Paper I).pdf
 
CACJapan - GROUP Presentation 1- Wk 4.pdf
CACJapan - GROUP Presentation 1- Wk 4.pdfCACJapan - GROUP Presentation 1- Wk 4.pdf
CACJapan - GROUP Presentation 1- Wk 4.pdf
 
Home assignment II on Spectroscopy 2024 Answers.pdf
Home assignment II on Spectroscopy 2024 Answers.pdfHome assignment II on Spectroscopy 2024 Answers.pdf
Home assignment II on Spectroscopy 2024 Answers.pdf
 
Biological Screening of Herbal Drugs in detailed.
Biological Screening of Herbal Drugs in detailed.Biological Screening of Herbal Drugs in detailed.
Biological Screening of Herbal Drugs in detailed.
 
Unit 2- Research Aptitude (UGC NET Paper I).pdf
Unit 2- Research Aptitude (UGC NET Paper I).pdfUnit 2- Research Aptitude (UGC NET Paper I).pdf
Unit 2- Research Aptitude (UGC NET Paper I).pdf
 
Model Attribute Check Company Auto Property
Model Attribute  Check Company Auto PropertyModel Attribute  Check Company Auto Property
Model Attribute Check Company Auto Property
 
2024.06.01 Introducing a competency framework for languag learning materials ...
2024.06.01 Introducing a competency framework for languag learning materials ...2024.06.01 Introducing a competency framework for languag learning materials ...
2024.06.01 Introducing a competency framework for languag learning materials ...
 

Class 9: Consistent Hashing

  • 1. Class 9: Consistent Hashing cs1120 Fall 2011 David Evans 12 September 2011
  • 4. Internet Circa 1998 Client Router Client Router Router Yahoo.com Client Router Router Client Router
  • 5. google.com, November 1998 from archive.org
  • 6.
  • 7. Caching the Internet Cache Client Router Client Router Router Yahoo.com Client Cache Router A Cache stores previous results. If the result is already known Router from the same request recently, Client Router it returns that result. Problem: how do Clients and Routers know which cache to try?
  • 8. Lookup Table Key Value “University of Virginia” “Wahoos” “Virginia Tech” “Turkeys” “University of Michigan” “Wolverines” “MIT” “Beavers” … … Each entry is a (Key . Value) pair. To look up the Value associated with a given Key, search the Keys in order until you find one that matches, and then the value is the associated Value.
  • 9. Examples (define schools (list (cons "University of Virginia" "Wahoos") (cons "Virginia Tech" "Turkeys") (cons "MIT" "Beavers") (cons "UC Santa Cruz" "Banana Slugs"))) > (table-lookup schools "University of Virginia") "Wahoos" > (table-lookup schools "MIT") "Beavers" > (table-lookup schools "UC Irvine") #f
  • 10. Simple Lookup Table Define a procedure, table-lookup, that takes as inputs a table and a key. If the table contains an entry (key . value), the output is value. If there is no entry whose first part matches key, the output is false. 1. Be very optimistic! Since lists are defined recursively, most problems involving lists can be solved with recursive procedures. 2. Think of the simplest input, something you can already solve. This is the base case. For lists, it is often when the list is null. 3. Consider how you would solve the problem using the result for a slightly smaller version of the problem. For lists, the smaller version of the problem is usually the cdr of the list.
  • 11. Simple Lookup Table Define a procedure, table-lookup, that takes as inputs a table and a key. If the table contains an entry (key . value), the output is value. If there is no entry whose first part matches key, the output is false.
  • 12. Simple Lookup Table Define a procedure, table-lookup, that takes as inputs a table and a key. If the table contains an entry (key . value), the output is value. If there is no entry whose first part matches key, the output is false. (define (table-lookup table key) (if (null? table) false (if (equal? (car (car table)) key) (cdr (car table)) (table-lookup (cdr table) key)))) This works…but if the table is big (or there are many caches) it is very slow!
  • 13. Regular Hash Table Index Key Value compute-hash: 0 Key, Size Number 1 Maps a key (which could be any 2 value) and a table size to a number between 0 and Size – 1. 3 This is the position in the table 4 where the Key should be stored. 5 6 > (compute-hash “University of Virginia” 12) 8 7 > (compute-hash “Virginia Tech” 12) 8 “University of Virginia” “Wahoos” 9 …. 9 “Virginia Tech” “Turkeys” 10 11
  • 14. Typical compute-hash Function Convert input to a string (format “~a” x) converts any value x to a string > (format "~a" 23) "23" > (format "~a" "University of Virginia") "University of Virginia" > (format "~a" (cons 1 (cons 2 null))) "(1 2)"
  • 15. Typical compute-hash Function Convert input to a string (format “~a” x) converts any value x to a string Convert each character in the string to a number (char->integer c) converts any character to a number. > (char->integer #A) 65 > (char->integer #U) 85 > (char->integer #space) 32
  • 16. Typical compute-hash Function Convert input to a string (format “~a” x) converts any value x to a string Convert each character in the string to a number (char->integer c) converts any character to a number. Compute the sum of all the numbers, modulo the size of the table.
  • 17. Defining compute-hash (define (compute-hash key size) (modulo (sum-chars (string->list (format "~a" key))) size))
  • 18. Defining sum-chars Define a procedure, sum-chars, that takes as input a list of characters, and outputs the sum of all the character values (as converted by char->integer) in the list. 1. Be very optimistic! Since lists are defined recursively, most problems involving lists can be solved with recursive procedures. 2. Think of the simplest input, something you can already solve. This is the base case. For lists, it is often when the list is null. 3. Consider how you would solve the problem using the result for a slightly smaller version of the problem. For lists, the smaller version of the problem is usually the cdr of the list.
  • 19. Defining sum-chars Define a procedure, sum-chars, that takes as input a list of characters, and outputs the sum of all the character values (as converted by char->integer) in the list. (define (sum-chars p) (if (null? p) 0 (+(char->integer (car p)) (sum-chars (cdr p)))))
  • 20. (define (sum-chars p) (apply + (map char->integer p)))
  • 21. Use of Hash Table in PS2 Note: this uses several things (define (memoize f) you haven’t seen yet. I won’t try to explain them all now. (let ((ht (make-hash))) (lambda (s1 s2) (let ((key (format "~a#~a" s1 s2))) (hash-ref ht key Look up the value of key in the (lambda () hash table, ht. If it has a value, that is the value. If it has no (let ((res (f s1 s2))) value yet, apply this procedure which finds the value by (hash-set! ht key res) applying (f s1 s2) and stores it in the table at the location res))))))) associated with this key.
  • 22. Problem with Regular Hashing Index Key Value 0 > (compute-hash “University of Virginia” 12) 1 8 2 > (compute-hash “Virginia Tech” 12) 3 9 4 …. 5 > (compute-hash “Virginia Tech” 13) 10 6 7 To work, everyone needs to have 8 “University of Virginia” “Wahoos” exactly the same table! This is 9 “Virginia Tech” “Turkeys” really hard on the Internet, where nodes leave and join all the time. 10 11
  • 23. Cache Client Router Client Router Router Yahoo.com Client Cache Router Router Client Router (find-cache caches url) => evaluates to address of the cache likely to have request cached.
  • 24. 29th ACM Symposium on Theory of Computing, 1997
  • 25.
  • 27. Akamai Akamai Headquarters, Cambridge, MA
  • 28.
  • 29. Charge Enjoy Today’s Fast Internet and remember Danny Lewin’s contribution (see today’s class post for links to articles) PS2 Due Wednesday Upcoming Help Today, noon-1:30pm (Kristina, Rice 1st) Today, 1:15-2:00pm (Dave, Rice 507) Tuesday, 11am-noon (Dave, Rice 507) Daniel Lewin Tuesday, 5-6:30pm (Valerie, Rice 1st) 14 May 1970 – Tuesday, 6:30-8pm (Jonathan, Rice 1st) 11 September 2001