Upgrade to Pro — share decks privately, control downloads, hide ads and more …

How the Web Works: Lecture 9

How the Web Works: Lecture 9

This talk was designed for a class (98-135) taught at Carnegie Mellon University in Spring 2010.

Abhinav Sharma

January 09, 2014
Tweet

More Decks by Abhinav Sharma

Other Decks in Education

Transcript

  1. Homeworks Overall, I failed =( Should’ve done it in winter

    Get 3 Points to Pass Hopefully, 10 by the end
  2. Homeworks Overall, I failed =( Should’ve done it in winter

    Get 3 Points to Pass Hopefully, 10 by the end I don’t want to fail anyone
  3. Let encrypt with a key! ENC(K, “MES”) = “NFT” |

    DEC(K, “NFT”) = “MES” K = “Shift One Alphabet”
  4. Let encrypt with a key! But how do we share

    the key? ENC(K, “MES”) = “NFT” | DEC(K, “NFT”) = “MES” K = “Shift One Alphabet”
  5. n = p * q Given These Easy to Compute

    Given This Possible but...
  6. RSA

  7. Public Key Encryption Create an Algorithm that... uses n to

    encrypt but needs p & q to decrypt Publish n as public key
  8. Public Key Encryption Create an Algorithm that... uses n to

    encrypt but needs p & q to decrypt Publish n as public key Keep p & q
  9. Public Key Encryption Create an Algorithm that... uses n to

    encrypt but needs p & q to decrypt Publish n as public key Keep p & q Heard of PGP?
  10. More Generally Distributed Hash Table Given a Key, get the

    Value Stored across computers Google’s Index (GFS) So, how do you find a file?
  11. Assignment Assign Key K to Node K If Node K

    doesn’t exist ... assign to next node 1 3 4 5 7 9 1 1 1 6 12 2 8 13 4 9 15 5 11 16
  12. 1 6 12 2 8 13 4 9 15 5

    11 16 1 3 4 5 7 9 12 15
  13. 1 6 12 2 8 13 4 9 15 5

    11 16 1 3 4 5 7 9 12 15
  14. 16 1 6 12 2 8 13 4 9 15

    5 11 1 3 4 5 7 9 12 15
  15. Searching For key K ~ For Node K Linear Search

    Start at Machine 1, goto next ... so on until found! 1 3 4 5 7 9 1 1 1 6 12 2 8 13 4 9 15 5 11 16
  16. Binary Search Is 8 in the list? What position is

    it? 1 3 5 6 8 9 1 3 5 6 8 9 6 8 9
  17. Binary Search Is 8 in the list? What position is

    it? 1 3 5 6 8 9 1 3 5 6 8 9 6 8 9 8 9
  18. 16 1 6 12 2 8 13 4 9 15

    5 11 1 3 4 5 7 9 12 15
  19. 16 1 6 12 2 8 13 4 9 15

    5 11 1 3 4 5 7 9 12 15 Each machine stores address to some others!
  20. Finger Table 1 3 4 5 7 9 1 1

    1 6 12 2 8 13 4 9 15 5 11 16
  21. Finger Table Total Machines (2^m) = 8 1 3 4

    5 7 9 1 1 1 6 12 2 8 13 4 9 15 5 11 16
  22. Finger Table Total Machines (2^m) = 8 Machine N7 stores:

    1 3 4 5 7 9 1 1 1 6 12 2 8 13 4 9 15 5 11 16
  23. Finger Table Total Machines (2^m) = 8 Machine N7 stores:

    addr(N7 + 1) addr(N7 + 2) addr(N7 + 4) = addr(N7 + 2^(m-1)) 1 3 4 5 7 9 1 1 1 6 12 2 8 13 4 9 15 5 11 16
  24. Finger Table Total Machines (2^m) = 8 Machine N7 stores:

    addr(N7 + 1) addr(N7 + 2) addr(N7 + 4) = addr(N7 + 2^(m-1)) Can Take short-cuts! 1 3 4 5 7 9 1 1 1 6 12 2 8 13 4 9 15 5 11 16
  25. 16 1 6 12 2 8 13 4 9 15

    5 11 1 3 4 5 7 9 12 15
  26. 16 1 6 12 2 8 13 4 9 15

    5 11 1 3 4 5 7 9 12 15
  27. 16 1 6 12 2 8 13 4 9 15

    5 11 1 3 4 5 7 9 12 15 Make Biggest Jump | Too Low | Use N7’s table
  28. 16 1 6 12 2 8 13 4 9 15

    5 11 1 3 4 5 7 9 12 15 Make Biggest Jump | Too Low | Use N7’s table
  29. 16 1 6 12 2 8 13 4 9 15

    5 11 1 3 4 5 7 9 12 15
  30. 16 1 6 12 2 8 13 4 9 15

    5 11 1 3 4 5 7 9 12 15
  31. 16 1 6 12 2 8 13 4 9 15

    5 11 1 3 4 5 7 9 12 15 Halve the remaining ring
  32. 16 1 6 12 2 8 13 4 9 15

    5 11 1 3 4 5 7 9 12 15 Halve the remaining ring
  33. 16 1 6 12 2 8 13 4 9 15

    5 11 1 3 4 5 7 9 12 15
  34. 16 1 6 12 2 8 13 4 9 15

    5 11 1 3 4 5 7 9 12 15
  35. 16 1 6 12 2 8 13 4 9 15

    5 11 1 3 4 5 7 9 12 15 Done!
  36. Chord Protocol 1 3 4 5 7 9 1 1

    1 6 12 2 8 13 4 9 15 5 11 16 http://en.wikipedia.org/wiki/Chord_%28peer-to-peer%29
  37. Chord Protocol log(N) Performance 1 3 4 5 7 9

    1 1 1 6 12 2 8 13 4 9 15 5 11 16 http://en.wikipedia.org/wiki/Chord_%28peer-to-peer%29
  38. Chord Protocol log(N) Performance Fully Decentralizes P2P 1 3 4

    5 7 9 1 1 1 6 12 2 8 13 4 9 15 5 11 16 http://en.wikipedia.org/wiki/Chord_%28peer-to-peer%29
  39. Chord Protocol log(N) Performance Fully Decentralizes P2P Napster was Centralized

    1 3 4 5 7 9 1 1 1 6 12 2 8 13 4 9 15 5 11 16 http://en.wikipedia.org/wiki/Chord_%28peer-to-peer%29
  40. Chord Protocol log(N) Performance Fully Decentralizes P2P Napster was Centralized

    ... hence closed down! 1 3 4 5 7 9 1 1 1 6 12 2 8 13 4 9 15 5 11 16 http://en.wikipedia.org/wiki/Chord_%28peer-to-peer%29
  41. Chord Protocol log(N) Performance Fully Decentralizes P2P Napster was Centralized

    ... hence closed down! RIAA/MPAA: Oh Noes! 1 3 4 5 7 9 1 1 1 6 12 2 8 13 4 9 15 5 11 16 http://en.wikipedia.org/wiki/Chord_%28peer-to-peer%29
  42. function Cook( i1, i2, f ) { alert("get the "

    + i1); f(i1); f(i2); } Cook( "lobster", "water", PutInPot ); Cook( "chicken", "coconut", BoomBoom );
  43. Map

  44. var a = [1,2,3]; for (i=0; i<a.length; i++) { a[i]

    = a[i] * 2; } for (i=0; i<a.length; i++) { alert(a[i]); }
  45. function map(fmap, a) { for (i = 0; i <

    a.length; i++) { a[i] = fmap(a[i]); } } map( function(x){return x*2;}, a ); map( alert, a );
  46. function sum(a) { var s = 0; for (i =

    0; i < a.length; i++) s += a[i]; return s; } function join(a) { var s = ""; for (i = 0; i < a.length; i++) s += a[i]; return s; }
  47. function reduce(fred, a, init) { var s = init; for

    (i = 0; i < a.length; i++) s = fred( s, a[i] ); return s; }
  48. function sum(a) { return reduce( function(a, b){ return a +

    b; }, a, 0 ); } function join(a) { return reduce( function(a, b){ return a + b; }, a, "" ); }
  49. Map [1, 2, 3, 4, 5] [2, 4, 6, 8

    , 10] [One, Two, Three, Four , Five] Reduce
  50. Map [1, 2, 3, 4, 5] [2, 4, 6, 8

    , 10] [One, Two, Three, Four , Five] Reduce [1, 1, 1, 1, 1]
  51. Map [1, 2, 3, 4, 5] [2, 4, 6, 8

    , 10] [One, Two, Three, Four , Five] Reduce [1, 1, 1, 1, 1] 5
  52. Map [1, 2, 3, 4, 5] [2, 4, 6, 8

    , 10] [One, Two, Three, Four , Five] Reduce [1, 1, 1, 1, 1] 5 “11111”
  53. “Without understanding functional programming, you can't invent MapReduce. The very

    fact that Google invented MapReduce, and Microsoft didn't, says something about why Microsoft is still playing catch up” - Joel Spolsky
  54. Pop Quiz [1, 2, 3, 4, 5] [“odd”, “even”, “odd”,

    “even”, “odd”] “oddevenoddevenoddeven”
  55. foo foo baz bar gor baz goo bar foo foo

    baz bar gor baz goo bar
  56. foo foo baz bar gor baz goo bar foo foo

    baz bar gor baz goo bar Mapper Mapper
  57. foo foo baz bar gor baz goo bar foo foo

    baz bar gor baz goo bar Mapper Mapper foo 1 foo 1 baz 1 bar 1 gor 1 baz 1 goo 1 bar 1
  58. foo foo baz bar gor baz goo bar foo foo

    baz bar gor baz goo bar Mapper Mapper foo 1 foo 1 baz 1 bar 1 gor 1 baz 1 goo 1 bar 1 Bucket by Key
  59. foo foo baz bar gor baz goo bar foo foo

    baz bar gor baz goo bar Mapper Mapper foo 1 foo 1 baz 1 bar 1 gor 1 baz 1 goo 1 bar 1 Bucket by Key [foo, foo] [baz, baz] [bar, bar] [goo] [gor]
  60. foo foo baz bar gor baz goo bar foo foo

    baz bar gor baz goo bar Mapper Mapper foo 1 foo 1 baz 1 bar 1 gor 1 baz 1 goo 1 bar 1 Bucket by Key [foo, foo] [baz, baz] [bar, bar] [goo] [gor] foo reducer foo reducer foo reducer foo reducer foo reducer
  61. foo foo baz bar gor baz goo bar foo foo

    baz bar gor baz goo bar Mapper Mapper foo 1 foo 1 baz 1 bar 1 gor 1 baz 1 goo 1 bar 1 Bucket by Key [foo, foo] [baz, baz] [bar, bar] [goo] [gor] foo reducer foo reducer foo reducer foo reducer foo reducer 2 2 2 1 1
  62. Who Does What? User: Write Mapper and Reducer Hadoop: Splitting,

    Bucketing Cons: Restricted Paradigm Pros: Generalized, Safe
  63. Who Does What? User: Write Mapper and Reducer Hadoop: Splitting,

    Bucketing Cons: Restricted Paradigm Pros: Generalized, Safe Implementing can be tricky!
  64. The Point People talk about scaling ... but now you

    know it! Distributing Files Distributing Computation
  65. Higher Level Point This isn’t a CS class... ... but

    I’m a CS major =P Its not all HTML/CSS There’s some serious CS here!
  66. Redundancy Replicate across computers Main server balances load Other servers

    serve content Also useful for data backups Usually Host Managed
  67. Caching PHP is dynamic ... usually unnecessarily Calculate, cache, reserve

    Memoization PHP/memcached http://en.wikipedia.org/wiki/Memcached