behavioral simulations in mapreduce

44
Behavioral Simulations in MapReduce Guozhang Wang , Marcos Vaz Salles, Benjamin Sowell, Xun Wang, Tuan Cao, Alan Demers, Johannes Gehrke, Walker White Cornell University 1

Upload: donoma

Post on 13-Jan-2016

35 views

Category:

Documents


3 download

DESCRIPTION

Behavioral Simulations in MapReduce. Guozhang Wang , Marcos Vaz Salles, Benjamin Sowell, Xun Wang, Tuan Cao, Alan Demers, Johannes Gehrke, Walker White Cornell University. What are Behavioral Simulations?. - PowerPoint PPT Presentation

TRANSCRIPT

Page 1: Behavioral Simulations in MapReduce

Behavioral Simulations in MapReduce

Guozhang Wang, Marcos Vaz Salles,

Benjamin Sowell, Xun Wang, Tuan Cao, Alan Demers,

Johannes Gehrke, Walker White

Cornell University

1

Page 2: Behavioral Simulations in MapReduce

What are Behavioral Simulations?

• Simulations of individuals that interact to create emerging behavior in complex systems

• Application Areas – Traffic networks– Ecology systems– Sociology systems– etc

2

Page 3: Behavioral Simulations in MapReduce

Why Behavioral Simulations?

• Traffic– Congestion cost $87.2 billion

in the U.S. in 2007– More people killed by air

pollution than accidents– Detailed models: micro-

simulators not scale to NYC!

• Ecology– Hard to scale to large fish

schools or locust swarms 3

Page 4: Behavioral Simulations in MapReduce

Challenges of Behavioral Simulations

• Easy to program not scalable– Examples: Swarm, Mason– Typically one thread per agent, lots of contention

• Scalable hard to program– Examples: TRANSIMS, DynaMIT (traffic), GPU

implementation of fish simulation (ecology)– Hard-coded models, compromise level of detail

4

Can we do better?

Page 5: Behavioral Simulations in MapReduce

Our Contribution

• A new simulation platform that combines:– Ease of programming

• Program simulations in State-Effect pattern• BRASIL: Scripting language for domain scientists

– Scalability• Execute simulations in the MapReduce model• BRACE: Special-purpose MapReduce engine

5

Page 6: Behavioral Simulations in MapReduce

Talk Outline

• Motivation

• Ease of Programming– Program Simulations in State-Effect Pattern– BRASIL

• Scalability– Execute Simulations in MapReduce Model– BRACE

• Experiments

• Ongoing Work and Conclusion6

Page 7: Behavioral Simulations in MapReduce

A Running Example: Fish Schools

• Adapted from Couzin et al., Nature 2005

7

α

ρ

• Fish Behavior– Avoidance: if too

close, repel other fish– Attraction: if seen

within range, attract other fish

Page 8: Behavioral Simulations in MapReduce

A Running Example: Fish Schools

• Concurrency: agents are concurrent within a tick

• Interactions: agents continually interact

• Spatial Locality: agents have limited visibility

8

• Time-stepping: agents proceed in ticks

α

ρ

Page 9: Behavioral Simulations in MapReduce

Classic Solutions for Concurrency

9

• Preempt conflicts locking

• Rollback in case of conflicts optimistic concurrency control

• Problems:– Strong interactions many conflicts

• Either lots of lock contentions• Or lots of rollbacks

– Does not scale well

Page 10: Behavioral Simulations in MapReduce

State-Effect Pattern

• Programming pattern to deal with concurrency

• Follows time-stepped model

• Core Idea: Make all actions inside of a tick order-independent

10

Page 11: Behavioral Simulations in MapReduce

States and Effects

• States: – Snapshot of agents at the beginning of the tick

• position, velocity vector

11

• Effects:– Intermediate results

from interaction, used to calculate new states

• set of forces from other fish

α

ρ

Page 12: Behavioral Simulations in MapReduce

Two Phases of a Tick

• Query: capture agent interaction– Read states write effects– Each effect set is associated with

combinator function– Effect writes are order-independent

• Update: refresh world for next tick– Read effects write states– Reads and writes are totally local– State writes are order-independent

Tick

Update

Query

12

Page 13: Behavioral Simulations in MapReduce

Fish in State-Effect

• Query– For fish f in visibility α:

• Write repulsion to f’s effects– For fish f in visibility ρ:

• Write attraction to f’s effects

• Update– new velocity = combined

repulsion + combined attraction + old velocity

– new position = old position + old velocity 13

α

ρ

α

ρ

Page 14: Behavioral Simulations in MapReduce

Fish in State-Effect

• Query– For fish f in visibility α:

• Write repulsion to f’s effects– For fish f in visibility ρ:

• Write attraction to f’s effects

• Update– new velocity = combined

repulsion + combined attraction + old velocity

