SlideShare a Scribd company logo
1 of 58
Download to read offline
Concurrency Summit 2008


    Comparing
implementations of
  the Actor Model
       Jim Roepcke
       <jr@uvic.ca>

                            1
Actor models?



                2
This kind?
             3
No, not that kind...



                       4
The kind in Joe
Armstrong’s Erlang,
                      5
The kind in Joe
Armstrong’s Erlang,
                      6
Evan Phoenix’s
  Rubinius,
                 7
Martin Odersky’s
     Scala,
                   8
and Steve Dekorte’s
        Io.
                      9
What is the
Actor Model?



               10
It’s a trendy
  model for
 concurrent
programming



                11
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
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
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




                                     22
OM NOM NOM!


• Implemented the
  “burger problem”
  from CSC 464
  Assignment 1 in all
  four languages




                        23
spawn!

supervisor




                 24
mmm
                      hungry
                                               Student
            Student              Student
                                                   Burger
                      burger!

            Student              Student

                                              enjoy!

           Order Line           Burger Line

                      ok
k   Cook     Cook                  Burger Burger


                      supervisor                         25
Actors communicate
                     26
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
Sending messages

    Erlang             Rubinius

 pid ! message     actor << message



    Scala                 Io

actor ! message   obj @@method(args)



                                       28
Actors and burgers
                     29
Actors spawn
               30
Creating actors


• To create concurrency, actors create
  more actors and send them messages
• Actors are independently executing
  entities




                                         31
Creating actors

      Erlang                 Rubinius

  pid = spawn(fun)     actor = Actor.spawn ...


       Scala
                                 Io
sa = new SomeActor()
                       sa := SomeActor clone
      sa.start()



                                                 32
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
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
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
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
Actors run in parallel
                         37
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
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
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
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



                                         43
Receiving messages
                     Erlang

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
Receiving messages
                      Rubinius

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
  end
end

                                       45
Receiving messages
                        Scala

def act()
  loop {
    receive {
       case Hello(from) => greet(from)
       case Ping() => doPingThing()
       case Goodbye(from) => {
         from ! KThxBye(self)
         exit()
       }
    }
  }
}

                                         46
Receiving messages
                        Io

MyActor := Object clone
MyActor 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 @@ping
anActor @@goodbye(self) // look ma, no loops!

                                                    47
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 sense

• Semantic deadlock can be detected
  and removed easily using wait-for
  graphs



                                         49
Actors perform great!
                        50
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
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
“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 for remote actors


                                 54
No cows were hurt...
                       55
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
Questions
Make it quick, Paul’s next




                             57
Dedicated to
 Cheryl, Cyan,
  Xavier, and
    Justin



                 58

More Related Content

Similar to Comparing implementations of the actor model

Rocket Fuelled Cucumbers
Rocket Fuelled CucumbersRocket Fuelled Cucumbers
Rocket Fuelled CucumbersJoseph Wilk
 
Concurrency in Python
Concurrency in PythonConcurrency in Python
Concurrency in PythonMosky Liu
 
Scratching the itch, making Scratch for the Raspberry Pie
Scratching the itch, making Scratch for the Raspberry PieScratching the itch, making Scratch for the Raspberry Pie
Scratching the itch, making Scratch for the Raspberry PieESUG
 
Steelcon 2014 - Process Injection with Python
Steelcon 2014 - Process Injection with PythonSteelcon 2014 - Process Injection with Python
Steelcon 2014 - Process Injection with Pythoninfodox
 
Intro to elixir and phoenix
Intro to elixir and phoenixIntro to elixir and phoenix
Intro to elixir and phoenixJared Smith
 
Cloud native akka and kubernetes holy grail to elasticity
Cloud native akka and kubernetes   holy grail to elasticityCloud native akka and kubernetes   holy grail to elasticity
Cloud native akka and kubernetes holy grail to elasticityFabio Tiriticco
 
Cloud Native Akka & Kubernetes: the holy grail to elasticity?
Cloud Native Akka & Kubernetes: the holy grail to elasticity?Cloud Native Akka & Kubernetes: the holy grail to elasticity?
Cloud Native Akka & Kubernetes: the holy grail to elasticity?J On The Beach
 
Introduction to Akka - Atlanta Java Users Group
Introduction to Akka - Atlanta Java Users GroupIntroduction to Akka - Atlanta Java Users Group
Introduction to Akka - Atlanta Java Users GroupRoy Russo
 
Modern Java Concurrency (Devoxx Nov/2011)
Modern Java Concurrency (Devoxx Nov/2011)Modern Java Concurrency (Devoxx Nov/2011)
Modern Java Concurrency (Devoxx Nov/2011)Martijn Verburg
 
Distributed and concurrent programming with RabbitMQ and EventMachine Rails U...
Distributed and concurrent programming with RabbitMQ and EventMachine Rails U...Distributed and concurrent programming with RabbitMQ and EventMachine Rails U...
Distributed and concurrent programming with RabbitMQ and EventMachine Rails U...Paolo Negri
 
Hybrid concurrency patterns
Hybrid concurrency patternsHybrid concurrency patterns
Hybrid concurrency patternsKyle Drake
 
