Download - Bloom : Big Systems, Small Programs
![Page 1: Bloom : Big Systems, Small Programs](https://reader031.vdocuments.net/reader031/viewer/2022013004/56816254550346895dd29e42/html5/thumbnails/1.jpg)
Bloom:Big Systems, Small ProgramsNeil ConwayUC Berkeley
![Page 2: Bloom : Big Systems, Small Programs](https://reader031.vdocuments.net/reader031/viewer/2022013004/56816254550346895dd29e42/html5/thumbnails/2.jpg)
Distributed Computing
![Page 3: Bloom : Big Systems, Small Programs](https://reader031.vdocuments.net/reader031/viewer/2022013004/56816254550346895dd29e42/html5/thumbnails/3.jpg)
Programming Languages
![Page 4: Bloom : Big Systems, Small Programs](https://reader031.vdocuments.net/reader031/viewer/2022013004/56816254550346895dd29e42/html5/thumbnails/4.jpg)
Optimization
Loop unrollingRegister allocation
Data prefetching
Function inlining
Global coordination, waitingCaching, indexing
Replication, data localityPartitioning, load balancing
![Page 5: Bloom : Big Systems, Small Programs](https://reader031.vdocuments.net/reader031/viewer/2022013004/56816254550346895dd29e42/html5/thumbnails/5.jpg)
Warnings
Undeclared variables
Type mismatches
Sign conversion mistakes
Replica divergenceInconsistent state
DeadlocksRace conditions
![Page 6: Bloom : Big Systems, Small Programs](https://reader031.vdocuments.net/reader031/viewer/2022013004/56816254550346895dd29e42/html5/thumbnails/6.jpg)
Debugging
Stack traces
Log files, printf
gdb
Full stack visualization, analytics
Consistent global snapshots
Provenance analysis
![Page 7: Bloom : Big Systems, Small Programs](https://reader031.vdocuments.net/reader031/viewer/2022013004/56816254550346895dd29e42/html5/thumbnails/7.jpg)
Developer productivity is amajor unsolved problemin distributed computing.
![Page 8: Bloom : Big Systems, Small Programs](https://reader031.vdocuments.net/reader031/viewer/2022013004/56816254550346895dd29e42/html5/thumbnails/8.jpg)
We can do better!
… provided we’re willing to make changes.
![Page 9: Bloom : Big Systems, Small Programs](https://reader031.vdocuments.net/reader031/viewer/2022013004/56816254550346895dd29e42/html5/thumbnails/9.jpg)
Design Principles
![Page 10: Bloom : Big Systems, Small Programs](https://reader031.vdocuments.net/reader031/viewer/2022013004/56816254550346895dd29e42/html5/thumbnails/10.jpg)
![Page 11: Bloom : Big Systems, Small Programs](https://reader031.vdocuments.net/reader031/viewer/2022013004/56816254550346895dd29e42/html5/thumbnails/11.jpg)
Centralized Computing
• Predictable latency• No partial failure• Single clock• Global event
order
![Page 12: Bloom : Big Systems, Small Programs](https://reader031.vdocuments.net/reader031/viewer/2022013004/56816254550346895dd29e42/html5/thumbnails/12.jpg)
Taking Order For Granted
Data (Ordered)array of bytes
Compute
(Ordered) sequence of instructions
Global eventorder
![Page 13: Bloom : Big Systems, Small Programs](https://reader031.vdocuments.net/reader031/viewer/2022013004/56816254550346895dd29e42/html5/thumbnails/13.jpg)
Distributed Computing
• Unpredictable latency
• Partial failures• No global event
order
![Page 14: Bloom : Big Systems, Small Programs](https://reader031.vdocuments.net/reader031/viewer/2022013004/56816254550346895dd29e42/html5/thumbnails/14.jpg)
Alternative #1:Enforce global event order at all nodes(“Strong Consistency”)
![Page 15: Bloom : Big Systems, Small Programs](https://reader031.vdocuments.net/reader031/viewer/2022013004/56816254550346895dd29e42/html5/thumbnails/15.jpg)
Alternative #1:Enforce global event order at all nodes(“Strong Consistency”)
Problems:• Availability (CAP)• Latency
![Page 16: Bloom : Big Systems, Small Programs](https://reader031.vdocuments.net/reader031/viewer/2022013004/56816254550346895dd29e42/html5/thumbnails/16.jpg)
Alternative #2:Ensure correct behaviorfor any network order(“Weak Consistency”)
![Page 17: Bloom : Big Systems, Small Programs](https://reader031.vdocuments.net/reader031/viewer/2022013004/56816254550346895dd29e42/html5/thumbnails/17.jpg)
Alternative #2:Ensure correct behaviorfor any network order(“Weak Consistency”)
Problem:With traditional languages, this is very difficult.
![Page 18: Bloom : Big Systems, Small Programs](https://reader031.vdocuments.net/reader031/viewer/2022013004/56816254550346895dd29e42/html5/thumbnails/18.jpg)
The “ACID 2.0” PatternAssociativity:
X ○ (Y ○ Z) = (X ○ Y) ○ Z“batch tolerance”
Commutativity:X ○ Y = Y ○ X
“reordering tolerance”
Idempotence:X ○ X = X
“retry tolerance”
![Page 19: Bloom : Big Systems, Small Programs](https://reader031.vdocuments.net/reader031/viewer/2022013004/56816254550346895dd29e42/html5/thumbnails/19.jpg)
“When I see patterns in my programs, I consider it a sign of trouble … [they are a sign] that I'm using abstractions that aren't powerful enough.”
—Paul Graham
![Page 20: Bloom : Big Systems, Small Programs](https://reader031.vdocuments.net/reader031/viewer/2022013004/56816254550346895dd29e42/html5/thumbnails/20.jpg)
Bounded Join Semilattices
A triple hS,t,?i such that:– S is a set– t is a binary operator
(“least upper bound”)• Induces a partial order on
S: x ·S y if x t y = y• Associative, Commutative,
and Idempotent– 8x 2 S: ? t x = x
![Page 21: Bloom : Big Systems, Small Programs](https://reader031.vdocuments.net/reader031/viewer/2022013004/56816254550346895dd29e42/html5/thumbnails/21.jpg)
Bounded Join Semilattices
Lattices are objects that grow over time.
An interface with anACID 2.0 merge() method– Associative– Commutative– Idempotent
![Page 22: Bloom : Big Systems, Small Programs](https://reader031.vdocuments.net/reader031/viewer/2022013004/56816254550346895dd29e42/html5/thumbnails/22.jpg)
Time
Set(Merge = Union)
Increasing Int(Merge = Max)
Boolean(Merge = Or)
![Page 23: Bloom : Big Systems, Small Programs](https://reader031.vdocuments.net/reader031/viewer/2022013004/56816254550346895dd29e42/html5/thumbnails/23.jpg)
CRDTs: Convergent Replicated Data Types–e.g., registers,
counters, sets, graphs, trees
Implementations:–Statebox–Knockbox– riak_dt
![Page 24: Bloom : Big Systems, Small Programs](https://reader031.vdocuments.net/reader031/viewer/2022013004/56816254550346895dd29e42/html5/thumbnails/24.jpg)
Lattices representdisorderly data.
How can we represent disorderly computation?
![Page 25: Bloom : Big Systems, Small Programs](https://reader031.vdocuments.net/reader031/viewer/2022013004/56816254550346895dd29e42/html5/thumbnails/25.jpg)
f : ST is a monotone function iff:8a,b 2 S : a ·S b ) f(a) ·T f(b)
![Page 26: Bloom : Big Systems, Small Programs](https://reader031.vdocuments.net/reader031/viewer/2022013004/56816254550346895dd29e42/html5/thumbnails/26.jpg)
Time
Set(Merge = Union)
Increasing Int(Merge = Max)
Boolean(Merge = Or)
size() >= 3
Monotone function:set increase-int
Monotone function:increase-int boolean
![Page 27: Bloom : Big Systems, Small Programs](https://reader031.vdocuments.net/reader031/viewer/2022013004/56816254550346895dd29e42/html5/thumbnails/27.jpg)
ConsistencyAsLogicalMonotonicity
![Page 28: Bloom : Big Systems, Small Programs](https://reader031.vdocuments.net/reader031/viewer/2022013004/56816254550346895dd29e42/html5/thumbnails/28.jpg)
![Page 29: Bloom : Big Systems, Small Programs](https://reader031.vdocuments.net/reader031/viewer/2022013004/56816254550346895dd29e42/html5/thumbnails/29.jpg)
![Page 30: Bloom : Big Systems, Small Programs](https://reader031.vdocuments.net/reader031/viewer/2022013004/56816254550346895dd29e42/html5/thumbnails/30.jpg)
![Page 31: Bloom : Big Systems, Small Programs](https://reader031.vdocuments.net/reader031/viewer/2022013004/56816254550346895dd29e42/html5/thumbnails/31.jpg)
Case Study
![Page 32: Bloom : Big Systems, Small Programs](https://reader031.vdocuments.net/reader031/viewer/2022013004/56816254550346895dd29e42/html5/thumbnails/32.jpg)
![Page 33: Bloom : Big Systems, Small Programs](https://reader031.vdocuments.net/reader031/viewer/2022013004/56816254550346895dd29e42/html5/thumbnails/33.jpg)
![Page 34: Bloom : Big Systems, Small Programs](https://reader031.vdocuments.net/reader031/viewer/2022013004/56816254550346895dd29e42/html5/thumbnails/34.jpg)
![Page 35: Bloom : Big Systems, Small Programs](https://reader031.vdocuments.net/reader031/viewer/2022013004/56816254550346895dd29e42/html5/thumbnails/35.jpg)
![Page 36: Bloom : Big Systems, Small Programs](https://reader031.vdocuments.net/reader031/viewer/2022013004/56816254550346895dd29e42/html5/thumbnails/36.jpg)
![Page 37: Bloom : Big Systems, Small Programs](https://reader031.vdocuments.net/reader031/viewer/2022013004/56816254550346895dd29e42/html5/thumbnails/37.jpg)
Questions1. Will cart replicas eventually
converge?– “Eventual Consistency”
2. What will client observe on checkout?– Goal: checkout reflects all session
activity
3. To achieve #1 and #2, how much ordering is required?
![Page 38: Bloom : Big Systems, Small Programs](https://reader031.vdocuments.net/reader031/viewer/2022013004/56816254550346895dd29e42/html5/thumbnails/38.jpg)
if kvs[x] exists: old = kvs[x] kvs.delete(x) if old > c kvs[x] = old – c
if kvs[x] exists: old = kvs[x] kvs.delete(x)else old = 0kvs[x] = old + c
Design #1: Mutable StateAdd(item x, count c):
Remove(item x, count c):
Non-monotonic!
![Page 39: Bloom : Big Systems, Small Programs](https://reader031.vdocuments.net/reader031/viewer/2022013004/56816254550346895dd29e42/html5/thumbnails/39.jpg)
Conclusion:Every operation mightrequire coordination!
Non-monotonic!
![Page 40: Bloom : Big Systems, Small Programs](https://reader031.vdocuments.net/reader031/viewer/2022013004/56816254550346895dd29e42/html5/thumbnails/40.jpg)
Design #2: “Disorderly”Add(item x, count c):Add x,c to add_log
Remove(item x, count c):
Add x,c to del_log
Checkout():Group add_log byitem ID; sum counts.
Group del_log byitem ID; sum counts.
For each item, subtract deletes from adds.Non-monotonic!
![Page 41: Bloom : Big Systems, Small Programs](https://reader031.vdocuments.net/reader031/viewer/2022013004/56816254550346895dd29e42/html5/thumbnails/41.jpg)
Conclusion:Replication is safe;might need tocoordinate on checkout
Monotonic
![Page 42: Bloom : Big Systems, Small Programs](https://reader031.vdocuments.net/reader031/viewer/2022013004/56816254550346895dd29e42/html5/thumbnails/42.jpg)
Takeaways• Avoid: mutable state update
Prefer: immutable data, monotone growth
• Major difference in coordination cost!– Coordinate once per operation vs.
Coordinate once per checkout
• We’d like a type system for monotonicity
![Page 43: Bloom : Big Systems, Small Programs](https://reader031.vdocuments.net/reader031/viewer/2022013004/56816254550346895dd29e42/html5/thumbnails/43.jpg)
Language Design
![Page 44: Bloom : Big Systems, Small Programs](https://reader031.vdocuments.net/reader031/viewer/2022013004/56816254550346895dd29e42/html5/thumbnails/44.jpg)
Disorderly Programming• Order-independent:
default• Order dependencies:
explicit• Order as part of the
design process• Tool support–Where is order
needed? Why?
![Page 45: Bloom : Big Systems, Small Programs](https://reader031.vdocuments.net/reader031/viewer/2022013004/56816254550346895dd29e42/html5/thumbnails/45.jpg)
The Disorderly Spectrum
ASM
C
Java
Lisp, ML
Haskell
SQL, LINQ,Datalog
Bloom
High-level“Declarative”Powerful optimizers
![Page 46: Bloom : Big Systems, Small Programs](https://reader031.vdocuments.net/reader031/viewer/2022013004/56816254550346895dd29e42/html5/thumbnails/46.jpg)
Bloom ≈ declarative agents
Processes thatcommunicate viaasynchronousmessage passing
Each processhas a localdatabase
Logical rules describecomputation andcommunication (“SQL++”)
![Page 47: Bloom : Big Systems, Small Programs](https://reader031.vdocuments.net/reader031/viewer/2022013004/56816254550346895dd29e42/html5/thumbnails/47.jpg)
Each agent has a database of values that changes over time.
All values have a locationand timestamp.
![Page 48: Bloom : Big Systems, Small Programs](https://reader031.vdocuments.net/reader031/viewer/2022013004/56816254550346895dd29e42/html5/thumbnails/48.jpg)
left-hand-side <= right-hand-side
If RHS is true (SELECT …)
Then LHS is true(INTO lhs)
When and whereis the LHS true?
![Page 49: Bloom : Big Systems, Small Programs](https://reader031.vdocuments.net/reader031/viewer/2022013004/56816254550346895dd29e42/html5/thumbnails/49.jpg)
Temporal Operators
1. Same location,same timestamp
2. Same location,next timestamp
3. Different location,non-deterministic timestamp
<=
<+<-
<~
Computation
PersistenceDeletion
Communication
![Page 50: Bloom : Big Systems, Small Programs](https://reader031.vdocuments.net/reader031/viewer/2022013004/56816254550346895dd29e42/html5/thumbnails/50.jpg)
Observe Compute Act
![Page 51: Bloom : Big Systems, Small Programs](https://reader031.vdocuments.net/reader031/viewer/2022013004/56816254550346895dd29e42/html5/thumbnails/51.jpg)
Our First Program:PubSub
![Page 52: Bloom : Big Systems, Small Programs](https://reader031.vdocuments.net/reader031/viewer/2022013004/56816254550346895dd29e42/html5/thumbnails/52.jpg)
![Page 53: Bloom : Big Systems, Small Programs](https://reader031.vdocuments.net/reader031/viewer/2022013004/56816254550346895dd29e42/html5/thumbnails/53.jpg)
class Hub include Bud
state do channel :subscribe, [:@addr, :topic, :client] channel :pub, [:@addr, :topic, :val] channel :event, [:@addr, :topic, :val] table :sub, [:addr, :topic] end
bloom do sub <= subscribe {|s| [s.client, s.topic]} event <~ (pub * sub).pairs(:topic => :topic) {|p,s| [s.addr, p.topic, p.val] } endend
Ruby DSL
![Page 54: Bloom : Big Systems, Small Programs](https://reader031.vdocuments.net/reader031/viewer/2022013004/56816254550346895dd29e42/html5/thumbnails/54.jpg)
class Hub include Bud
state do channel :subscribe, [:@addr, :topic, :client] channel :pub, [:@addr, :topic, :val] channel :event, [:@addr, :topic, :val] table :sub, [:addr, :topic] end
bloom do sub <= subscribe {|s| [s.client, s.topic]} event <~ (pub * sub).pairs(:topic => :topic) {|p,s| [s.addr, p.topic, p.val] } endend
State declarations
![Page 55: Bloom : Big Systems, Small Programs](https://reader031.vdocuments.net/reader031/viewer/2022013004/56816254550346895dd29e42/html5/thumbnails/55.jpg)
class Hub include Bud
state do channel :subscribe, [:@addr, :topic, :client] channel :pub, [:@addr, :topic, :val] channel :event, [:@addr, :topic, :val] table :sub, [:addr, :topic] end
bloom do sub <= subscribe {|s| [s.client, s.topic]} event <~ (pub * sub).pairs(:topic => :topic) {|p,s| [s.addr, p.topic, p.val] } endend
Rules
![Page 56: Bloom : Big Systems, Small Programs](https://reader031.vdocuments.net/reader031/viewer/2022013004/56816254550346895dd29e42/html5/thumbnails/56.jpg)
class Hub include Bud
state do table :sub, [:client, :topic] channel :subscribe, [:@addr, :topic, :client] channel :pub, [:@addr, :topic, :val] channel :event, [:@addr, :topic, :val] end
bloom do sub <= subscribe {|s| [s.client, s.topic]} event <~ (pub * sub).pairs(:topic => :topic) {|p,s| [s.addr, p.topic, p.val] } endend
Persistent state: setof subscriptions
Schema
![Page 57: Bloom : Big Systems, Small Programs](https://reader031.vdocuments.net/reader031/viewer/2022013004/56816254550346895dd29e42/html5/thumbnails/57.jpg)
class Hub include Bud
state do table :sub, [:client, :topic] channel :subscribe, [:@addr, :topic, :client] channel :pub, [:@addr, :topic, :val] channel :event, [:@addr, :topic, :val] end
bloom do sub <= subscribe {|s| [s.client, s.topic]} event <~ (pub * sub).pairs(:topic => :topic) {|p,s| [s.addr, p.topic, p.val] } endend
Network input, output
Destination address
![Page 58: Bloom : Big Systems, Small Programs](https://reader031.vdocuments.net/reader031/viewer/2022013004/56816254550346895dd29e42/html5/thumbnails/58.jpg)
class Hub include Bud
state do table :sub, [:client, :topic] channel :subscribe, [:@addr, :topic, :client] channel :pub, [:@addr, :topic, :val] channel :event, [:@addr, :topic, :val] end
bloom do sub <= subscribe {|s| [s.client, s.topic]} event <~ (pub * sub).pairs(:topic => :topic) {|p,s| [s.client, p.topic, p.val] } endend
Remember subscriptions
![Page 59: Bloom : Big Systems, Small Programs](https://reader031.vdocuments.net/reader031/viewer/2022013004/56816254550346895dd29e42/html5/thumbnails/59.jpg)
class Hub include Bud
state do table :sub, [:client, :topic] channel :subscribe, [:@addr, :topic, :client] channel :pub, [:@addr, :topic, :val] channel :event, [:@addr, :topic, :val] end
bloom do sub <= subscribe {|s| [s.client, s.topic]} event <~ (pub * sub).pairs(:topic => :topic) {|p,s| [s.client, p.topic, p.val] } endend
Send events to subscribers
Join (as in SQL) Join key
![Page 60: Bloom : Big Systems, Small Programs](https://reader031.vdocuments.net/reader031/viewer/2022013004/56816254550346895dd29e42/html5/thumbnails/60.jpg)
PersistentState
EphemeralEvents
“Push-Based”
![Page 61: Bloom : Big Systems, Small Programs](https://reader031.vdocuments.net/reader031/viewer/2022013004/56816254550346895dd29e42/html5/thumbnails/61.jpg)
EphemeralEvents
PersistentState
“Pull-Based”
![Page 62: Bloom : Big Systems, Small Programs](https://reader031.vdocuments.net/reader031/viewer/2022013004/56816254550346895dd29e42/html5/thumbnails/62.jpg)
class Hub include Bud
state do table :sub, [:client, :topic] channel :subscribe, [:@addr, :topic, :client] channel :pub, [:@addr, :topic, :val] channel :event, [:@addr, :topic, :val] end
bloom do sub <= subscribe {|s| [s.client, s.topic]} event <~ (pub * sub).pairs(:topic => :topic) {|p,s| [s.client, p.topic, p.val] } endend
![Page 63: Bloom : Big Systems, Small Programs](https://reader031.vdocuments.net/reader031/viewer/2022013004/56816254550346895dd29e42/html5/thumbnails/63.jpg)
class HubPull include Bud
state do table :pub, [:topic, :val] channel :publish, [:@addr, :topic, :val] channel :sub, [:@addr, :topic, :client] channel :event, [:@addr, :topic, :val] end
bloom do pub <= publish {|p| [p.topic, p.val]} event <~ (pub * sub).pairs(:topic => :topic) {|p,s| [s.client, p.topic, p.val] } endend
![Page 64: Bloom : Big Systems, Small Programs](https://reader031.vdocuments.net/reader031/viewer/2022013004/56816254550346895dd29e42/html5/thumbnails/64.jpg)
Suppose we keep only the most recent message for each topic (“last writer wins”).
Publish PutSubscribe GetEvent ReplyPub DBTopic Key
Rename:
![Page 65: Bloom : Big Systems, Small Programs](https://reader031.vdocuments.net/reader031/viewer/2022013004/56816254550346895dd29e42/html5/thumbnails/65.jpg)
class KvsHub include Bud
state do table :db, [:key, :val] channel :put, [:@addr, :key, :val] channel :get, [:@addr, :key, :client] channel :reply, [:@addr, :key, :val]end
bloom do db <+ put {|p| [p.key, p.val]} db <- (db * put).lefts(:key => :key) reply <~ (db * get).pairs(:key => :key) {|d,g| [g.client, d.key, d.val] } endend
Update = delete + insert
![Page 66: Bloom : Big Systems, Small Programs](https://reader031.vdocuments.net/reader031/viewer/2022013004/56816254550346895dd29e42/html5/thumbnails/66.jpg)
![Page 67: Bloom : Big Systems, Small Programs](https://reader031.vdocuments.net/reader031/viewer/2022013004/56816254550346895dd29e42/html5/thumbnails/67.jpg)
![Page 68: Bloom : Big Systems, Small Programs](https://reader031.vdocuments.net/reader031/viewer/2022013004/56816254550346895dd29e42/html5/thumbnails/68.jpg)
class KvsHub include Bud
state do table :db, [:key, :val] channel :put, [:@addr, :key, :val] channel :get, [:@addr, :key, :client] channel :reply, [:@addr, :key, :val]end
bloom do db <+ put {|p| [p.key, p.val]} db <- (db * put).lefts(:key => :key) reply <~ (db * get).pairs(:key => :key) {|d,g| [g.client, d.key, d.val] } endend
![Page 69: Bloom : Big Systems, Small Programs](https://reader031.vdocuments.net/reader031/viewer/2022013004/56816254550346895dd29e42/html5/thumbnails/69.jpg)
TakeawaysBloom:• Concise, high-level programs• State update, asynchrony, and non-
monotonicity are explicit in the syntax
Design Patterns:• Communication vs. Storage• Queries vs. Data• Push vs. Pull
Actuallynot sodifferent!
![Page 70: Bloom : Big Systems, Small Programs](https://reader031.vdocuments.net/reader031/viewer/2022013004/56816254550346895dd29e42/html5/thumbnails/70.jpg)
ConclusionTraditional languages are not a good fit for modern distributed computing
Principle: Disorderly programs for disorderly networks
Practice: Bloom– High-level, disorderly, declarative– Designed for distribution
![Page 71: Bloom : Big Systems, Small Programs](https://reader031.vdocuments.net/reader031/viewer/2022013004/56816254550346895dd29e42/html5/thumbnails/71.jpg)
Thank You!Twitter: @neil_conway
gem install budhttp://www.bloom-lang.net
Peter AlvaroEmily AndrewsPeter BailisDavid Maier
Bill MarczakJoe HellersteinSriram Srinivasan
Collaborators: