SlideShare a Scribd company logo
Ruby
                     goes to

                        @elise_huard Euruko 2011
Monday 30 May 2011
Why Concurrency?



Monday 30 May 2011
“... for the first time in history, no one is
                     building a much faster sequential processor.
                     If you want your programs to run
                     significantly faster (...) you’re going to have to
                     parallelize your program.”
                                                           Hennessy and Patterson
                                       “Computer Architectures” (4th edition, 2007)




Monday 30 May 2011
Concurrency !=
                       Parallellism


Monday 30 May 2011
3 threads, 2 cores


                      1                    1       2




                      2                    3
                                                   1




                       3                   3
                                                   2




                       1




                     core1   core2         core1   core2


Monday 30 May 2011
Your program




                                language VM



                                     OS
                     (kernel processes, other processes)


                          multicore - multiCPU


Monday 30 May 2011
Concurrency will melt
                    your brain

                     non-determinism
                     mutable AND shared state



Monday 30 May 2011
Actor Model




Monday 30 May 2011
Hewitt et al. 1973
                     no shared state
                     in response to a message, an actor can:
                     make local decisions
                     create more actors
                     send more messages
                     determine how to respond to the next message
                     received



Monday 30 May 2011
Hewitt et al. 1973


                     Generalization of the lambda
                     calculus



Monday 30 May 2011
Inspiration

                     artificial intelligence
                     ‘quantum mechanics’ - observing details
                     by which the order of arrival of
                     messages for an actor is determined
                     can affect result



Monday 30 May 2011
The point
                      only actors - no global state
                      partial order of execution




           from http://pragprog.com/titles/vspcon/programming-concurrency-on-the-jvm




Monday 30 May 2011
Implementations

                     • using threads/processes
                     • async messaging - mailbox
                     • pattern matching on incoming messages
                     • actors = state machines.

Monday 30 May 2011
Lifecycle




                     from http://pragprog.com/titles/vspcon/programming-concurrency-on-the-jvm




Monday 30 May 2011
Sleeping barber
                     shop with x chairs
                     1 barber
                         no customer: sleep. customers: cut hairs
                     customer
                         if barber is sleeping: wake him up
                         else if enough chairs take a chair
                         else leave


Monday 30 May 2011
Monday 30 May 2011
Actors in Ruby




Monday 30 May 2011
Concurrent gem

                     theoretical - different concurrency
                     models
                     https://github.com/mental/concurrent




Monday 30 May 2011
Rubinius Actors
                     require 'actor'


                     actor = Actor.spawn(Actor.current) do |master|
                       msg = Actor.receive
                       master.send msg
                     end


                     actor.send "test"
                     msg = Actor.receive
                     # msg == "test"




Monday 30 May 2011
Revactor

               concurrent I/O for networking
               apps
               Evented rather than parallel
                     https://github.com/tarcieri/revactor



Monday 30 May 2011
Celluloid


                     thread-based actors
                     based on erlang

                      https://github.com/tarcieri/celluloid


Monday 30 May 2011
No true parallelism
                          with MRI


Monday 30 May 2011
Cheat on Ruby


Monday 30 May 2011
Erlang


                     light-weight processes
                     = actors


Monday 30 May 2011
Erlang

                     blocking receives
                     timeouts
                     supervision trees: fault-tolerance



Monday 30 May 2011
Erlectricity
              require 'rubygems'

              require 'erlectricity'

              receive do |f|
                f.when([:echo, String]) do |text|
                  f.send!([:result, "You said: #{text}"])
                  f.receive_loop
                end
              end

              https://github.com/mojombo/erlectricity
Monday 30 May 2011
Reia or Elixir


                     languages on erlang vm
                     friendlier, more ruby-like, OO



Monday 30 May 2011
Scala
                     “We also included enhancements to make it
                     easier to call from Ruby into Scala libraries,
                     which has enabled the Lift web framework to
                     offer support for Ruby.” Charles Nutter, ‘JRuby 1.6 released,
                     now what ?’

                     http://www.engineyard.com/blog/2011/jruby-1-6-released-now-what/


                     Actors in standard library


Monday 30 May 2011
Akka



                actor model + software transactional memory
                               java and scala



Monday 30 May 2011
Akka

                     • sending: reply is possible or not, sync or
                       async
                     • supervision: several strategies
                     • as library or as framework
                     • local and distributed

Monday 30 May 2011
JRuby!



Monday 30 May 2011
Caveat



Monday 30 May 2011
Advantages

                     easy to grasp
                     real encapsulation -
                     separation of concerns
                     highly decentralized

Monday 30 May 2011
But


                     many messages (bandwidth)
                     livelocks are still possible



Monday 30 May 2011
Back to Ruby




Monday 30 May 2011
Time to control
                         shared state ?
                     Change RubySpec:
                     default: variables not shared between
                     threads?
                     integrate better concurrency primitives
                     into the Ruby stdlib ?


Monday 30 May 2011
Let’s think about it.



Monday 30 May 2011
Thanks
                             @elise_huard




                     http://www.delicious.com/elisehuard/concurrency
