$30 off During Our Annual Pro Sale. View Details »

Building Applications with Distributed Erlang

Building Applications with Distributed Erlang

NDC London, 2014

Christopher Meiklejohn

December 04, 2014
Tweet

More Decks by Christopher Meiklejohn

Other Decks in Programming

Transcript

  1. BUILDING APPLICATIONS
    with
    DISTRIBUTED ERLANG
    cmeik
    the adventures of
    hash(<<“author”>>, <<“Christopher Meiklejohn”>>)

    View Slide

  2. who am i
    CMEIK

    View Slide

  3. who am i
    CMEIK

    View Slide

  4. who am i
    CMEIK
    distributed systems engineer
    basho technologies

    View Slide

  5. who am i
    CMEIK
    distributed systems engineer
    basho technologies
    researcher with the
    syncfree project

    View Slide

  6. what is
    THE AGENDA

    View Slide

  7. what is
    THE AGENDA
    (novice)
    1. what is distributed erlang?

    View Slide

  8. what is
    THE AGENDA
    (novice)
    1. what is distributed erlang?
    (erlanger)
    2. where do i go from here?

    View Slide

  9. what is
    DISTRIBUTED ERLANG

    View Slide

  10. what is
    DISTRIBUTED ERLANG
    EXTENSION TO HELP BUILD
    DISTRIBUTED SYSTEMS

    View Slide

  11. what is
    DISTRIBUTED ERLANG
    EXTENSION TO HELP BUILD
    DISTRIBUTED SYSTEMS

    View Slide

  12. what are the goals of a
    DISTRIBUTED SYSTEM

    View Slide

  13. what are the goals of a
    DISTRIBUTED SYSTEM
    “A distributed system is a software system in
    which components located on networked
    computers communicate and coordinate their
    actions by passing messages. The components
    interact with each other in order to achieve a
    common goal. Three significant characteristics of
    distributed systems are: concurrency of
    components, lack of a global clock, and
    independent failure of components.”
    Wikipedia, “Distributed Computing”

    View Slide

  14. what are some examples of a
    DISTRIBUTED SYSTEM

    View Slide

  15. what are some examples of a
    DISTRIBUTED SYSTEM
    distributed databases, riak, cassandra, etc.

    View Slide

  16. what are some examples of a
    DISTRIBUTED SYSTEM
    distributed databases, riak, cassandra, etc.
    master/slave in sql, multi-partition txns

    View Slide

  17. what are some examples of a
    DISTRIBUTED SYSTEM
    distributed databases, riak, cassandra, etc.
    master/slave in sql, multi-partition txns
    web services via rest, soap, etc.

    View Slide

  18. what are some examples of a
    DISTRIBUTED SYSTEM
    distributed databases, riak, cassandra, etc.
    master/slave in sql, multi-partition txns
    web services via rest, soap, etc.
    mobile clients, internet of things

    View Slide

  19. why are distributed systems
    HARD
    L. Peter Deutsch, “Fallacies of Distributed Computing”

    View Slide

  20. why are distributed systems
    HARD
    the network is reliable
    L. Peter Deutsch, “Fallacies of Distributed Computing”

    View Slide

  21. why are distributed systems
    HARD
    the network is reliable
    latency is zero
    L. Peter Deutsch, “Fallacies of Distributed Computing”

    View Slide

  22. why are distributed systems
    HARD
    the network is reliable
    latency is zero
    bandwidth is infinite
    L. Peter Deutsch, “Fallacies of Distributed Computing”

    View Slide

  23. why are distributed systems
    HARD
    the network is reliable
    latency is zero
    bandwidth is infinite
    the network is secure
    L. Peter Deutsch, “Fallacies of Distributed Computing”

    View Slide

  24. why are distributed systems
    HARD
    the network is reliable
    latency is zero
    bandwidth is infinite
    the network is secure
    topology doesn’t change
    L. Peter Deutsch, “Fallacies of Distributed Computing”

    View Slide

  25. why are distributed systems
    HARD
    the network is reliable
    latency is zero
    bandwidth is infinite
    the network is secure
    topology doesn’t change
    there is one administrator
    L. Peter Deutsch, “Fallacies of Distributed Computing”

    View Slide

  26. why are distributed systems
    HARD
    the network is reliable
    latency is zero
    bandwidth is infinite
    the network is secure
    topology doesn’t change
    there is one administrator
    transport cost is zero
    L. Peter Deutsch, “Fallacies of Distributed Computing”

    View Slide

  27. why are distributed systems
    HARD
    the network is reliable
    latency is zero
    bandwidth is infinite
    the network is secure
    topology doesn’t change
    there is one administrator
    transport cost is zero
    the network is homogeneous
    L. Peter Deutsch, “Fallacies of Distributed Computing”

    View Slide

  28. what is
    DISTRIBUTED ERLANG

    View Slide

  29. what is
    DISTRIBUTED ERLANG
    1
    3
    2 4
    5

    View Slide

  30. what is
    DISTRIBUTED ERLANG
    1
    3
    2 4
    5
    transparent
    • message passing
    • links
    • monitors
    transitive
    connections
    (except hidden nodes)
    access control via
    cookies

    View Slide

  31. what is
    DISTRIBUTED ERLANG
    1
    3
    2 4
    5
    transparent
    • message passing
    • links
    • monitors
    transitive
    connections
    (except hidden nodes)
    access control via
    cookies
    6

    View Slide

  32. what is
    DISTRIBUTED ERLANG
    1
    3
    2 4
    5
    transparent
    • message passing
    • links
    • monitors
    transitive
    connections
    (except hidden nodes)
    access control via
    cookies
    6

    View Slide

  33. what is
    DISTRIBUTED ERLANG
    1
    3
    2 4
    5
    transparent
    • message passing
    • links
    • monitors
    transitive
    connections
    (except hidden nodes)
    access control via
    cookies
    6

    View Slide

  34. what is
    DISTRIBUTED ERLANG

    View Slide

  35. what is
    DISTRIBUTED ERLANG
    1 2

    View Slide

  36. what is
    DISTRIBUTED ERLANG
    1
    spawn functions
    on other nodes
    2
    p1 p2

    View Slide

  37. what is
    DISTRIBUTED ERLANG
    1
    spawn functions
    on other nodes
    2
    p1 p2
    monitor or link
    on other nodes

    View Slide

  38. what is
    DISTRIBUTED ERLANG
    1
    spawn functions
    on other nodes
    2
    p1 p2
    monitor or link
    on other nodes
    1 2
    p1 p2

    View Slide

  39. what is
    DISTRIBUTED ERLANG
    1
    spawn functions
    on other nodes
    2
    p1 p2
    monitor or link
    on other nodes
    1 2
    p1

    View Slide

  40. what distributed erlang gets
    RIGHT

    View Slide

  41. what distributed erlang gets
    RIGHT
    assumes unreliable asynchronous message passing

    View Slide

  42. what libraries come with
    DISTRIBUTED ERLANG

    View Slide

  43. what libraries come with
    DISTRIBUTED ERLANG
    global - global name registration and locking

    View Slide

  44. what libraries come with
    DISTRIBUTED ERLANG
    global - global name registration and locking
    pg2 - process group registry

    View Slide

  45. what libraries come with
    DISTRIBUTED ERLANG
    global - global name registration and locking
    pg2 - process group registry
    mnesia - distributed transactions

    View Slide

  46. what libraries come with
    DISTRIBUTED ERLANG
    global - global name registration and locking
    pg2 - process group registry
    mnesia - distributed transactions
    net_kernel - erlang distributed networking kernel

    View Slide

  47. what libraries come with
    DISTRIBUTED ERLANG
    global - global name registration and locking
    pg2 - process group registry
    mnesia - distributed transactions
    net_kernel - erlang distributed networking kernel
    rpc - remote procedure call services

    View Slide

  48. what is
    GLOBAL

    View Slide

  49. what is
    GLOBAL
    global name registration and locking service

    View Slide

  50. what is
    GLOBAL
    global name registration and locking service
    shared state, replicated locally

    View Slide

  51. what is
    GLOBAL
    global name registration and locking service
    shared state, replicated locally
    races under network partitions

    View Slide

  52. what is
    GLOBAL
    global name registration and locking service
    shared state, replicated locally
    races under network partitions
    provides ad-hoc resolution hook

    View Slide

  53. what is
    PG2

    View Slide

  54. what is
    PG2
    distributed process group registry

    View Slide

  55. what is
    PG2
    distributed process group registry
    usually used for work partitioning

    View Slide

  56. what is
    PG2
    distributed process group registry
    usually used for work partitioning
    races under network partitions

    View Slide

  57. what is
    PG2
    distributed process group registry
    usually used for work partitioning
    races under network partitions
    can lose values under network partitions

    View Slide

  58. what is
    PG2
    distributed process group registry
    usually used for work partitioning
    races under network partitions
    can lose values under network partitions
    originally isis inspired, pg descendent

    View Slide

  59. what is
    MNESIA

    View Slide

  60. transactional database in erlang
    what is
    MNESIA

    View Slide

  61. transactional database in erlang
    implemented using replicated ets tables
    what is
    MNESIA

    View Slide

  62. transactional database in erlang
    implemented using replicated ets tables
    global transactions are *expensive*
    what is
    MNESIA

    View Slide

  63. transactional database in erlang
    implemented using replicated ets tables
    global transactions are *expensive*
    network partitions can cause values to be lost
    what is
    MNESIA

    View Slide

  64. what is
    NET_KERNEL

    View Slide

  65. maintenance of network in distributed erlang
    what is
    NET_KERNEL

    View Slide

  66. maintenance of network in distributed erlang
    responsible for detecting failures
    what is
    NET_KERNEL

    View Slide

  67. maintenance of network in distributed erlang
    responsible for detecting failures
    dropped tcp connections, network partitions
    what is
    NET_KERNEL

    View Slide

  68. maintenance of network in distributed erlang
    responsible for detecting failures
    dropped tcp connections, network partitions
    poor mechanism for cluster management
    what is
    NET_KERNEL

    View Slide

  69. what is
    RPC

    View Slide

  70. remote procedure call services
    what is
    RPC

    View Slide

  71. remote procedure call services
    serialized execution of requests
    what is
    RPC

    View Slide

  72. remote procedure call services
    serialized execution of requests
    call to a single node, or multi call
    what is
    RPC

    View Slide

  73. remote procedure call services
    serialized execution of requests
    call to a single node, or multi call
    synchronous programming pattern
    what is
    RPC

    View Slide

  74. what are the
    ANTI-PATTERNS*

    View Slide

  75. what are the
    ANTI-PATTERNS*
    utilizing shared state

    View Slide

  76. what are the
    ANTI-PATTERNS*
    utilizing shared state
    reliance on physical time

    View Slide

  77. what are the
    ANTI-PATTERNS*
    utilizing shared state
    reliance on physical time
    using predesignated masters

    View Slide

  78. what are the
    ANTI-PATTERNS*
    utilizing shared state
    reliance on physical time
    using predesignated masters
    treating the network as synchronous

    View Slide

  79. what are the
    ANTI-PATTERNS*
    utilizing shared state
    reliance on physical time
    using predesignated masters
    treating the network as synchronous
    * also: distributed objects, guaranteed delivery mechanisms, distributed
    serializable transactions, etc.

    View Slide

  80. unfortunately these mechanisms are
    NAIVE
    so, what can do we and what have we
    LEARNED

    View Slide

  81. what about
    CLUSTER MEMBERSHIP

    View Slide

  82. what about
    CLUSTER MEMBERSHIP
    1
    3
    2
    4

    View Slide

  83. what about
    CLUSTER MEMBERSHIP
    fixed membership, a priori
    1
    3
    2
    4

    View Slide

  84. what about
    CLUSTER MEMBERSHIP
    fixed membership, a priori
    don’t tie to net_kernel,
    net_ticktime
    1
    3
    2
    4

    View Slide

  85. what about
    CLUSTER MEMBERSHIP
    fixed membership, a priori
    don’t tie to net_kernel,
    net_ticktime
    store information locally,
    gossip
    1
    3
    2
    4

    View Slide

  86. what about
    CLUSTER MEMBERSHIP
    fixed membership, a priori
    don’t tie to net_kernel,
    net_ticktime
    store information locally,
    gossip
    hyparview, plumtree, thicket
    1
    3
    2
    4

    View Slide

  87. what about
    FAILURE DETECTION
    1
    3
    2
    4

    View Slide

  88. what about
    FAILURE DETECTION
    detection of delays vs.
    failed nodes
    1
    3
    2
    4

    View Slide

  89. what about
    FAILURE DETECTION
    detection of delays vs.
    failed nodes
    net_kernel, net_ticktime
    1
    3
    2
    4

    View Slide

  90. what about
    FAILURE DETECTION
    detection of delays vs.
    failed nodes
    net_kernel, net_ticktime
    the φ accrual
    failure detector
    1
    3
    2
    4

    View Slide

  91. what about
    FAILURE DETECTION
    detection of delays vs.
    failed nodes
    net_kernel, net_ticktime
    the φ accrual
    failure detector
    swim: membership and
    failure detector
    1
    3
    2
    4

    View Slide

  92. what about
    VALUE DIVERGENCE

    View Slide

  93. what about
    VALUE DIVERGENCE
    replicated data can diverge
    1 1

    View Slide

  94. what about
    VALUE DIVERGENCE
    replicated data can diverge
    1
    3
    2
    1

    View Slide

  95. what about
    VALUE DIVERGENCE
    replicated data can diverge
    1
    3
    2
    1
    ?

    View Slide

  96. what about
    VALUE DIVERGENCE
    replicated data can diverge
    identify concurrency
    1
    3
    2
    1
    ?

    View Slide

  97. what about
    VALUE DIVERGENCE
    replicated data can diverge
    lamport clock,
    vector clocks,
    version vectors,
    wall clock
    identify concurrency
    1
    3
    2
    1
    ?

    View Slide

  98. what about
    VALUE DIVERGENCE
    replicated data can diverge
    lamport clock,
    vector clocks,
    version vectors,
    wall clock
    identify concurrency
    how to resolve?
    lww vs. siblings vs. crdt
    1
    3
    2
    1
    ?

    View Slide

  99. what about
    DISTRIBUTION BUFFERS

    View Slide

  100. what about
    DISTRIBUTION BUFFERS
    1 2
    p1
    p3
    p2

    View Slide

  101. what about
    DISTRIBUTION BUFFERS
    1 2
    p1
    p3
    p2

    View Slide

  102. what about
    DISTRIBUTION BUFFERS
    1 2
    p1
    p3
    p2
    large objects can cause
    head-of-line blocking

    View Slide

  103. what about
    DISTRIBUTION BUFFERS
    1 2
    p1
    p3
    p2
    large objects can cause
    head-of-line blocking
    move objects to
    tcp sockets

    View Slide

  104. what about
    DISTRIBUTION BUFFERS
    1 2
    p1
    p3
    p2
    large objects can cause
    head-of-line blocking
    move objects to
    tcp sockets
    increase distribution
    port buffer size

    View Slide

  105. what about
    DISTRIBUTION BUFFERS
    1 2
    p1
    p3
    p2
    large objects can cause
    head-of-line blocking
    move objects to
    tcp sockets
    increase distribution
    port buffer size
    beware unbounded
    queues

    View Slide

  106. what about
    LEADER ELECTION

    View Slide

  107. what about
    LEADER ELECTION
    1
    2
    3
    4

    View Slide

  108. what about
    LEADER ELECTION
    gen_leader assumes
    fixed topology
    1
    2
    3
    4

    View Slide

  109. what about
    LEADER ELECTION
    gen_leader assumes
    fixed topology
    use paxos or raft
    1
    2
    3
    4

    View Slide

  110. what about
    LEADER ELECTION
    gen_leader assumes
    fixed topology
    use paxos or raft
    gen_leader known
    to deadlock
    1
    2
    3
    4

    View Slide

  111. what about
    MESSAGE FORMATS

    View Slide

  112. what about
    MESSAGE FORMATS
    v1 v2

    View Slide

  113. what about
    MESSAGE FORMATS
    mixed version clusters
    reality in large systems
    v1 v2

    View Slide

  114. what about
    MESSAGE FORMATS
    mixed version clusters
    reality in large systems
    keep formats compatible
    v1 v2

    View Slide

  115. what about
    MESSAGE FORMATS
    mixed version clusters
    reality in large systems
    keep formats compatible
    upgrade to new format
    v1 v2

    View Slide

  116. what about
    MESSAGE DELIVERY

    View Slide

  117. what about
    MESSAGE DELIVERY
    message delivery not
    guaranteed with
    failures

    View Slide

  118. what about
    MESSAGE DELIVERY
    message delivery not
    guaranteed with
    failures
    1
    2

    View Slide

  119. what about
    MESSAGE DELIVERY
    message delivery not
    guaranteed with
    failures
    1
    2
    1
    2
    3
    4

    View Slide

  120. what about
    MESSAGE DELIVERY
    message delivery not
    guaranteed with
    failures
    1
    2
    1
    1
    2
    2
    3
    1 4
    3
    4

    View Slide

  121. what can we take away from this
    DISCUSSION

    View Slide

  122. what are the
    LESSONS

    View Slide

  123. distributed erlang gets you part of the way
    but, you still have to understand the problems
    and the tradeoffs
    what are the
    LESSONS

    View Slide

  124. distributed erlang gets you part of the way
    but, you still have to understand the problems
    and the tradeoffs
    what are the
    LESSONS
    http://christophermeiklejohn.com/distributed/systems/
    2013/07/12/readings-in-distributed-systems.html

    View Slide

  125. what are some useful
    ERLANG LIBRARIES

    View Slide

  126. what are some useful
    ERLANG LIBRARIES
    riak_core: distributed systems toolkit
    https://github.com/basho/riak_core

    View Slide

  127. what are some useful
    ERLANG LIBRARIES
    riak_core: distributed systems toolkit
    https://github.com/basho/riak_core
    riak_ensemble: generic multi-paxos framework
    https://github.com/basho/riak_ensemble

    View Slide

  128. what are some useful
    ERLANG LIBRARIES
    riak_core: distributed systems toolkit
    https://github.com/basho/riak_core
    riak_ensemble: generic multi-paxos framework
    https://github.com/basho/riak_ensemble
    riak_dt: conflict-free replicated data types
    https://github.com/basho/riak_dt

    View Slide

  129. what are some useful
    ERLANG LIBRARIES
    riak_core: distributed systems toolkit
    https://github.com/basho/riak_core
    riak_ensemble: generic multi-paxos framework
    https://github.com/basho/riak_ensemble
    riak_dt: conflict-free replicated data types
    https://github.com/basho/riak_dt
    riak_test: riak_core testing framework
    https://github.com/basho/riak_test

    View Slide

  130. what are some useful
    RESEARCH PROJECTS

    View Slide

  131. what are some useful
    RESEARCH PROJECTS
    syncfree: large-scale computation on erlang
    https://github.com/syncfree

    View Slide

  132. what are some useful
    RESEARCH PROJECTS
    syncfree: large-scale computation on erlang
    https://github.com/syncfree
    release: large-scale erlang deployments
    https://github.com/release-project/

    View Slide

  133. what are some useful
    RESEARCH PROJECTS
    syncfree: large-scale computation on erlang
    https://github.com/syncfree
    release: large-scale erlang deployments
    https://github.com/release-project/
    paraphrase: parallel computation
    https://github.com/paraphrase

    View Slide

  134. what are some
    PUBLICATIONS

    View Slide

  135. what are some
    PUBLICATIONS

    View Slide

  136. what are some
    PUBLICATIONS

    View Slide

  137. what are some
    PUBLICATIONS

    View Slide

  138. what are some
    PUBLICATIONS

    View Slide

  139. what are some
    PUBLICATIONS

    View Slide

  140. what are some
    PUBLICATIONS
    pid reuse
    unreliable failure detectors
    unreliable delivery of messages
    …and more!

    View Slide

  141. do you have any
    questions?
    THANKS!

    View Slide

  142. do you have any
    questions?
    THANKS!

    View Slide