380 likes | 483 Views
The Regiment Macroprogramming System. Ryan Newton (MIT) Greg Morrisett, Matt Welsh (Harvard). Sensor Network Programming. ... is hard low level resource management, debugging embedded devices Macroprogramming - one proposed solution Program at the global level
E N D
The Regiment Macroprogramming System • Ryan Newton (MIT) • Greg Morrisett, Matt Welsh (Harvard)
Sensor Network Programming • ... is hard • low level resource management, debugging embedded devices • Macroprogramming - one proposed solution • Program at the global level • Implicitly distribute program onto network • Compiler/runtime maps global to local
Why Regiment? • Some Macroprogramming approaches: • TinyDB: send SQL query to the network • Kairos: focused on synchronizing shared state • And many others... + middleware layers (Hoods, Abstract Regions) • When to use Regiment? • Long-running stream-processing computations • Significant spatial component to processing (regions) • Need efficient compiled node-program
Regiment: spatio-temporal macroprogramming • Stream-processing dataflow language • Streams of sensor data • Regions group streams, capture subsets of interest • Filter regions, map functions over them,fold (reduce) to produce results • Compiler: convert source to custom intermediate language [IPSN ‘05] • This paper: app case study + evaluation • Collaborative sensing: detect chemical plumes
Outline • Regiment Language • Regiment Compiler • Application Case Study
S sfilter(p, smap(f, S)) For this talk: assume epochs. Basic Datatypes • Nodes are modeled as streams of tuples • Streams can be processed by user functions or filtered with user predicates • Regions are bundles of streams • Accessible only through region operators
R’= rmap(f, R) Outputs a region! Basic Operators • rmap: apply a function to all data elements of all streams in a region region R R’= rmap(f, R)
Basic Operators • rmap: apply a function to all data elements of all streams in a region • rfilter: reduce membership in a region by applying a predicate region R R’= rmap(f, R) R’’= rfilter(p, R’)
Basic Operators • rmap: apply a function to all data elements of all streams in a region • rfilter: reduce membership in a region by applying a predicate • rfold: aggregate a region into a single stream using associative, commutative function region R R’= rmap(f, R) R’’= rfilter(p, R’) rfold(avg, (0,0), R’’)
Region Formation • world: a special region containing all nodes in the network • rmap/rfilter output new region values (but don’t construct regions) • neighborhood formation primitives • find the nodes near a given node • by hops, distance, etc • For example khood(k-hop-neighborhood) ‘world’ khood(1,N1)
Composable Operators! • Regiment’s operators produce and consume regions • Can construct nested regions (region of regions) • Enables collaborative sensing • Together with user-defined functions this makes the language expressive world rmap( khood(1), world)
Example Query: Average temperature More involved thanSELECT AVG(TEMP) but much more general... fun dosum(temp, (sumtemp, count)) { (sumtemp+temp, count+1) } tempreg = rmap( sense("temp"), world); sumstrm = rfold( dosum, (0,0), tempreg); avgstrm = smap( (/), sumstrm); BASE ← avgstrm User-Defined Functions are integrated Can map/filter/fold an arbitrary number of times, use nested regions, etc.
Different communication strategies Local Filtering Collaborative Filtering • Regiment is high level • these programs are simple and short • but not TOO high level • still expressive enough to take control of the comm strategy! Collaborative w/Gossip Gossip w/ suppression
Second Variant: Collaborative Filtering fun localthresh(nd) { sense("concentration", nd) > CHEM_THRESHOLD } detects = rfilter(localthresh, world); hoods = rmap( fun(nd){ khood(1,nd) }, detects); fun sum(r) {rfold((+), 0, r)} sums = rmap(sum, hoods); BASE ← rfilter( fun(cnt){cnt > CLUSTER_THRESH}, sums)
Aggregates data from neighbors into tableindexed by node id Third Variant: Gossip fun sum(tbl) { fold( fun((id,t), acc) {t + acc}, 0, r) } detects = rfilter(abovethresh, rmap(read,world)); tables = table_gossip(detects); sums = rmap(sum, tables); BASE ← rfilter(fun(t) {t>CLUSTER THRESH}, sums)
How much understanding of the underlying compiler and runtime system do you think is needed to develop an efficient application in Regiment? Discussion ?
Outline • Regiment Language • Regiment Compiler • Application Case Study
Strawman Proposal • What would a “direct” implementation look like? • How do you implement a variable that stores a region? • Or a function that takes and returns regions? • A region would be manifest as a table of nodes/data • A central base station would manage region tables • Runtime messages would task & query regions • Extremely inefficient! • Requires constant communication with base station during steady state operation Instead we generate a distributed, node-level program
The Regiment Compiler • Regiment Source • Region dataflow • Node dataflow • Token machine [IPSN ‘05] • Token encapsulates state and handler method • Event driven • Atomic, asynchronous event handlers rmap(project, rfilter(abovethresh, world) No heavyweight query-engine or runtime required
Architecture • Regiment Compiler: • Simplify source • Partial evaluate to produce aRegion Dataflow normal form • Convert to Node Dataflow(Switch POV) • Convert to Token Machine • General-purpose Spanning tree implementation used to implement regions • Also in the paper:Compiling programs with nested regions
Compiling Regiment Programs • Regiment walks a thin line • We can’t implement (at runtime): • region values stored in data structures • if x then R1 else R2 • Thus: partial evaluate at compile-time • ‘x’ above must evaluate at compile time • Essentially: write script to generate fixed Region dataflow • (But still with nested regions, much generality)
Outline • Regiment Language • Regiment Compiler • Application Case Study
Application: chemical plume detection • Event (chemical plume) starts at a point • Spreads outward uniformly • Nodes sense event proportional to distance from edge of affected area • Data-fusion from multiple nodes allows extraction of signal from noise (Image from Glenn Nofsinger)
RED LED: Reading exceeds local threshold Expanding Circle:Chemical Plume GREEN LED: node within plume
Different communication strategies Local Filtering Collaborative Filtering Collab w/ gossip & suppression Collaborative w/Gossip
Expressiveness:Make the easy program easy and the hard possible Simulation: 250 nodes avg degree ~7.2 network diameter ~13 ETX-based trees Simple probabalistic connectivity model Communication savings through program refinement • Local chem threshold 12ppmnoise stddev 4ppm
Current and Future Work • Regiment 2.0 == WaveScript • Added signal processing libraries • Using for several applications currently • acoustic localization, pipeline leak detection • C++ backend, runs on ARM class or better • We hope to replace our incomplete NesC backend with a better solution using a third party virtual machine • Looking for users! Download at http://regiment.us
Conclusion • Regiment converts global program to node behaviors • Carefully designed operator set + partial evaluation rules • Partial evaluation strategy enables abstraction, reusability in the source, w/out loss of efficiency in the generated code • Productivity tool • Allows rapid prototyping of applications • Tool support for debugging (simulator)
Unraveling Nested Regions • For nested regions • Trace new data flow • Splice operators in • Generate node dataflow • Hooks into spanning tree service
First Variant: Local Filtering fun abovethresh((chem,id)) { chem > THRESHOLD } fun projectfields(node) { (sense("concentration", node), nodeid(node)) } BASE ← rfilter(abovethresh, rmap(projectfields, world)) Now we rapidly prototype several solution variants
Operating systems (TinyOS) Resource (device) management Basic primitives Protocols (MAC, routing) {covered in many previous lectures} Programming languages and runtime environments Low level (C, nesC) Very high level abstractions (Regiment) Services needed Synchronization of clocks (RBS) Propagation of new code to all nodes (Trickle) Localization {not today} Software Development Infrastructure for Sensor Networks