Monday 30 May 2011
Ruby
                      goes to
                     Hollywood
                           Elise Huard LRUG 11-04-2011
Monday 30 May 2011
Ruby
                      goes to
                     Hollywood
                            Elise Huard LRUG
Monday 30 May 2011
Monday 30 May 2011

More Related Content

PDF
Ruby hollywood
PDF
Envato Dev Ops - Alt.Net Melbourne
PDF
Drizzle 7.0, Future of Virtualizing
PPS
Barbeiro Sonolento
PDF
JavaScript Secrets
PDF
Nodejs
PDF
The facilities of Features Drupal module
PDF
Distribute the workload, PHPTek, Amsterdam, 2011
Ruby hollywood
Envato Dev Ops - Alt.Net Melbourne
Drizzle 7.0, Future of Virtualizing
Barbeiro Sonolento
JavaScript Secrets
Nodejs
The facilities of Features Drupal module
Distribute the workload, PHPTek, Amsterdam, 2011

Similar to Ruby goes to hollywood (10)

PDF
web标准化交流会bobby分享
PDF
web标准化交流会上海站bobby分享
PDF
Erlang: Bult for concurrent, distributed systems
PDF
Dev-Time Liferay
PDF
Neo4j Spatial - GIS for the rest of us.
PDF
Our Best Practices Are Killing Us
PDF
NodeJS, CoffeeScript & Real-time Web
PDF
Scaling websites with RabbitMQ A(rlvaro Videla)
PDF
BDD For Zend Framework With PHPSpec
PDF
Building an alarm clock with node.js
web标准化交流会bobby分享
web标准化交流会上海站bobby分享
Erlang: Bult for concurrent, distributed systems
Dev-Time Liferay
Neo4j Spatial - GIS for the rest of us.
Our Best Practices Are Killing Us
NodeJS, CoffeeScript & Real-time Web
Scaling websites with RabbitMQ A(rlvaro Videla)
BDD For Zend Framework With PHPSpec
Building an alarm clock with node.js
Ad

More from ehuard (14)

PDF
Euroclojure 2017
PDF
Ruby goes to Hollywood
PDF
Ruby hollywood nordic
PDF
Concurrency: Rubies, plural
PDF
Concurrency
PDF
Concurrency
PDF
12 hours to rate a rails application
PDF
how to rate a Rails application
PDF
12 Hours To Rate A Rails Application
KEY
Barcamp Ghent2009
ODP
Tokyo Cabinet
ODP
The real-time web
KEY
Rails and the internet of things
ODP
Oauth
Euroclojure 2017
Ruby goes to Hollywood
Ruby hollywood nordic
Concurrency: Rubies, plural
Concurrency
Concurrency
12 hours to rate a rails application
how to rate a Rails application
12 Hours To Rate A Rails Application
Barcamp Ghent2009
Tokyo Cabinet
The real-time web
Rails and the internet of things
Oauth
Ad

Recently uploaded (20)

PDF
Build a system with the filesystem maintained by OSTree @ COSCUP 2025
PDF
Per capita expenditure prediction using model stacking based on satellite ima...
PDF
Approach and Philosophy of On baking technology
PDF
Electronic commerce courselecture one. Pdf
PDF
Dropbox Q2 2025 Financial Results & Investor Presentation
PDF
Spectral efficient network and resource selection model in 5G networks
PDF
Machine learning based COVID-19 study performance prediction
PDF
Optimiser vos workloads AI/ML sur Amazon EC2 et AWS Graviton
PDF
A comparative analysis of optical character recognition models for extracting...
PDF
Chapter 3 Spatial Domain Image Processing.pdf
PDF
Peak of Data & AI Encore- AI for Metadata and Smarter Workflows
PDF
Unlocking AI with Model Context Protocol (MCP)
PDF
Profit Center Accounting in SAP S/4HANA, S4F28 Col11
PDF
NewMind AI Weekly Chronicles - August'25-Week II
PDF
gpt5_lecture_notes_comprehensive_20250812015547.pdf
PPTX
Digital-Transformation-Roadmap-for-Companies.pptx
PPTX
Cloud computing and distributed systems.
PPT
Teaching material agriculture food technology
PDF
Network Security Unit 5.pdf for BCA BBA.
PDF
Architecting across the Boundaries of two Complex Domains - Healthcare & Tech...
Build a system with the filesystem maintained by OSTree @ COSCUP 2025
Per capita expenditure prediction using model stacking based on satellite ima...
Approach and Philosophy of On baking technology
Electronic commerce courselecture one. Pdf
Dropbox Q2 2025 Financial Results & Investor Presentation
Spectral efficient network and resource selection model in 5G networks
Machine learning based COVID-19 study performance prediction
Optimiser vos workloads AI/ML sur Amazon EC2 et AWS Graviton
A comparative analysis of optical character recognition models for extracting...
Chapter 3 Spatial Domain Image Processing.pdf
Peak of Data & AI Encore- AI for Metadata and Smarter Workflows
Unlocking AI with Model Context Protocol (MCP)
Profit Center Accounting in SAP S/4HANA, S4F28 Col11
NewMind AI Weekly Chronicles - August'25-Week II
gpt5_lecture_notes_comprehensive_20250812015547.pdf
Digital-Transformation-Roadmap-for-Companies.pptx
Cloud computing and distributed systems.
Teaching material agriculture food technology
Network Security Unit 5.pdf for BCA BBA.
Architecting across the Boundaries of two Complex Domains - Healthcare & Tech...

