actors, a unifying pattern for scalable concurrency | c4 2006

42
actors a unifying design pattern for scalable concurrency www.iolanguage.com [email protected]

Upload: real-nobile

Post on 22-Apr-2015

7.541 views

Category:

Technology


1 download

DESCRIPTION

IoLanguage www.iolanguage.com

TRANSCRIPT

Page 2: Actors, a Unifying Pattern for Scalable Concurrency | C4 2006

talk overview

what is an actor?

concurrency trends

problems and solutions

the big picture

Page 3: Actors, a Unifying Pattern for Scalable Concurrency | C4 2006

what is an actor?an informal definition

an object with an asynchronous message queue and an execution context for

processing that queue

encapsulates state, instructions and execution

(a CSP is a process level actor)

Page 4: Actors, a Unifying Pattern for Scalable Concurrency | C4 2006

concurrency trendsa quick look

Page 5: Actors, a Unifying Pattern for Scalable Concurrency | C4 2006

clock speedleveling off

1990 1995 2000 2005 2010 2015

50 120800

2,000

4,000

5,000

?

?

Page 6: Actors, a Unifying Pattern for Scalable Concurrency | C4 2006

cores per machineincreasing exponentially

2002 2004 2006 2008 2011

2 4 8

24

80

?

?

Page 7: Actors, a Unifying Pattern for Scalable Concurrency | C4 2006

clustersmassive scaling

typical scale

memcached 10^2

gfs 10^4

mmog 10^3

p2p 10^5

@home 10^6

Page 8: Actors, a Unifying Pattern for Scalable Concurrency | C4 2006

trends are cores and clusters

ideal concurrency modelwill naturally scale across both

Page 9: Actors, a Unifying Pattern for Scalable Concurrency | C4 2006

traditional concurrency model

preemptive threads with shared memory and

coordination via locks

Page 10: Actors, a Unifying Pattern for Scalable Concurrency | C4 2006

problemnondeterminism

Page 11: Actors, a Unifying Pattern for Scalable Concurrency | C4 2006

For concurrent programming to become mainstream, we must discard threads as a

programming model.

Nondeterminism should be judiciously and carefully introduced where needed, and it

should be explicit in programs.

- Ed Lee, The Problem with ThreadsBerkeley CS Tech Report

Page 12: Actors, a Unifying Pattern for Scalable Concurrency | C4 2006

thread A

traditional concurrency modelthreads can directly change one another’s state

“spaghetti concurrency”

thread B

Page 13: Actors, a Unifying Pattern for Scalable Concurrency | C4 2006

actor/csp modelonly a thread can directly change it’s own state

thread A thread B

queue queue

same model works across machines

Page 14: Actors, a Unifying Pattern for Scalable Concurrency | C4 2006

a natural extension

actors are the object paradigm extended to execution

objects encapsulate state and instructions

actors encapsulate state, instructions and execution

Page 15: Actors, a Unifying Pattern for Scalable Concurrency | C4 2006

what this looks like in Ioany object becomes an actor when

sent an async message

account deposit(10.00) // sync message

account @deposit(10.00) // future message

account @@deposit(10.00) // async message

Io is a hybrid actor language

Page 16: Actors, a Unifying Pattern for Scalable Concurrency | C4 2006

problemasynchronous programming

Page 17: Actors, a Unifying Pattern for Scalable Concurrency | C4 2006

a future

an object returned from an async message which becomes the result when it is

available. If it is accessed before the result is ready, it blocks the calling execution

context.

Page 18: Actors, a Unifying Pattern for Scalable Concurrency | C4 2006

futures

sync programming with async messages by decoupling messages from return values

allows lazy synchronization and automatic deadlock detection

Page 19: Actors, a Unifying Pattern for Scalable Concurrency | C4 2006

another look

account deposit(10.00) // sync message

account @deposit(10.00) // future message

account @@deposit(10.00) // async message

Page 20: Actors, a Unifying Pattern for Scalable Concurrency | C4 2006

another example

// waits for resultdata := url fetch

// returns a future immediatelydata := url @fetch

data setFutureDelegate(self)

Page 21: Actors, a Unifying Pattern for Scalable Concurrency | C4 2006

the undiscovered countrylots of interesting concurrent coordinating patterns can be composed from futures or

other forms of async return messages

c := urls cursor c setConcurrency(500)c setDelegate(self)c foreach(fetch)

Page 22: Actors, a Unifying Pattern for Scalable Concurrency | C4 2006

problemdistributed programming

Page 23: Actors, a Unifying Pattern for Scalable Concurrency | C4 2006

transparent distributed objectsunified local and remote messaging