SPARKNaCl: A verified, fast cryptographic library
SPARKNaCl: A verified, fast cryptographic librarySPARKNaCl: A verified, fast cryptographic library
SPARKNaCl: A verified, fast cryptographic libraryAdaCore
 
Byteman and The Jokre, Sanne Grinovero (JBoss by RedHat)
Byteman and The Jokre, Sanne Grinovero (JBoss by RedHat)Byteman and The Jokre, Sanne Grinovero (JBoss by RedHat)
Byteman and The Jokre, Sanne Grinovero (JBoss by RedHat)OpenBlend society
 
TRICK2013 Results
TRICK2013 ResultsTRICK2013 Results
TRICK2013 Resultsmametter
 
CSP: Huh? And Components
CSP: Huh? And ComponentsCSP: Huh? And Components
CSP: Huh? And ComponentsDaniel Fagnan
 
Rethinking the debugger
Rethinking the debuggerRethinking the debugger
Rethinking the debuggerIulian Dragos
 

Similar to Comparing implementations of the actor model (20)

Rocket Fuelled Cucumbers
Rocket Fuelled CucumbersRocket Fuelled Cucumbers
Rocket Fuelled Cucumbers
 
Concurrency in Python
Concurrency in PythonConcurrency in Python
Concurrency in Python
 
Ruby Under The Hood
Ruby Under The HoodRuby Under The Hood
Ruby Under The Hood
 
Scratching the itch, making Scratch for the Raspberry Pie
Scratching the itch, making Scratch for the Raspberry PieScratching the itch, making Scratch for the Raspberry Pie
Scratching the itch, making Scratch for the Raspberry Pie
 
Steelcon 2014 - Process Injection with Python
Steelcon 2014 - Process Injection with PythonSteelcon 2014 - Process Injection with Python
Steelcon 2014 - Process Injection with Python
 
Intro to elixir and phoenix
Intro to elixir and phoenixIntro to elixir and phoenix
Intro to elixir and phoenix
 
Cloud native akka and kubernetes holy grail to elasticity
Cloud native akka and kubernetes   holy grail to elasticityCloud native akka and kubernetes   holy grail to elasticity
Cloud native akka and kubernetes holy grail to elasticity
 
Cloud Native Akka & Kubernetes: the holy grail to elasticity?
Cloud Native Akka & Kubernetes: the holy grail to elasticity?Cloud Native Akka & Kubernetes: the holy grail to elasticity?
Cloud Native Akka & Kubernetes: the holy grail to elasticity?
 
Lrug
LrugLrug
Lrug
 
Akka Actors
Akka ActorsAkka Actors
Akka Actors
 
Introduction to Akka - Atlanta Java Users Group
Introduction to Akka - Atlanta Java Users GroupIntroduction to Akka - Atlanta Java Users Group
Introduction to Akka - Atlanta Java Users Group
 
Modern Java Concurrency (Devoxx Nov/2011)
Modern Java Concurrency (Devoxx Nov/2011)Modern Java Concurrency (Devoxx Nov/2011)
Modern Java Concurrency (Devoxx Nov/2011)
 
Distributed and concurrent programming with RabbitMQ and EventMachine Rails U...
Distributed and concurrent programming with RabbitMQ and EventMachine Rails U...Distributed and concurrent programming with RabbitMQ and EventMachine Rails U...
Distributed and concurrent programming with RabbitMQ and EventMachine Rails U...
 
Hybrid concurrency patterns
Hybrid concurrency patternsHybrid concurrency patterns
Hybrid concurrency patterns
 
SPARKNaCl: A verified, fast cryptographic library
SPARKNaCl: A verified, fast cryptographic librarySPARKNaCl: A verified, fast cryptographic library
SPARKNaCl: A verified, fast cryptographic library
 
JRuby: The Hard Parts
JRuby: The Hard PartsJRuby: The Hard Parts
JRuby: The Hard Parts
 
Byteman and The Jokre, Sanne Grinovero (JBoss by RedHat)
Byteman and The Jokre, Sanne Grinovero (JBoss by RedHat)Byteman and The Jokre, Sanne Grinovero (JBoss by RedHat)
Byteman and The Jokre, Sanne Grinovero (JBoss by RedHat)
 
TRICK2013 Results
TRICK2013 ResultsTRICK2013 Results
TRICK2013 Results
 
CSP: Huh? And Components
CSP: Huh? And ComponentsCSP: Huh? And Components
CSP: Huh? And Components
 
Rethinking the debugger
Rethinking the debuggerRethinking the debugger
Rethinking the debugger
 

Recently uploaded

Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024BookNet Canada
 
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptxThe Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptxLoriGlavin3
 
Scanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL CertsScanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL CertsRizwan Syed
 
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024BookNet Canada
 
Commit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easyCommit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easyAlfredo García Lavilla
 
SALESFORCE EDUCATION CLOUD | FEXLE SERVICES
SALESFORCE EDUCATION CLOUD | FEXLE SERVICESSALESFORCE EDUCATION CLOUD | FEXLE SERVICES
SALESFORCE EDUCATION CLOUD | FEXLE SERVICESmohitsingh558521
 