Ruby goes to hollywood

  • 1. Ruby goes to @elise_huard Euruko 2011 Monday 30 May 2011
  • 3. “... for the first time in history, no one is building a much faster sequential processor. If you want your programs to run significantly faster (...) you’re going to have to parallelize your program.” Hennessy and Patterson “Computer Architectures” (4th edition, 2007) Monday 30 May 2011
  • 4. Concurrency != Parallellism Monday 30 May 2011
  • 5. 3 threads, 2 cores 1 1 2 2 3 1 3 3 2 1 core1 core2 core1 core2 Monday 30 May 2011
  • 6. Your program language VM OS (kernel processes, other processes) multicore - multiCPU Monday 30 May 2011
  • 7. Concurrency will melt your brain non-determinism mutable AND shared state Monday 30 May 2011
  • 9. Hewitt et al. 1973 no shared state in response to a message, an actor can: make local decisions create more actors send more messages determine how to respond to the next message received Monday 30 May 2011
  • 10. Hewitt et al. 1973 Generalization of the lambda calculus Monday 30 May 2011
  • 11. Inspiration artificial intelligence ‘quantum mechanics’ - observing details by which the order of arrival of messages for an actor is determined can affect result Monday 30 May 2011
  • 12. The point only actors - no global state partial order of execution from http://pragprog.com/titles/vspcon/programming-concurrency-on-the-jvm Monday 30 May 2011
  • 13. Implementations • using threads/processes • async messaging - mailbox • pattern matching on incoming messages • actors = state machines. Monday 30 May 2011
  • 14. Lifecycle from http://pragprog.com/titles/vspcon/programming-concurrency-on-the-jvm Monday 30 May 2011
  • 15. Sleeping barber shop with x chairs 1 barber no customer: sleep. customers: cut hairs customer if barber is sleeping: wake him up else if enough chairs take a chair else leave Monday 30 May 2011
  • 17. Actors in Ruby Monday 30 May 2011
  • 18. Concurrent gem theoretical - different concurrency models https://github.com/mental/concurrent Monday 30 May 2011
  • 19. Rubinius Actors require 'actor' actor = Actor.spawn(Actor.current) do |master| msg = Actor.receive master.send msg end actor.send "test" msg = Actor.receive # msg == "test" Monday 30 May 2011
  • 20. Revactor concurrent I/O for networking apps Evented rather than parallel https://github.com/tarcieri/revactor Monday 30 May 2011
  • 21. Celluloid thread-based actors based on erlang https://github.com/tarcieri/celluloid Monday 30 May 2011
  • 22. No true parallelism with MRI Monday 30 May 2011
  • 23. Cheat on Ruby Monday 30 May 2011
  • 24. Erlang light-weight processes = actors Monday 30 May 2011
  • 25. Erlang blocking receives timeouts supervision trees: fault-tolerance Monday 30 May 2011
  • 26. Erlectricity require 'rubygems' require 'erlectricity' receive do |f| f.when([:echo, String]) do |text| f.send!([:result, "You said: #{text}"]) f.receive_loop end end https://github.com/mojombo/erlectricity Monday 30 May 2011
  • 27. Reia or Elixir languages on erlang vm friendlier, more ruby-like, OO Monday 30 May 2011
  • 28. Scala “We also included enhancements to make it easier to call from Ruby into Scala libraries, which has enabled the Lift web framework to offer support for Ruby.” Charles Nutter, ‘JRuby 1.6 released, now what ?’ http://www.engineyard.com/blog/2011/jruby-1-6-released-now-what/ Actors in standard library Monday 30 May 2011
  • 29. Akka actor model + software transactional memory java and scala Monday 30 May 2011
  • 30. Akka • sending: reply is possible or not, sync or async • supervision: several strategies • as library or as framework • local and distributed Monday 30 May 2011
  • 33. Advantages easy to grasp real encapsulation - separation of concerns highly decentralized Monday 30 May 2011
  • 34. But many messages (bandwidth) livelocks are still possible Monday 30 May 2011
  • 35. Back to Ruby Monday 30 May 2011
  • 36. Time to control shared state ? Change RubySpec: default: variables not shared between threads? integrate better concurrency primitives into the Ruby stdlib ? Monday 30 May 2011
  • 37. Let’s think about it. Monday 30 May 2011
  • 38. Thanks @elise_huard http://www.delicious.com/elisehuard/concurrency Monday 30 May 2011
  • 39. Ruby goes to Hollywood Elise Huard LRUG 11-04-2011 Monday 30 May 2011
  • 40. Ruby goes to Hollywood Elise Huard LRUG Monday 30 May 2011