– new position = old position + old velocity 14

Page 15: Behavioral Simulations in MapReduce

BRASIL (Big Red Agent SImulation Language)

15

• High-level language for domain scientists

• Object-oriented style

• Programs specify behavior logic of individual agents

Page 16: Behavioral Simulations in MapReduce

Fish Program in BRASILclass Fish { // The fish location & vel (x) public state float x : (x+vx); #range[-1,1]; public state float vx : vx + rand() + avoidx / count * vx; // Used to update our velocity (x) private effect float avoidx : sum; private effect int count : sum; ... /** The query-phase for this fish. */ public void run() { // Use "forces" to repel fish too close foreach(Fish p : Extent<Fish>) { p.avoidx <- 1 / x - p.x; ... p.count <- 1; } }}

Update ruleVisibility

Effect combinator

Effect assignment

16

Page 17: Behavioral Simulations in MapReduce

Features of BRASIL

17

• Syntax enforces state-effect pattern

• Visibility declarations to express spatial locality

• Translates to Monad Algebra

• Can reuse classic DB optimization techniques– Details of translation in the paper

P = <1:𝛱1 𝛰 𝛱p,2:𝛱2> 𝛰 PAIRWITH2 𝛰 𝜎 𝛱1= 𝛱2 𝛰 𝛱key 𝛰 GET 𝛰 𝛱x

E1 = <1:𝛱1 𝛰 𝛱p,2:𝜌(avoidx),3:1 / (𝛱1 𝛰 𝛱x – P)>E2 = <1:𝛱1 𝛰 𝛱p,2:𝜌(count),3:1>B = <1:𝛱1,2:𝛱2,3:𝛱2 ⊕ (E1 𝛰 SNG) ⊕ (E2 𝛰 SNG)>F = <1:𝛱1,2:𝛱2,3:<1:𝛱1 𝛰 𝑥p(𝛱2) 𝛰 PAIRWITHp, 2:𝛱2, 3:𝛱3> 𝛰 FLATMAP(B 𝛰 𝛱3)>

public void run() { // Use "forces" to repel fish too close foreach(Fish p : Extent<Fish>) { p.avoidx <- 1 / x - p.x; ... p.count <- 1; } }

Page 18: Behavioral Simulations in MapReduce

Talk Outline

18

• Motivation

• Ease of Programming– Program Simulations in State-Effect Pattern– BRASIL

• Scalability– Execute Simulations in MapReduce Model– BRACE

• Experiments

• Ongoing Work and Conclusion

Page 19: Behavioral Simulations in MapReduce

How to Scale to Millions of Fish?

19

• Use multiple nodes in a cluster of machines for large simulation scenarios

• Need to efficiently parallelize computations of state-effect pattern

• Core Idea: execute in MapReduce– Agent partitioning with replications

Page 20: Behavioral Simulations in MapReduce

State-Effect Revisited

20

• Communicate new states before next tick’s query phase

Tick

CommunicateNew State

Communicate Effects

Updateeffects new state

Querystate effects

Page 21: Behavioral Simulations in MapReduce

State-Effect Revisited

21

• Communicate new states before next tick’s query phase

• Communicate effect assignments before update phase

Tick

CommunicateNew State

Communicate Effects

Updateeffects new state

Querystate effects

Page 22: Behavioral Simulations in MapReduce

From State-Effect to Map-Reduce

Map1 t

Reduce1 t

Map2 t

Reduce2 t

Map1 t+1

Assigneffects (partial)

Forward data

Aggregate effects

Update Redistribute data

…Distribute data

22

Tick

CommunicateNew State

Communicate Effects

Updateeffects new state

Querystate effects

Page 23: Behavioral Simulations in MapReduce

BRACE (Big Red Agent Computation Engine)

23

• Special-purpose MapReduce engine for behavioral simulations

• Basic Optimizations– Keep data in main memory– Collocate tasks

• Optimizations based on Spatial Properties:– Local synchronization– Effect inversion

Page 24: Behavioral Simulations in MapReduce

Spatial Partitioning

• Partition simulation space into regions, each handled by a separate node

24

Page 25: Behavioral Simulations in MapReduce

Communication Between Partitions

• Owned Region: agents in it are owned by the node

25Owned

Page 26: Behavioral Simulations in MapReduce

Communication Between Partitions

• Visible Region: agents in it are not owned, but need to be seen by the node

26Owned Visible

State CommunicationQueryEffect communicationUpdate

Page 27: Behavioral Simulations in MapReduce

Communication Between Partitions

• Visible Region: agents in it are not owned, but need to be seen by the node

27Owned Visible

• Only need to com-municate with neighbors to– refresh states– forward assigned

effects

Page 28: Behavioral Simulations in MapReduce

Effect Inversion

• In case of local effects only, can save one round of communication in each tick

Map1 t

Reduce1 t

Do not have non-local effects

28

…Distribute data

Assigneffects (partial)Assign and Aggregate effects

Map2 t

Reduce2 t

Forward data

Aggregate effects

Page 29: Behavioral Simulations in MapReduce

Effect Inversion Is Always Possible

• Theorem: Every behavioral simulation written in BRASIL that uses non-local effects can be rewritten to an equivalent simulation that uses local effects only– Proof in the paper

29

Page 30: Behavioral Simulations in MapReduce

Intuition of Effect Inversion Theorem

Non-localEffect Writes

Non-localState Reads

α 2α

LocalEffect Writes

+

30

Page 31: Behavioral Simulations in MapReduce

Talk Outline

31

• Motivation

• Ease of Programming– Program Simulations in Time-stepped Pattern– BRASIL

• Scalability– Execute Simulations in Dataflow Model– BRACE

• Experiments

• Ongoing Work and Conclusion

Page 32: Behavioral Simulations in MapReduce

Experimental Setup

• BRACE prototype– Grid partitioning– KD-Tree spatial indexing, rebuild every tick– Basic load balancing– No checkpointing

• Hardware: Cornell WebLab Cluster (60 nodes, 2xQuadCore Xeon 2.66GHz, 4MB cache, 16GB RAM)

32

Page 33: Behavioral Simulations in MapReduce

Implemented Simulations

• Traffic Simulation– Best-effort reimplementation of MITSIM lane

changing and car following– Large segment of highway

• Bacteria Simulation– Simple artificial society simulation

• Fish School Simulation– Model of collective animal motion by Couzin et al.,

Nature, 200533

Page 34: Behavioral Simulations in MapReduce

Scalability

• Nearly linear scalability for traffic simulation; notch consequence of Web Lab’s IP routing architecture

34

Page 35: Behavioral Simulations in MapReduce

Optimization

• 16-node with indexing and effect inversion• 10,000 epochs of bacteria simulation

35

Page 36: Behavioral Simulations in MapReduce

Single-Node Performance

• Single-node traffic scale-up with indexing• Scale-up with indexing similar, but MITSIM has more

efficient hard-coded indexing scheme

Page 37: Behavioral Simulations in MapReduce

Dynamic Agent Partitioning

• 16-node with load balancing turned on• Fish simulation of two independent schools that swim

in opposite directions37

Page 38: Behavioral Simulations in MapReduce

38

• Scientists want to run their simulations in the cloud

• Can we use the cloud?– Large and variable latency latency compensation

techniques– Large number of unreliable nodes low-overhead

checkpoints

Ongoing WorkBringing Simulations to the Cloud

Page 39: Behavioral Simulations in MapReduce

Conclusions

• Behavioral Simulations can have huge impact, but need to be run at large-scale

• New programming platform for behavioral simulations – Easy to program: Simulations in the state-effect

pattern BRASIL– Scalable: State-effect pattern in special-purpose

MapReduce Engine BRACE

• We are moving to simulate NYC !

Thank you!

39

Page 40: Behavioral Simulations in MapReduce

Backup Slides

40

Page 41: Behavioral Simulations in MapReduce

MITSIM: Single-Node Traffic Simulator

Stockholm, Norway41

Page 42: Behavioral Simulations in MapReduce

42

BRACE Architecture

• Do not load balance and check-point every tick, but only at epoch boundaries

Page 43: Behavioral Simulations in MapReduce

Time-stepped Behavior:Sense-Think-Act Cycle

Read-Write Conflict

while(tick < end) {

float rx = leadCar.pos – this.pos;

float rv = leadCar.spd – this.spd;

bool gethorn = this.heardHorn;

if(gethorn) {

dv = emergence_yield();

} else if(dx > high_x) {

dv = free_acc(rx, rv);

} else if (dx > low_x) {

dv = car_follow(rx, rv);

} else {

dv = emergence_brake(rx);

honk = get_angry(rx, rv);

}

this.spd = this.spd + dv;

this.pos = this.pos + this.spd;

leadCar.heardHorn = honk;

}

Tick

Think

Sense

Act

Page 44: Behavioral Simulations in MapReduce

Time-stepped Behavior:Sense-Think-Act Cycle

Write-Write Conflict

while(tick < end) {

float rx = leadCar.pos – this.pos;

float rv = leadCar.spd – this.spd;

bool gethorn = this.heardHorn;

if(gethorn) {

dv = emergence_yield();

} else if(dx > high_x) {

dv = free_acc(rx, rv);

} else if (dx > low_x) {

dv = car_follow(rx, rv);

} else {

dv = emergence_brake(rx);

honk = get_angry(rx, rv);

}

this.spd = this.spd + dv;

this.pos = this.pos + this.spd;

leadCar.heardHorn = honk;

}

Tick

Think

Sense

Act