comparing implementations of the actor model
DESCRIPTION
Presentation for term paper for CSC 464 Concurrency, in Victoria, in April 2008. Slideshare removed the photos, here's a PDF version https://dl.dropboxusercontent.com/u/169716/csc464-project/Comparing%20Implementations%20of%20the%20Actor%20Model.pdfTRANSCRIPT
![Page 1: Comparing implementations of the actor model](https://reader034.vdocument.in/reader034/viewer/2022052619/555a5f92d8b42a47748b5269/html5/thumbnails/1.jpg)
Comparing implementations of
the Actor ModelJim Roepcke<[email protected]>
Concurrency Summit 2008
1
![Page 2: Comparing implementations of the actor model](https://reader034.vdocument.in/reader034/viewer/2022052619/555a5f92d8b42a47748b5269/html5/thumbnails/2.jpg)
Actor models?
2
![Page 3: Comparing implementations of the actor model](https://reader034.vdocument.in/reader034/viewer/2022052619/555a5f92d8b42a47748b5269/html5/thumbnails/3.jpg)
This kind?3
![Page 4: Comparing implementations of the actor model](https://reader034.vdocument.in/reader034/viewer/2022052619/555a5f92d8b42a47748b5269/html5/thumbnails/4.jpg)
No, not that kind...
4
![Page 5: Comparing implementations of the actor model](https://reader034.vdocument.in/reader034/viewer/2022052619/555a5f92d8b42a47748b5269/html5/thumbnails/5.jpg)
The kind in Joe Armstrong’s Erlang,
5
![Page 6: Comparing implementations of the actor model](https://reader034.vdocument.in/reader034/viewer/2022052619/555a5f92d8b42a47748b5269/html5/thumbnails/6.jpg)
The kind in Joe Armstrong’s Erlang,
6
![Page 7: Comparing implementations of the actor model](https://reader034.vdocument.in/reader034/viewer/2022052619/555a5f92d8b42a47748b5269/html5/thumbnails/7.jpg)
Evan Phoenix’s Rubinius,
7
![Page 8: Comparing implementations of the actor model](https://reader034.vdocument.in/reader034/viewer/2022052619/555a5f92d8b42a47748b5269/html5/thumbnails/8.jpg)
Martin Odersky’s Scala,
8
![Page 9: Comparing implementations of the actor model](https://reader034.vdocument.in/reader034/viewer/2022052619/555a5f92d8b42a47748b5269/html5/thumbnails/9.jpg)
and Steve Dekorte’sIo.
9
![Page 10: Comparing implementations of the actor model](https://reader034.vdocument.in/reader034/viewer/2022052619/555a5f92d8b42a47748b5269/html5/thumbnails/10.jpg)
What is theActor Model?
10
![Page 11: Comparing implementations of the actor model](https://reader034.vdocument.in/reader034/viewer/2022052619/555a5f92d8b42a47748b5269/html5/thumbnails/11.jpg)
It’s a trendy model for
concurrent programming
11
![Page 12: Comparing implementations of the actor model](https://reader034.vdocument.in/reader034/viewer/2022052619/555a5f92d8b42a47748b5269/html5/thumbnails/12.jpg)
Massively parallel future
• The future has begun!
• We had lots of time to figure this out
• Programmers are still using threads and mutexes in “high level” code
• Bad programmer!
• ABSTRACTION FTW!
12
![Page 13: Comparing implementations of the actor model](https://reader034.vdocument.in/reader034/viewer/2022052619/555a5f92d8b42a47748b5269/html5/thumbnails/13.jpg)
What’s old is new again
• Actors defined by Hewitt in 1973
• More work by his PhD students in the 80s, Clinger, Agha
• Adopted by Erlang in the late 80s for the telecom industry
• Picking up steam as concurrency becomes a hot issue again
13
![Page 14: Comparing implementations of the actor model](https://reader034.vdocument.in/reader034/viewer/2022052619/555a5f92d8b42a47748b5269/html5/thumbnails/14.jpg)
Actors win because they are simple
14
![Page 15: Comparing implementations of the actor model](https://reader034.vdocument.in/reader034/viewer/2022052619/555a5f92d8b42a47748b5269/html5/thumbnails/15.jpg)
Actors communicate15
![Page 16: Comparing implementations of the actor model](https://reader034.vdocument.in/reader034/viewer/2022052619/555a5f92d8b42a47748b5269/html5/thumbnails/16.jpg)
Actors spawn16
![Page 17: Comparing implementations of the actor model](https://reader034.vdocument.in/reader034/viewer/2022052619/555a5f92d8b42a47748b5269/html5/thumbnails/17.jpg)
Actors run in parallel17
![Page 18: Comparing implementations of the actor model](https://reader034.vdocument.in/reader034/viewer/2022052619/555a5f92d8b42a47748b5269/html5/thumbnails/18.jpg)
Actors listen18
![Page 19: Comparing implementations of the actor model](https://reader034.vdocument.in/reader034/viewer/2022052619/555a5f92d8b42a47748b5269/html5/thumbnails/19.jpg)
Actors avoid deadlock19
![Page 20: Comparing implementations of the actor model](https://reader034.vdocument.in/reader034/viewer/2022052619/555a5f92d8b42a47748b5269/html5/thumbnails/20.jpg)
Actors perform great!20
![Page 21: Comparing implementations of the actor model](https://reader034.vdocument.in/reader034/viewer/2022052619/555a5f92d8b42a47748b5269/html5/thumbnails/21.jpg)
Now: up close21
![Page 22: Comparing implementations of the actor model](https://reader034.vdocument.in/reader034/viewer/2022052619/555a5f92d8b42a47748b5269/html5/thumbnails/22.jpg)
ComparingActors to Actors
• Implemented a program in Erlang, Rubinius, Scala and Io
• My experiences with each
22
![Page 23: Comparing implementations of the actor model](https://reader034.vdocument.in/reader034/viewer/2022052619/555a5f92d8b42a47748b5269/html5/thumbnails/23.jpg)
OM NOM NOM!
• Implemented the “burger problem” from CSC 464 Assignment 1 in all four languages
23
![Page 24: Comparing implementations of the actor model](https://reader034.vdocument.in/reader034/viewer/2022052619/555a5f92d8b42a47748b5269/html5/thumbnails/24.jpg)
supervisor
spawn!
24
![Page 25: Comparing implementations of the actor model](https://reader034.vdocument.in/reader034/viewer/2022052619/555a5f92d8b42a47748b5269/html5/thumbnails/25.jpg)
Student
Cook
Student
Student
Order Line
CookCook
Burger Line
Student
StudentStudent
Burger Burger
Burger
hungry
burger!
enjoy!
ok
mmm
supervisor 25
![Page 26: Comparing implementations of the actor model](https://reader034.vdocument.in/reader034/viewer/2022052619/555a5f92d8b42a47748b5269/html5/thumbnails/26.jpg)
Actors communicate26
![Page 27: Comparing implementations of the actor model](https://reader034.vdocument.in/reader034/viewer/2022052619/555a5f92d8b42a47748b5269/html5/thumbnails/27.jpg)
Communication
• Asynchronous Message Passing
• Encourages no memory sharing
• Each actor has a “mailbox” which queues messages sent
• “send” mechanism to deliver a message to an actor
27
![Page 28: Comparing implementations of the actor model](https://reader034.vdocument.in/reader034/viewer/2022052619/555a5f92d8b42a47748b5269/html5/thumbnails/28.jpg)
Sending messages
Erlang
pid ! message
Rubinius
actor << message
Scala
actor ! message
Io
obj @@method(args)
28
![Page 29: Comparing implementations of the actor model](https://reader034.vdocument.in/reader034/viewer/2022052619/555a5f92d8b42a47748b5269/html5/thumbnails/29.jpg)
Actors and burgers29
![Page 30: Comparing implementations of the actor model](https://reader034.vdocument.in/reader034/viewer/2022052619/555a5f92d8b42a47748b5269/html5/thumbnails/30.jpg)
Actors spawn30
![Page 31: Comparing implementations of the actor model](https://reader034.vdocument.in/reader034/viewer/2022052619/555a5f92d8b42a47748b5269/html5/thumbnails/31.jpg)
Creating actors
• To create concurrency, actors create more actors and send them messages
• Actors are independently executing entities
31
![Page 32: Comparing implementations of the actor model](https://reader034.vdocument.in/reader034/viewer/2022052619/555a5f92d8b42a47748b5269/html5/thumbnails/32.jpg)
Creating actors
Erlang
pid = spawn(fun)
Rubinius
actor = Actor.spawn ...
Scala
sa = new SomeActor()sa.start()
Io
sa := SomeActor clone
32
![Page 33: Comparing implementations of the actor model](https://reader034.vdocument.in/reader034/viewer/2022052619/555a5f92d8b42a47748b5269/html5/thumbnails/33.jpg)
Erlang Actors
• Actors are called processes
• Process creation and context switching is very fast and lightweight
• Processes cannot share memory
• Typically run a tail-recursive function
33
![Page 34: Comparing implementations of the actor model](https://reader034.vdocument.in/reader034/viewer/2022052619/555a5f92d8b42a47748b5269/html5/thumbnails/34.jpg)
Rubinius Actors
• Actor class comes with Rubinius VM
• Green Ruby thread per actor
• VM assigns a Mailbox per thread
• Remote Actors new, not perfect yet
• “Orders of magnitude” worse than Erlang: Rubinius developer on IRC
34
![Page 35: Comparing implementations of the actor model](https://reader034.vdocument.in/reader034/viewer/2022052619/555a5f92d8b42a47748b5269/html5/thumbnails/35.jpg)
Scala Actors
• scala.actors package comes with Scala
• Hybrid execution model, actors run in their own thread or via events
• Claim massive scalability using events and thread pools
• Remote Actors supported
• act() loops to stay alive
35
![Page 36: Comparing implementations of the actor model](https://reader034.vdocument.in/reader034/viewer/2022052619/555a5f92d8b42a47748b5269/html5/thumbnails/36.jpg)
Io Actors
• Io uses coroutines for concurrency
• Scheduling is FIFO, no prioritization
• One kernel thread per VM, async I/O
• @@ runs the method on a dedicated per-object coroutine for messages
• Remote actors not supported
36
![Page 37: Comparing implementations of the actor model](https://reader034.vdocument.in/reader034/viewer/2022052619/555a5f92d8b42a47748b5269/html5/thumbnails/37.jpg)
Actors run in parallel37
![Page 38: Comparing implementations of the actor model](https://reader034.vdocument.in/reader034/viewer/2022052619/555a5f92d8b42a47748b5269/html5/thumbnails/38.jpg)
Parallelism: Erlang
• SMP Erlang automatically puts processes on different cores/CPUs
• Messaging actors in remote VMs is seamless
• spawn(Node, fun) to spawn an actor on a different VM which may be remote
38
![Page 39: Comparing implementations of the actor model](https://reader034.vdocument.in/reader034/viewer/2022052619/555a5f92d8b42a47748b5269/html5/thumbnails/39.jpg)
Parallelism: Rubinius
• One kernel thread per Rubinius VM
• Processor affinity for multi-core?
• Use VMActor to create an actor on a remote VM
• Messaging actors in remote VMs is seamless thanks to duck typing
39
![Page 40: Comparing implementations of the actor model](https://reader034.vdocument.in/reader034/viewer/2022052619/555a5f92d8b42a47748b5269/html5/thumbnails/40.jpg)
Parallelism: Scala
• When using event-based actors, Scala creates multple threads to balance load across cores
• Use RemoteActor class to find an actor on a different VM
• Messaging actors in remote VMs is seamless
40
![Page 41: Comparing implementations of the actor model](https://reader034.vdocument.in/reader034/viewer/2022052619/555a5f92d8b42a47748b5269/html5/thumbnails/41.jpg)
Parallelism: Io
•Nope :-(
•One kernel thread per VM
•No support for remote actors built-in
41
![Page 42: Comparing implementations of the actor model](https://reader034.vdocument.in/reader034/viewer/2022052619/555a5f92d8b42a47748b5269/html5/thumbnails/42.jpg)
Actors listen42
![Page 43: Comparing implementations of the actor model](https://reader034.vdocument.in/reader034/viewer/2022052619/555a5f92d8b42a47748b5269/html5/thumbnails/43.jpg)
Receiving messages
• Take a message off the mailbox queue
• Decide if you want to deal with it
• Messages are data
• Timeouts
43
![Page 44: Comparing implementations of the actor model](https://reader034.vdocument.in/reader034/viewer/2022052619/555a5f92d8b42a47748b5269/html5/thumbnails/44.jpg)
Receiving messagesErlang
loop(State) -> % a tail-recursive function receive {hello, From} -> greet(From), loop(State) ping -> doPingThing(), loop(State) {goodbye, From} -> From ! {kthxbye, self(), State} % no loop after 100 loop(State+1) % inc # of timeouts end.
44
![Page 45: Comparing implementations of the actor model](https://reader034.vdocument.in/reader034/viewer/2022052619/555a5f92d8b42a47748b5269/html5/thumbnails/45.jpg)
Receiving messagesRubinius
def actor_process() looping = true while looping Actor.receive do |filter| filter.when Hello do |message| greet(message.from) end filter.when Goodbye do |message| message.from << KThxBye[self] looping = false end endend
45
![Page 46: Comparing implementations of the actor model](https://reader034.vdocument.in/reader034/viewer/2022052619/555a5f92d8b42a47748b5269/html5/thumbnails/46.jpg)
Receiving messagesScala
def act() loop { receive { case Hello(from) => greet(from) case Ping() => doPingThing() case Goodbye(from) => { from ! KThxBye(self) exit() } } }}
46
![Page 47: Comparing implementations of the actor model](https://reader034.vdocument.in/reader034/viewer/2022052619/555a5f92d8b42a47748b5269/html5/thumbnails/47.jpg)
Receiving messagesIo
MyActor := Object cloneMyActor hello := method(from, greet(from))MyActor ping := method(doPingThing)MyActor goodbye := method(from, from @@kthxbye(self))
anActor := MyActor clone // create actor instance anActor @@hello(self)anActor @@pinganActor @@goodbye(self) // look ma, no loops!
47
![Page 48: Comparing implementations of the actor model](https://reader034.vdocument.in/reader034/viewer/2022052619/555a5f92d8b42a47748b5269/html5/thumbnails/48.jpg)
Actors avoid deadlock48
![Page 49: Comparing implementations of the actor model](https://reader034.vdocument.in/reader034/viewer/2022052619/555a5f92d8b42a47748b5269/html5/thumbnails/49.jpg)
No locks, no dead
• Agha(1985) says the semantics of the Actor model mean that deadlock doesn’t exist in a syntactic sense
• Semantic deadlock can be detected and removed easily using wait-for graphs
49
![Page 50: Comparing implementations of the actor model](https://reader034.vdocument.in/reader034/viewer/2022052619/555a5f92d8b42a47748b5269/html5/thumbnails/50.jpg)
Actors perform great!50
![Page 51: Comparing implementations of the actor model](https://reader034.vdocument.in/reader034/viewer/2022052619/555a5f92d8b42a47748b5269/html5/thumbnails/51.jpg)
Fine grained, hot CPU
• Lightweight context switching
• Actors don’t suffer from locking granularity issues because there are no locks
• Actors can run “full out” on as many CPUs/machines as the underlying language can make available
51
![Page 52: Comparing implementations of the actor model](https://reader034.vdocument.in/reader034/viewer/2022052619/555a5f92d8b42a47748b5269/html5/thumbnails/52.jpg)
Conclusion
• Light, fast processes needed to see huge scalability
• Erlang’s the fastest and most mature (see OTP)
• You can’t sneeze in the JVM without declaring it’s chemical composition
• Io is a beautiful little language
52
![Page 53: Comparing implementations of the actor model](https://reader034.vdocument.in/reader034/viewer/2022052619/555a5f92d8b42a47748b5269/html5/thumbnails/53.jpg)
“erlang is nice, because
everything just works”
Paul JenkinsApril 11, 2008
53
![Page 54: Comparing implementations of the actor model](https://reader034.vdocument.in/reader034/viewer/2022052619/555a5f92d8b42a47748b5269/html5/thumbnails/54.jpg)
What next?
• Iolang... Io with:
• Support for multiple cores
• Easy way: one VM per core?
• Selective receive
• Support for remote actors
54
![Page 55: Comparing implementations of the actor model](https://reader034.vdocument.in/reader034/viewer/2022052619/555a5f92d8b42a47748b5269/html5/thumbnails/55.jpg)
No cows were hurt...55
![Page 56: Comparing implementations of the actor model](https://reader034.vdocument.in/reader034/viewer/2022052619/555a5f92d8b42a47748b5269/html5/thumbnails/56.jpg)
Picture creditsBillie Joe: http://flickr.com/photos/15034493@N00/112357008/sizes/l/
Joe Armstrong: http://flickr.com/photos/mbiddulph/2037845171/sizes/l/Evan Phoenix: http://flickr.com/photos/scoop/1403258349/sizes/o/Steve Dekorte: http://flickr.com/photos/x180/276960722/sizes/o/
Martin Odersky: http://picasaweb.google.com/JavaPolis.com/JavaPolis2007/photo#5144254997958003122Bruno: http://www.smh.com.au/ffximage/2006/10/31/bruno_wideweb__470x329,0.jpg
Coady: http://flickr.com/photos/sebastian_bergmann/116486823/sizes/o/Ships: http://flickr.com/photos/lesec/361956524/sizes/o/
Jim: http://flickr.com/photos/kteague/278136366/sizes/o/LOLcode: http://flickr.com/photos/i-marco/534996407/sizes/o/
Triplets: http://flickr.com/photos/origamijoel/217238954/sizes/l/Spawn: http://flickr.com/photos/austenhaines/399622840/
Parallel runners: http://flickr.com/photos/moodeous/205711924/sizes/o/Microscopic: http://flickr.com/photos/braid44/2232461763/sizes/o/
Emoburger: http://flickr.com/photos/gx9/269025682/Cow: http://flickr.com/photos/66164549@N00/542696674/sizes/o/
icanhascheezburger: http://icanhascheezburger.com/2007/01/11/i-can-has-cheezburger/
Thanks for listening
56
![Page 57: Comparing implementations of the actor model](https://reader034.vdocument.in/reader034/viewer/2022052619/555a5f92d8b42a47748b5269/html5/thumbnails/57.jpg)
QuestionsMake it quick, Paul’s next
57
![Page 58: Comparing implementations of the actor model](https://reader034.vdocument.in/reader034/viewer/2022052619/555a5f92d8b42a47748b5269/html5/thumbnails/58.jpg)
Dedicated toCheryl, Cyan, Xavier, and
Justin
58