Connect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationConnect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationSlibray Presentation
 
Hyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdf
Hyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdfHyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdf
Hyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdfPrecisely
 
SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024Lorenzo Miniero
 
Unraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfUnraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfAlex Barbosa Coqueiro
 
Take control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test SuiteTake control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test SuiteDianaGray10
 
Advanced Computer Architecture – An Introduction
Advanced Computer Architecture – An IntroductionAdvanced Computer Architecture – An Introduction
Advanced Computer Architecture – An IntroductionDilum Bandara
 
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek SchlawackFwdays
 
Dev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebDev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebUiPathCommunity
 
Developer Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQLDeveloper Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQLScyllaDB
 
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Mark Simos
 
Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 365Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 3652toLead Limited
 
Unleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding ClubUnleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding ClubKalema Edgar
 
"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr BaganFwdays
 
DSPy a system for AI to Write Prompts and Do Fine Tuning
DSPy a system for AI to Write Prompts and Do Fine TuningDSPy a system for AI to Write Prompts and Do Fine Tuning
DSPy a system for AI to Write Prompts and Do Fine TuningLars Bell
 

Recently uploaded (20)

Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
 
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptxThe Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
 
Scanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL CertsScanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL Certs
 
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
 
Commit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easyCommit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easy
 
SALESFORCE EDUCATION CLOUD | FEXLE SERVICES
SALESFORCE EDUCATION CLOUD | FEXLE SERVICESSALESFORCE EDUCATION CLOUD | FEXLE SERVICES
SALESFORCE EDUCATION CLOUD | FEXLE SERVICES
 
Connect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationConnect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck Presentation
 
Hyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdf
Hyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdfHyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdf
Hyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdf
 
SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024
 
Unraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfUnraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdf
 
Take control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test SuiteTake control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test Suite
 
Advanced Computer Architecture – An Introduction
Advanced Computer Architecture – An IntroductionAdvanced Computer Architecture – An Introduction
Advanced Computer Architecture – An Introduction
 
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
 
Dev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebDev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio Web
 
Developer Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQLDeveloper Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQL
 
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
 
Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 365Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 365
 
Unleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding ClubUnleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding Club
 
"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan
 
DSPy a system for AI to Write Prompts and Do Fine Tuning
DSPy a system for AI to Write Prompts and Do Fine TuningDSPy a system for AI to Write Prompts and Do Fine Tuning
DSPy a system for AI to Write Prompts and Do Fine Tuning
 

Comparing implementations of the actor model

  • 1. Concurrency Summit 2008 Comparing implementations of the Actor Model Jim Roepcke <jr@uvic.ca> 1
  • 4. No, not that kind... 4
  • 5. The kind in Joe Armstrong’s Erlang, 5
  • 6. The kind in Joe Armstrong’s Erlang, 6
  • 7. Evan Phoenix’s Rubinius, 7
  • 10. What is the Actor Model? 10
  • 11. It’s a trendy model for concurrent programming 11
  • 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. 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. Actors win because they are simple 14
  • 17. Actors run in parallel 17
  • 22. Comparing Actors to Actors • Implemented a program in Erlang, Rubinius, Scala and Io • My experiences with each 22
  • 23. OM NOM NOM! • Implemented the “burger problem” from CSC 464 Assignment 1 in all four languages 23
  • 25. mmm hungry Student Student Student Burger burger! Student Student enjoy! Order Line Burger Line ok k Cook Cook Burger Burger supervisor 25
  • 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. Sending messages Erlang Rubinius pid ! message actor << message Scala Io actor ! message obj @@method(args) 28
  • 31. Creating actors • To create concurrency, actors create more actors and send them messages • Actors are independently executing entities 31
  • 32. Creating actors Erlang Rubinius pid = spawn(fun) actor = Actor.spawn ... Scala Io sa = new SomeActor() sa := SomeActor clone sa.start() 32
  • 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. 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. 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. 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. Actors run in parallel 37
  • 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. 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. 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. Parallelism: Io • Nope :-( • One kernel thread per VM • No support for remote actors built-in 41
  • 43. Receiving messages • Take a message off the mailbox queue • Decide if you want to deal with it • Messages are data • Timeouts 43
  • 44. Receiving messages Erlang 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
  • 45. Receiving messages Rubinius 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 end end 45
  • 46. Receiving messages Scala def act() loop { receive { case Hello(from) => greet(from) case Ping() => doPingThing() case Goodbye(from) => { from ! KThxBye(self) exit() } } } } 46
  • 47. Receiving messages Io MyActor := Object clone MyActor 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 @@ping anActor @@goodbye(self) // look ma, no loops! 47
  • 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
  • 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. 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. “erlang is nice, because everything just works” Paul Jenkins April 11, 2008 53
  • 54. What next? • Iolang... Io with: • Support for multiple cores • Easy way: one VM per core? • Selective receive • Support for remote actors 54
  • 55. No cows were hurt... 55
  • 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. Questions Make it quick, Paul’s next 57
  • 58. Dedicated to Cheryl, Cyan, Xavier, and Justin 58