Actors, a Unifying Pattern for Scalable Concurrency | C4 2006
-
Upload
real-nobile -
Category
Technology
-
view
7.542 -
download
1
description
Transcript of Actors, a Unifying Pattern for Scalable Concurrency | C4 2006
![Page 2: Actors, a Unifying Pattern for Scalable Concurrency | C4 2006](https://reader034.fdocuments.us/reader034/viewer/2022051616/5538337c4a7959f66c8b46b2/html5/thumbnails/2.jpg)
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](https://reader034.fdocuments.us/reader034/viewer/2022051616/5538337c4a7959f66c8b46b2/html5/thumbnails/3.jpg)
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](https://reader034.fdocuments.us/reader034/viewer/2022051616/5538337c4a7959f66c8b46b2/html5/thumbnails/4.jpg)
concurrency trendsa quick look
![Page 5: Actors, a Unifying Pattern for Scalable Concurrency | C4 2006](https://reader034.fdocuments.us/reader034/viewer/2022051616/5538337c4a7959f66c8b46b2/html5/thumbnails/5.jpg)
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](https://reader034.fdocuments.us/reader034/viewer/2022051616/5538337c4a7959f66c8b46b2/html5/thumbnails/6.jpg)
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](https://reader034.fdocuments.us/reader034/viewer/2022051616/5538337c4a7959f66c8b46b2/html5/thumbnails/7.jpg)
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](https://reader034.fdocuments.us/reader034/viewer/2022051616/5538337c4a7959f66c8b46b2/html5/thumbnails/8.jpg)
trends are cores and clusters
ideal concurrency modelwill naturally scale across both
![Page 9: Actors, a Unifying Pattern for Scalable Concurrency | C4 2006](https://reader034.fdocuments.us/reader034/viewer/2022051616/5538337c4a7959f66c8b46b2/html5/thumbnails/9.jpg)
traditional concurrency model
preemptive threads with shared memory and
coordination via locks
![Page 10: Actors, a Unifying Pattern for Scalable Concurrency | C4 2006](https://reader034.fdocuments.us/reader034/viewer/2022051616/5538337c4a7959f66c8b46b2/html5/thumbnails/10.jpg)
problemnondeterminism
![Page 11: Actors, a Unifying Pattern for Scalable Concurrency | C4 2006](https://reader034.fdocuments.us/reader034/viewer/2022051616/5538337c4a7959f66c8b46b2/html5/thumbnails/11.jpg)
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](https://reader034.fdocuments.us/reader034/viewer/2022051616/5538337c4a7959f66c8b46b2/html5/thumbnails/12.jpg)
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](https://reader034.fdocuments.us/reader034/viewer/2022051616/5538337c4a7959f66c8b46b2/html5/thumbnails/13.jpg)
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](https://reader034.fdocuments.us/reader034/viewer/2022051616/5538337c4a7959f66c8b46b2/html5/thumbnails/14.jpg)
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](https://reader034.fdocuments.us/reader034/viewer/2022051616/5538337c4a7959f66c8b46b2/html5/thumbnails/15.jpg)
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](https://reader034.fdocuments.us/reader034/viewer/2022051616/5538337c4a7959f66c8b46b2/html5/thumbnails/16.jpg)
problemasynchronous programming
![Page 17: Actors, a Unifying Pattern for Scalable Concurrency | C4 2006](https://reader034.fdocuments.us/reader034/viewer/2022051616/5538337c4a7959f66c8b46b2/html5/thumbnails/17.jpg)
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](https://reader034.fdocuments.us/reader034/viewer/2022051616/5538337c4a7959f66c8b46b2/html5/thumbnails/18.jpg)
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](https://reader034.fdocuments.us/reader034/viewer/2022051616/5538337c4a7959f66c8b46b2/html5/thumbnails/19.jpg)
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](https://reader034.fdocuments.us/reader034/viewer/2022051616/5538337c4a7959f66c8b46b2/html5/thumbnails/20.jpg)
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](https://reader034.fdocuments.us/reader034/viewer/2022051616/5538337c4a7959f66c8b46b2/html5/thumbnails/21.jpg)
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](https://reader034.fdocuments.us/reader034/viewer/2022051616/5538337c4a7959f66c8b46b2/html5/thumbnails/22.jpg)
problemdistributed programming
![Page 23: Actors, a Unifying Pattern for Scalable Concurrency | C4 2006](https://reader034.fdocuments.us/reader034/viewer/2022051616/5538337c4a7959f66c8b46b2/html5/thumbnails/23.jpg)
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](https://reader034.fdocuments.us/reader034/viewer/2022051616/5538337c4a7959f66c8b46b2/html5/thumbnails/24.jpg)
problemthe high concurrencymemory bottleneck
![Page 25: Actors, a Unifying Pattern for Scalable Concurrency | C4 2006](https://reader034.fdocuments.us/reader034/viewer/2022051616/5538337c4a7959f66c8b46b2/html5/thumbnails/25.jpg)
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](https://reader034.fdocuments.us/reader034/viewer/2022051616/5538337c4a7959f66c8b46b2/html5/thumbnails/26.jpg)
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](https://reader034.fdocuments.us/reader034/viewer/2022051616/5538337c4a7959f66c8b46b2/html5/thumbnails/27.jpg)
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](https://reader034.fdocuments.us/reader034/viewer/2022051616/5538337c4a7959f66c8b46b2/html5/thumbnails/28.jpg)
what this means in practice
connections
![Page 29: Actors, a Unifying Pattern for Scalable Concurrency | C4 2006](https://reader034.fdocuments.us/reader034/viewer/2022051616/5538337c4a7959f66c8b46b2/html5/thumbnails/29.jpg)
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](https://reader034.fdocuments.us/reader034/viewer/2022051616/5538337c4a7959f66c8b46b2/html5/thumbnails/30.jpg)
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](https://reader034.fdocuments.us/reader034/viewer/2022051616/5538337c4a7959f66c8b46b2/html5/thumbnails/31.jpg)
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](https://reader034.fdocuments.us/reader034/viewer/2022051616/5538337c4a7959f66c8b46b2/html5/thumbnails/32.jpg)
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](https://reader034.fdocuments.us/reader034/viewer/2022051616/5538337c4a7959f66c8b46b2/html5/thumbnails/33.jpg)
actoruser thread
cluster
cluster cluster cluster
cluster
clusterclustercluster
![Page 34: Actors, a Unifying Pattern for Scalable Concurrency | C4 2006](https://reader034.fdocuments.us/reader034/viewer/2022051616/5538337c4a7959f66c8b46b2/html5/thumbnails/34.jpg)
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](https://reader034.fdocuments.us/reader034/viewer/2022051616/5538337c4a7959f66c8b46b2/html5/thumbnails/35.jpg)
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](https://reader034.fdocuments.us/reader034/viewer/2022051616/5538337c4a7959f66c8b46b2/html5/thumbnails/36.jpg)
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](https://reader034.fdocuments.us/reader034/viewer/2022051616/5538337c4a7959f66c8b46b2/html5/thumbnails/37.jpg)
some fun speculation
what about cores?a prediction based on this pattern
![Page 38: Actors, a Unifying Pattern for Scalable Concurrency | C4 2006](https://reader034.fdocuments.us/reader034/viewer/2022051616/5538337c4a7959f66c8b46b2/html5/thumbnails/38.jpg)
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](https://reader034.fdocuments.us/reader034/viewer/2022051616/5538337c4a7959f66c8b46b2/html5/thumbnails/39.jpg)
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](https://reader034.fdocuments.us/reader034/viewer/2022051616/5538337c4a7959f66c8b46b2/html5/thumbnails/40.jpg)
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](https://reader034.fdocuments.us/reader034/viewer/2022051616/5538337c4a7959f66c8b46b2/html5/thumbnails/41.jpg)
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](https://reader034.fdocuments.us/reader034/viewer/2022051616/5538337c4a7959f66c8b46b2/html5/thumbnails/42.jpg)
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]