0
Concurrency Summit 2008    Comparingimplementations of  the Actor Model       Jim Roepcke       <jr@uvic.ca>              ...
Actor models?                2
This kind?             3
No, not that kind...                       4
The kind in JoeArmstrong’s Erlang,                      5
The kind in JoeArmstrong’s Erlang,                      6
Evan Phoenix’s  Rubinius,                 7
Martin Odersky’s     Scala,                   8
and Steve Dekorte’s        Io.                      9
What is theActor Model?               10
It’s a trendy  model for concurrentprogramming                11
Massively parallel future• The future has begun!• We had lots of time to  figure this out• Programmers are still  using thr...
What’s old is new again• Actors defined by Hewitt in 1973• More work by his PhD students in the  80s, Clinger, Agha• Adopte...
Actors win because they are simple                     14
Actors communicate                     15
Actors spawn               16
Actors run in parallel                         17
Actors listen                18
Actors avoid deadlock                        19
Actors perform great!                        20
Now: up close                21
Comparing     Actors to Actors• Implemented a program in Erlang,  Rubinius, Scala and Io• My experiences with each        ...
OM NOM NOM!• Implemented the  “burger problem”  from CSC 464  Assignment 1 in all  four languages                        23
spawn!supervisor                 24
mmm                      hungry                                               Student            Student              Stud...
Actors communicate                     26
Communication• Asynchronous Message Passing• Encourages no memory sharing• Each actor has a “mailbox” which  queues messag...
Sending messages    Erlang             Rubinius pid ! message     actor << message    Scala                 Ioactor ! mess...
Actors and burgers                     29
Actors spawn               30
Creating actors• To create concurrency, actors create  more actors and send them messages• Actors are independently execut...
Creating actors      Erlang                 Rubinius  pid = spawn(fun)     actor = Actor.spawn ...       Scala            ...
Erlang Actors• Actors are called processes• Process creation and context  switching is very fast and lightweight• Processe...
Rubinius Actors• Actor class comes with Rubinius VM• Green Ruby thread per actor• VM assigns a Mailbox per thread• Remote ...
Scala Actors• scala.actors package comes with Scala• Hybrid execution model, actors run in  their own thread or via events...
Io Actors• Io uses coroutines for concurrency• Scheduling is FIFO, no prioritization• One kernel thread per VM, async I/O•...
Actors run in parallel                         37
Parallelism: Erlang• SMP Erlang automatically puts  processes on different cores/CPUs• Messaging actors in remote VMs is  ...
Parallelism: Rubinius• One kernel thread per Rubinius VM• Processor affinity for multi-core?• Use VMActor to create an acto...
Parallelism: Scala• When using event-based actors, Scala  creates multple threads to balance  load across cores• Use Remot...
Parallelism: Io• Nope :-(• One kernel thread per VM• No support for remote actors built-in                          41
Actors listen                42
Receiving messages• Take a message off the mailbox queue• Decide if you want to deal with it• Messages are data• Timeouts ...
Receiving messages                     Erlangloop(State) -> % a tail-recursive function  receive    {hello, From} ->      ...
Receiving messages                      Rubiniusdef actor_process()  looping = true  while looping    Actor.receive do |fil...
Receiving messages                        Scaladef act()  loop {    receive {       case Hello(from) => greet(from)       ...
Receiving messages                        IoMyActor := Object cloneMyActor hello := method(from, greet(from))MyActor ping ...
Actors avoid deadlock                        48
No locks, no dead• Agha(1985) says the semantics of the  Actor model mean that deadlock  doesn’t exist in a syntactic sens...
Actors perform great!                        50
Fine grained, hot CPU• Lightweight context switching• Actors don’t suffer from locking  granularity issues because there a...
Conclusion• Light, fast processes needed to see  huge scalability• Erlang’s the fastest and most mature  (see OTP)• You ca...
“erlang is nice,    because  everything  just works”    Paul Jenkins    April 11, 2008                     53
What next?• Iolang... Io with:  • Support for multiple cores  • Easy way: one VM per core?  • Selective receive  • Support...
No cows were hurt...                       55
Thanks for listening                                Picture credits                  Billie Joe: http://flickr.com/photos/1...
QuestionsMake it quick, Paul’s next                             57
Dedicated to Cheryl, Cyan,  Xavier, and    Justin                 58
Upcoming SlideShare
Loading in...5
×

Comparing implementations of the actor model

500

Published on

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.pdf

Published in: Technology
0 Comments
1 Like
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total Views
500
On Slideshare
0
From Embeds
0
Number of Embeds
0
Actions
Shares
0
Downloads
14
Comments
0
Likes
1
Embeds 0
No embeds

No notes for slide

Transcript of "Comparing implementations of the actor model"

  1. 1. Concurrency Summit 2008 Comparingimplementations of the Actor Model Jim Roepcke <jr@uvic.ca> 1
  2. 2. Actor models? 2
  3. 3. This kind? 3
  4. 4. No, not that kind... 4
  5. 5. The kind in JoeArmstrong’s Erlang, 5
  6. 6. The kind in JoeArmstrong’s Erlang, 6
  7. 7. Evan Phoenix’s Rubinius, 7
  8. 8. Martin Odersky’s Scala, 8
  9. 9. and Steve Dekorte’s Io. 9
  10. 10. What is theActor Model? 10
  11. 11. It’s a trendy model for concurrentprogramming 11
  12. 12. 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
  13. 13. 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
  14. 14. Actors win because they are simple 14
  15. 15. Actors communicate 15
  16. 16. Actors spawn 16
  17. 17. Actors run in parallel 17
  18. 18. Actors listen 18
  19. 19. Actors avoid deadlock 19
  20. 20. Actors perform great! 20
  21. 21. Now: up close 21
  22. 22. Comparing Actors to Actors• Implemented a program in Erlang, Rubinius, Scala and Io• My experiences with each 22
  23. 23. OM NOM NOM!• Implemented the “burger problem” from CSC 464 Assignment 1 in all four languages 23
  24. 24. spawn!supervisor 24
  25. 25. mmm hungry Student Student Student Burger burger! Student Student enjoy! Order Line Burger Line okk Cook Cook Burger Burger supervisor 25
  26. 26. Actors communicate 26
  27. 27. 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
  28. 28. Sending messages Erlang Rubinius pid ! message actor << message Scala Ioactor ! message obj @@method(args) 28
  29. 29. Actors and burgers 29
  30. 30. Actors spawn 30
  31. 31. Creating actors• To create concurrency, actors create more actors and send them messages• Actors are independently executing entities 31
  32. 32. Creating actors Erlang Rubinius pid = spawn(fun) actor = Actor.spawn ... Scala Iosa = new SomeActor() sa := SomeActor clone sa.start() 32
  33. 33. 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
  34. 34. 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
  35. 35. 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
  36. 36. 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
  37. 37. Actors run in parallel 37
  38. 38. 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
  39. 39. 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
  40. 40. 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
  41. 41. Parallelism: Io• Nope :-(• One kernel thread per VM• No support for remote actors built-in 41
  42. 42. Actors listen 42
  43. 43. Receiving messages• Take a message off the mailbox queue• Decide if you want to deal with it• Messages are data• Timeouts 43
  44. 44. Receiving messages Erlangloop(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
  45. 45. Receiving messages Rubiniusdef 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
  46. 46. Receiving messages Scaladef act() loop { receive { case Hello(from) => greet(from) case Ping() => doPingThing() case Goodbye(from) => { from ! KThxBye(self) exit() } } }} 46
  47. 47. Receiving messages IoMyActor := Object cloneMyActor hello := method(from, greet(from))MyActor ping := method(doPingThing)MyActor goodbye := method(from, from @@kthxbye(self))anActor := MyActor clone // create actor instanceanActor @@hello(self)anActor @@pinganActor @@goodbye(self) // look ma, no loops! 47
  48. 48. Actors avoid deadlock 48
  49. 49. 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
  50. 50. Actors perform great! 50
  51. 51. 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
  52. 52. 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
  53. 53. “erlang is nice, because everything just works” Paul Jenkins April 11, 2008 53
  54. 54. What next?• Iolang... Io with: • Support for multiple cores • Easy way: one VM per core? • Selective receive • Support for remote actors 54
  55. 55. No cows were hurt... 55
  56. 56. Thanks for listening Picture credits Billie 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#5144254997958003122 Bruno: 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/ 56
  57. 57. QuestionsMake it quick, Paul’s next 57
  58. 58. Dedicated to Cheryl, Cyan, Xavier, and Justin 58
  1. A particular slide catching your eye?

    Clipping is a handy way to collect important slides you want to go back to later.

×