peers append(DO at(ip, port, key))...c := peers cursor c setConcurrency(50)c setDelegate(self)c foreach(search(query))

eliminates protocol hassles but doesn’t mean we can ignore the network, etc

Page 24: Actors, a Unifying Pattern for Scalable Concurrency | C4 2006

problemthe high concurrencymemory bottleneck

Page 25: Actors, a Unifying Pattern for Scalable Concurrency | C4 2006

bytes max per GB

process/os thread 1,000,000s 100s*

stackfull coro 10,000s 10,000s

stackless coro orcontinuation

100s 1,000,000s**

execution contextsmemory usage and maximum concurrency

*webkit etc use os threads..**but thread related state may exceed stack size

Page 26: Actors, a Unifying Pattern for Scalable Concurrency | C4 2006

synonyms

user level threadlightweight thread

microthread green thread

coroutinecorofiber

synonyms

os threadkernel threadnative thread

Page 27: Actors, a Unifying Pattern for Scalable Concurrency | C4 2006

taxonomy

os thread

coroutine

stackless coro

continuation

stackfull coro

execution context / thread

user level threadlarge fixed stack size

small fixed stack size variable stack size

linked activation records

nondeterministic hw registers swapping

deterministic hw registers swapping

Page 28: Actors, a Unifying Pattern for Scalable Concurrency | C4 2006

what this means in practice

connections

Page 29: Actors, a Unifying Pattern for Scalable Concurrency | C4 2006

user level threads aren’tpreemptive, so what about

blocking ops?

avoid them by using async sockets and

async file i/o

Page 30: Actors, a Unifying Pattern for Scalable Concurrency | C4 2006

ease of use?pause the user level thread while waiting on the async i/o request

cpu bound blocking?use explicit yield() where needed

async issues

Page 31: Actors, a Unifying Pattern for Scalable Concurrency | C4 2006

conclusion

use user level threads for scaling concurrency on a given core andone os threads or processes per

core for scaling across cores

Page 32: Actors, a Unifying Pattern for Scalable Concurrency | C4 2006

the big picture“powers of 10”

each level follows the actor pattern of encapsulating state, instructions and execution and

communicating via async queued messaging

Page 33: Actors, a Unifying Pattern for Scalable Concurrency | C4 2006

actoruser thread

cluster

cluster cluster cluster

cluster

clusterclustercluster

Page 34: Actors, a Unifying Pattern for Scalable Concurrency | C4 2006

cspos process

cluster

clustercluster cluster

cluster

clusterclustercluster

actor

actor

actor

actor

actor

actor

actor

actor

actor

actor

actor

actor

actor

actor

actor

actor

Page 35: Actors, a Unifying Pattern for Scalable Concurrency | C4 2006

machinecluster

cluster cluster cluster

cluster

clusterclustercluster

csp

csp

csp

csp

csp

csp

csp

csp

csp

csp

csp

csp

csp

csp

csp

csp

Page 36: Actors, a Unifying Pattern for Scalable Concurrency | C4 2006

clustercluster

cluster cluster cluster

cluster

clusterclustercluster

machine

machine

machine

machine

machine

machine

machine

machine

machine

machine

machine

machine

machine

machine

machine

machine

Page 37: Actors, a Unifying Pattern for Scalable Concurrency | C4 2006

some fun speculation

what about cores?a prediction based on this pattern

Page 38: Actors, a Unifying Pattern for Scalable Concurrency | C4 2006

traditional SISD architectureworks, but clock speed growth is slowing

and silicon is cheap

core

bus

memory

Page 39: Actors, a Unifying Pattern for Scalable Concurrency | C4 2006

current MISD architecturebus bottleneck - memory performance per core

drops as core count increases

core

bus

memory

core

Page 40: Actors, a Unifying Pattern for Scalable Concurrency | C4 2006

SISDSISD SISD

SISD SISD SISD SISD

SISD

SISD

SISD

SISD

SISD

SISD

future MIMD architecture?the actor pattern on the hardware level

a connection machine on a chip

SISD SISD SISD SISD

core

memorySISD

Page 41: Actors, a Unifying Pattern for Scalable Concurrency | C4 2006

automatic MIMD distribution

SISDarray shard

SISD SISD SISDarray shard array shard array shard

SISDarray

SISD SISD SISD

SISD SISD SISD SISD

SISD

SISD

SISD

SISD

SISD

SISD

Page 42: Actors, a Unifying Pattern for Scalable Concurrency | C4 2006

solution problem solution

concurrency nondeterminism actors/csp

actors/csp distributed and async programming

transparent distributed objects and futures

high concurrency memory bottleneck user level threads

many cores bus bottleneck MIMD

this talk, in a nutshell

www.iolanguage.com [email protected]