SlideShare a Scribd company logo
1 of 41
Download to read offline
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

Similar to Ruby goes to hollywood

NodeJS, CoffeeScript & Real-time Web
NodeJS, CoffeeScript & Real-time WebNodeJS, CoffeeScript & Real-time Web
NodeJS, CoffeeScript & Real-time Web
Jakub Nesetril
 
Scaling websites with RabbitMQ A(rlvaro Videla)
Scaling websites with RabbitMQ   A(rlvaro Videla)Scaling websites with RabbitMQ   A(rlvaro Videla)
Scaling websites with RabbitMQ A(rlvaro Videla)
Ontico
 

Similar to Ruby goes to hollywood (11)

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

More from ehuard

Concurrency
ConcurrencyConcurrency
Concurrency
ehuard
 

More from ehuard (14)

Euroclojure 2017
Euroclojure 2017Euroclojure 2017
Euroclojure 2017
 
Ruby goes to Hollywood
Ruby goes to HollywoodRuby goes to Hollywood
Ruby goes to Hollywood
 
Ruby hollywood nordic
Ruby hollywood nordicRuby hollywood nordic
Ruby hollywood nordic
 
Concurrency: Rubies, plural
Concurrency: Rubies, pluralConcurrency: Rubies, plural
Concurrency: Rubies, plural
 
Concurrency
ConcurrencyConcurrency
Concurrency
 
Concurrency
ConcurrencyConcurrency
Concurrency
 
12 hours to rate a rails application
12 hours to rate a rails application12 hours to rate a rails application
12 hours to rate a rails application
 
how to rate a Rails application
how to rate a Rails applicationhow to rate a Rails application
how to rate a Rails application
 
12 Hours To Rate A Rails Application
12 Hours To Rate A Rails Application12 Hours To Rate A Rails Application
12 Hours To Rate A Rails Application
 
Barcamp Ghent2009
Barcamp Ghent2009Barcamp Ghent2009
Barcamp Ghent2009
 
Tokyo Cabinet
Tokyo CabinetTokyo Cabinet
Tokyo Cabinet
 
The real-time web
The real-time webThe real-time web
The real-time web
 
Rails and the internet of things
Rails and the internet of thingsRails and the internet of things
Rails and the internet of things
 
Oauth
OauthOauth
Oauth
 

Recently uploaded

IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI Solutions
Enterprise Knowledge
 
CNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of ServiceCNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of Service
giselly40
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slide
vu2urc
 

Recently uploaded (20)

08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdf
 
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
 
GenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdfGenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdf
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI Solutions
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024
 
Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024
 
presentation ICT roal in 21st century education
presentation ICT roal in 21st century educationpresentation ICT roal in 21st century education
presentation ICT roal in 21st century education
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonets
 
Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)
 
CNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of ServiceCNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of Service
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivity
 
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
 
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slide
 
What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?
 

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