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

Language Support for Cloud-Scale Distributed Sy...

Language Support for Cloud-Scale Distributed Systems

BuzzConf Argentina 2017

Christopher Meiklejohn

April 27, 2018
Tweet

More Decks by Christopher Meiklejohn

Other Decks in Research

Transcript

  1. LANGUAGE SUPPORT FOR CLOUD SCALE DISTRIBUTED PROGRAMS Christopher S. Meiklejohn

    Université catholique de Louvain Instituto Superior Técnico Northeastern University
  2. DISTRIBUTED APPLICATIONS TODAY Application users are located all over the

    world. Geo-replicate applications to increase availability and decrease user-perceived latency.
  3. IDEAL: GLOBAL “STRONG CONSISTENCY” Total order allows imperative programming 

    Events happen globally in order  Shared “memory locations” mutated in order Transactional guarantees  Atomicity: atomic commitment  Isolation: mutual exclusion Key insights: slow, but easy to program  Concurrent programs with locks  Correct under arbitrary distribution  Delays under failure
  4. No guaranteed event order globally because of multiple communication paths.

    GEO-REPLICATED MICROSERVICES No guaranteed order within the data center.
  5. REALITY: WEAKLY CONSISTENT MICROSERVICES Events happen in no well-defined order

     How does one write a program where events can happen in any order? No transactional guarantees  How does one enforce either isolation or atomicity Key insights: fast, but difficult to program  Each service needs it’s own failure handling  Each service needs to reason about concurrency  Available under failure
  6. 1988 – ARGUS RPC calls to “guardians”  Guardians are

    microservices  Provides sequential consistency  Invents “promises” to allow asynchrony without sacrificing order Transactions between services using MVCC  Nested transactions used to mask RPC failure  No response, rollback and retry at another replica Academic project funded by MIT/DOD  Built on a language called CLU  Little to no adoption in industry
  7. 1994 – DISTRIBUTED ERLANG Asynchronous message passing  No RPC,

    but can be emulated  Wait when you need the response explicitly Built-in DB constructs  Strongly-consistent database with transactions  No guarantees under failure, might hang arbitrarily Massively successful  Ericsson AXD501  WhatsApp  Riak (NHS, FMK, League of Legends)
  8. 2018 – MICROSOFT ORLEANS RPC calls  Guaranteed ordering 

    Explicit asynchrony when needed Transactional actors  Transactional state transitions  Serializable transactions (2PL/2PC) Adoption within Microsoft  Xbox Live  Halo, Gears of War 4
  9. HISTORICALLY… Total order & serializability is the gold standard 

    Events occur in order and are mutually excluded from one another  Difficult to provide at scale without performance impact Apt room to exploit protocols with weaker isolation  However, how do we know when you can use weak isolation? Is a total order needed for everything?  Can we detect precisely where a total order or serializability is required for correctness?  What is the cost of serializability?  What is “correctness” from the application point of view?
  10. TOTALLY ORDERING EVENTS Total order is expensive  Under failure,

    notes might have to wait arbitrarily long for a response  At geo-scale is prohibitive on performance (Microsoft’s Geo, Google Spanner, CockroachDB) Total order is unnecessary for many operations  Many operation need ordering but not a total order  Provably some operations need consensus Weak ordering sometimes OK  If application invariants can be preserved under weak ordering, why use total ordering?  E.g. precondition invariants (check and proceed with change) need total order to be safe Some application behavior needs consensus to be provably correct!
  11. PRESERVATION OF INVARIANTS 1. Relative order invariants (A; B) 

    Ensuring an implication stays true (P ⟹ Q)  E.g. Marking an order as fulfilled, and then adding it to the list of delivered orders  Can be done without coordination, by sending the object before the referenced object 2. Atomic groups of changes (all-or-nothing)  Updating an object and data derived from that change  E.g. Marking an order as fulfilled and decrementing the item quantity in stock together  Can be done without coordination, by sending the updates together 3. Precondition invariants (if … then else, compare-and-set, etc.)  Updating an object based on a condition  E.g. Only process the order when an item is available, assuming a single item  Requires coordination: isolation of the transaction through mutual exclusion Weaker ordering sufficient for AP invariants. Coordination needed for CAP-sensitive invariants.
  12. Consistency Layer with Shared Storage Communications Layer BEAM (Erlang /

    Elixir) Application Code RESEARCH AGENDA CRDTs for conflict resolution; HATs for transactions Geo-scale reliable and ordered messaging Asynchronous message passing between actors Static analysis and program specification We focus here today.
  13. Consistency Layer with Shared Storage Communications Layer BEAM (Erlang /

    Elixir) Application Code RESEARCH AGENDA CRDTs for conflict resolution; HATs for transactions Geo-scale reliable and ordered messaging Asynchronous message passing between actors Static analysis and program specification We assume distributed actors that communicate through asynchronous message passing.
  14. Consistency Layer with Shared Storage Communications Layer BEAM (Erlang /

    Elixir) Application Code RESEARCH AGENDA CRDTs for conflict resolution; HATs for transactions Geo-scale reliable and ordered messaging Asynchronous message passing between actors Static analysis and program specification
  15. DISTRIBUTED ERLANG All nodes communicate with all other nodes. Nodes

    periodically send heartbeat messages.  Considered “failed” when X missed heartbeats. Point-to-point messaging with a single hop. Nodes use a single TCP connection to communicate. Assumed that a single topology fits all applications All to all “heartbeating” is expensive and prohibitive. Single TCP connection is a bottleneck. Distributed Erlang is not “one size fits all.”
  16. PARTISAN: SCALING “DISTRIBUTED” ERLANG Alternative distribution layer for Erlang and

    Elixir applications.  Can be operated alongside Distributed Erlang Provides point-to-point messaging and failure detection.  Best-effort message delivery  Callback behavior on detection of node failures Pluggable “network topology” backends that can be configured at runtime.  Client/server, large-scale overlays, full mesh, etc.  Backends have various optimizations available Optimizations  Spanning tree optimization  Causal messaging
  17. FULL MESH All nodes communicate with all other nodes. Nodes

    maintain open TCP connections.  Considered “failed” when connection is dropped. Point-to-point messaging with a single hop. Membership is gossiped. Similar to the default Distributed Erlang implementation – as library, not runtime
  18. CLIENT-SERVER Client nodes communicate with server nodes. Server nodes communicate

    with one another. Point-to-point messaging through the server. Nodes maintain open TCP connections.  Considered “failed” when connection is dropped. User Name User Name User Name User Name
  19. HYPARVIEW Supports large-scale networks (10,000+ nodes) Nodes maintain partial views

    of the network  Active views form connected graph  Passive views for backup links used to repair graph connectivity under failure Nodes maintain open TCP connections.  Considered “failed” when connection is dropped.  Some links to passive nodes kept open for “fast” replacement of failed active nodes Point-to-point messaging for connected nodes.  Under partial views, not all nodes might be connected directly.
  20. PARALLELISM Enable multiple TCP connections between nodes for increased parallelism.

    Partition traffic using a partition key.  Automatic placement  Manual partitioning for data-heavy applications Optimal for high-latency applications where latency can slow down sends P1 P1 P2 P3 P2 Messages for P1 always routed through connection 1.
  21. CHANNELS Enable multiple TCP connections between nodes for segmenting traffic.

    Alleviates head-of-line blocking between different types of traffic and destinations. Optimal for isolating slow senders from fast senders Can be combined with parallelism for multiple channels and connections per channel. gossip gossip object object object
  22. MONOTONIC CHANNELS Enable multiple TCP connections between nodes for segmenting

    traffic. Drops messages when state is increasing on the channel to reduce load and transmission of redundant information. Think: growing monotonic hash rings, objects designated with vector clock, CRDTs, etc. object object ring3 ring2 ring1 System avoids transmission of redundant rings through load shedding.
  23. TRANSITIVE MESSAGE DELIVERY Lazily compute a spanning tree as messages

    are being sent – repair tree when necessary. Messages are “forwarded” through tree links for best-effort any-to-any messaging. Nodes can only message nodes actively directly connected.
  24. X-BOT: ORACLE OPTIMIZED OVERLAYS 10 1 2 4-step optimization pass

    for replacement of nodes in the active view with nodes in passive view. (for random selection of active members) Not all links have equal cost – with cost determined by outside “oracle.” Reduce dissemination latency by optimizing overlay accordingly – swap passive and active members.
  25. CAUSAL ORDERING Ensure messages are delivered in causal order 

    FIFO between process pairs of sender/receiver  Holds transitively for sending and receiving messages A B C A Prevent C being received prior to A. Important for overlays where message might not always take the same path! (ie. HyParView, etc.)
  26. RELIABLE DELIVERY Buffer and retransmit messages using acknowledgements from destination

    Per-message or per-channel At-least-once delivery (to the application) Needed for causal delivery where a dropped message might prohibit progress P1 M1 P1 M2 P2 P3 Messages for P1 are periodically retransmitted until acknowledged. P1 M1
  27. Consistency Layer with Shared Storage Communications Layer BEAM (Erlang /

    Elixir) Application Code RESEARCH AGENDA CRDTs for conflict resolution; HATs for transactions Geo-scale reliable and ordered messaging Asynchronous message passing between actors Static analysis and program specification
  28. CRDT-BASED STORAGE How can we deal with conflicts from concurrent

    modification? add(1) add(1) rmv(1) {1} {1} CRDT recognizes remove at B doesn’t eliminate add issued at A, because it didn’t observe it.
  29. CURE: HIGHLY AVAILABLE TRANSACTIONS add(1) {1} {1} inc(1) 1 Transactions

    across data items stored on different servers. add(1) inc(1) rmv(1) dec(1) Snapshots are causally ordered. 1 Effects of concurrent transactions can be merged and never abort.
  30. MANAGING CONSISTENCY Conflict-free Replicated Data Types (CRDTs)  Enable convergence

    of data with weak ordering by predefining rules for conflict resolution Cure: Highly Available Transactions  Causally-consistent snapshots  Avoid need for aborts by merging concurrent updates  Enables atomic commitment and relative ordering of updates Invariant preservation  Causality, CRDTs, and HATs enough for ordering and atomicity invariants  Coordination is still required for precondition invariants  Typically requires ACID transactions – but how do we know when to use them?
  31. Consistency Layer with Shared Storage Communications Layer BEAM (Erlang /

    Elixir) Application Code RESEARCH AGENDA CRDTs for conflict resolution; HATs for transactions Geo-scale reliable and ordered messaging Asynchronous message passing between actors Static analysis and program specification
  32. CONCURRENT REMOVALS We must block on precondition invariants to know

    whether or not it’s safe. wd(500) Withdraw must block to ensure invariant of a non-negative balance in account. (mutual exclusion) balance(500) wd(500) wd(500) balance(500)
  33. IDENTIFYING MUTUAL EXCLUSION Examine operations that might happen concurrently in

    code  Specify all application invariants  If an invariant will be violated based on existing invariants under concurrency, forbid Synthesize coordination only when necessary  Only coordinate when an invariant might be violated by an operation from the application Annotate a program accordingly  CISE shows we can annotate a program accordingly with first-order logic  Can we find a way to integrate this intro the programming model?
  34. CONCLUSION Consensus is safe, but over conservative  Consensus allows

    us to be safe because of a total order  This limits high-availability and fault-tolerance Weak consistency and weak isolation enable performance  Too many protocols, how do we know what protocol to use?  How do we know when it’s safe to be weak? Language support for distribution can help us!  Provide reliable messaging when needed with ordering guarantees  Provide transactional semantics at the language level – picking the right consistency level  Enable analysis for knowing when it’s alright to be weak