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

Bloom: A Language For Disorderly Distributed Pr...

Bloom: A Language For Disorderly Distributed Programming

Wicked Good Ruby '13.

Christopher Meiklejohn

October 13, 2013
Tweet

More Decks by Christopher Meiklejohn

Other Decks in Programming

Transcript

  1. (X · Y) · Z = X · (Y ·

    Z) ACID 2.0: Associativity Sunday, October 13, 13
  2. b a c a, b a, c a, b, c

    Set; merge function: union. b, c Sunday, October 13, 13
  3. 3 5 7 5 7 7 Increaing natual; merge function:

    max. Sunday, October 13, 13
  4. [ [{1, a}], [] ] [ [{1, a}], [] ]

    Sunday, October 13, 13
  5. [ [{1, a}], [] ] [ [{1, a}], [] ]

    [ [{1, a}], [{1, a}] ] [ [{1, a}], [{1, a}] ] Sunday, October 13, 13
  6. [ [{1, a}], [] ] [ [{1, a}], [] ]

    [ [{1, a}], [{1, a}] ] [ [{1, a}], [{1, a}] ] [ [{1, a}, {2, a}], [{1, a}] ] Sunday, October 13, 13
  7. [ [{1, a}], [] ] [ [{1, a}], [] ]

    [ [{1, a}], [{1, a}] ] [ [{1, a}], [{1, a}] ] [ [{1, a}, {2, a}], [{1, a}] ] [ [{1, a}, {2, a}], [{1, a}] ] Sunday, October 13, 13
  8. [ [{1, a}], [] ] [ [{1, a}], [] ]

    Sunday, October 13, 13
  9. [ [{1, a}], [] ] [ [{1, a}], [] ]

    [ [{1, a}, {2, b}], [] ] Sunday, October 13, 13
  10. [ [{1, a}], [] ] [ [{1, a}], [] ]

    [ [{1, a}, {2, b}], [] ] [ [{1, a}], [{1, a}] ] Sunday, October 13, 13
  11. [ [{1, a}], [] ] [ [{1, a}], [] ]

    [ [{1, a}, {2, b}], [] ] [ [{1, a}], [{1, a}] ] [ [{1, a}, {2, b}], [{1, a}] ] Sunday, October 13, 13
  12. module ChatProtocol state do channel :connect, [:@addr, :client] => [:nick]

    channel :mcast end end examples/chat/chat_protocol.rb Sunday, October 13, 13
  13. class ChatServer include Bud include ChatProtocol state { table :nodelist

    } bloom do nodelist <= connect.map { |c| [c.client, c.nick] } mcast <~ (mcast * nodelist).pairs { |m,n| [n.key, m.val] } end end examples/chat/chat_server.rb Sunday, October 13, 13
  14. class ChatServer include Bud include ChatProtocol state do table :nodelist

    channel :disconnect end bloom do nodelist <= connect.map { |c| [c.client, c.nick] } mcast <~ (mcast * nodelist).pairs { |m,n| [n.key, m.val] } nodelist <- disconnect.map { |c| [c.client, c.nick] } end end examples/chat/chat_server.rb Sunday, October 13, 13
  15. bloom do mcast <~ stdio do |s| [@server, [ip_port, @nick,

    Time.new.strftime("%I:%M.%S"), s.line]] end stdio <~ mcast { |m| [pretty_print(m.val)] } end examples/chat/chat.rb Sunday, October 13, 13
  16. module BasicKVS include KVSProtocol state do table :kvstate, [:key] =>

    [:value] end bloom :mutate do kvstate <+ kvput {|s| [s.key, s.value]} kvstate <- (kvstate * kvput).lefts(:key => :key) end bloom :get do temp :getj <= (kvget * kvstate).pairs(:key => :key) kvget_response <= getj do |g, t| [g.reqid, t.key, t.value] end end bloom :delete do kvstate <- (kvstate * kvdel).lefts(:key => :key) end end kvs/kvs.rb Sunday, October 13, 13
  17. module ReplicatedKVS include KVSProtocol include MulticastProtocol include MembershipProtocol import BasicKVS

    => :kvs bloom :local_indir do kvs.kvdel <= kvdel kvs.kvget <= kvget kvget_response <= kvs.kvget_response end bloom :puts do # if I am the master, multicast store requests mcast_send <= kvput do |k| unless member.include? [k.client] [k.reqid, ["put", [@addy, k.key, k.reqid, k.value]]] end end kvs.kvput <= mcast_done do |m| if m.payload[0] == "put" m.payload[1] end end # if I am a replica, store the payload of the multicast kvs.kvput <= pipe_out do |d| if d.payload.fetch(1) != @addy and d.payload[0] == "put" d.payload[1] end end end bloom :dels do mcast_send <= kvdel do |k| unless member.include? [k.client] [k.reqid, ["del", [@addy, k.key, k.reqid]]] end end kvs.kvdel <= mcast_done do |m| if m.payload[0] == "del" m.payload[1] end end kvs.kvdel <= pipe_out do |d| if d.payload.fetch(1) != @addy and d.payload[0] == "del" d.payload[1] end end end end kvs/kvs.rb Sunday, October 13, 13