SlideShare a Scribd company logo
1 of 30
Download to read offline
Ruby
                         goes to
                        Hollywood
                              @elise_huard LRUG
Tuesday 12 April 2011
Why Concurrency?



Tuesday 12 April 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)




Tuesday 12 April 2011
Concurrent programs
                                 !=
                         Parallel computing


Tuesday 12 April 2011
3 threads, 2 cores


                         1                    1       2




                         2                    3
                                                      1




                          3                   3
                                                      2




                          1




                        core1   core2         core1   core2

Tuesday 12 April 2011
Your program




                                   language VM



                                        OS
                        (kernel processes, other processes)


                             multicore - multiCPU


Tuesday 12 April 2011
Concurrency will melt
                      your brain

                        non-determinism
                        shared state



Tuesday 12 April 2011
Actor Model



Tuesday 12 April 2011
Hewitt et al. 1973
                        no shared state
                        in response to a message that it
                        receives, an actor can:
                        make local decisions
                        create more actors
                        send more messages
                        determine how to respond to the next message
                        received


Tuesday 12 April 2011
Inspiration
                        Artificial Intelligence
                        quantum mechanics - we cannot
                        observe the details by which the order
                        of arrival of messages for an actor is
                        determined. attempting to do so can
                        affect result and push indeterminacy
                        elsewhere.


Tuesday 12 April 2011
The point

                        only actors
                        no global state
                        partial order of execution


Tuesday 12 April 2011
Actors in Ruby



Tuesday 12 April 2011
definitely not parallel



Tuesday 12 April 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"




Tuesday 12 April 2011
Revactor
                  sock = Revactor::TCP.connect(host, port)
                listener = Revactor::TCP.listen(addr, port)
                sock = listener.accept

                sock.controller = Actor.current
                sock.active = true
                Actor.receive do |filter|
                  filter.when(Case[:tcp, sock, Object]) do |_, _, data|
                    ...
                  end
                  filter.when(Case[:somethingelse, Object]) do |_,
                message|
                    ...
                  end
                end


Tuesday 12 April 2011
Concurrent gem

                        theoretical - different concurrency
                        models
                        use rubinius style actors in other
                        versions of Ruby
                        https://github.com/mental/concurrent


Tuesday 12 April 2011
Meh.



Tuesday 12 April 2011
Cheat on Ruby



Tuesday 12 April 2011
Erlang


                        light-weight processes
                        = actors


Tuesday 12 April 2011
Erlectricity
                https://github.com/mojombo/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




Tuesday 12 April 2011
Erlectricity
                -module(echo).
                -export([test/0]).

                test() ->
                  Cmd = "ruby echo.rb",
                  Port = open_port({spawn, Cmd}, [{packet, 4},
                nouse_stdio, exit_status, binary]),
                  Payload = term_to_binary({echo, <<"hello world!">>}),
                  port_command(Port, Payload),
                  receive
                    {Port, {data, Data}} ->
                       {result, Text} = binary_to_term(Data),
                       io:format("~p~n", [Text])
                  end.



Tuesday 12 April 2011
BERT RPC

                        BERT (Binary ERlang Term) serialization library
                        for Ruby.
                        convert data into erlang binary format before
                        sending them over the wire




Tuesday 12 April 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


Tuesday 12 April 2011
Akka




                        https://github.com/danielribeiro/RubyOnAkka


Tuesday 12 April 2011
Back to Ruby



Tuesday 12 April 2011
Time to control
                            shared state ?

                        Change RubySpec ?
                        default variables: not shared between
                        threads
                        have keyword for shared variables



Tuesday 12 April 2011
Let’s think about it.



Tuesday 12 April 2011
Thanks
                         @elise_huard




Tuesday 12 April 2011
Ruby
                         goes to
                        Hollywood
                              Elise Huard LRUG 11-04-2011
Tuesday 12 April 2011
Ruby
                         goes to
                        Hollywood
                               Elise Huard LRUG
Tuesday 12 April 2011

More Related Content

Similar to Ruby hollywood

A Tour Through the Groovy Ecosystem
A Tour Through the Groovy EcosystemA Tour Through the Groovy Ecosystem
A Tour Through the Groovy EcosystemLeonard Axelsson
 
HootSuite Dev 2
HootSuite Dev 2HootSuite Dev 2
HootSuite Dev 2ujihisa
 
The Fast, The Slow and the Lazy
The Fast, The Slow and the LazyThe Fast, The Slow and the Lazy
The Fast, The Slow and the LazyMaurício Linhares
 
Carton CPAN dependency manager
Carton CPAN dependency managerCarton CPAN dependency manager
Carton CPAN dependency managerTatsuhiko Miyagawa
 
Node js techtalksto
Node js techtalkstoNode js techtalksto
Node js techtalkstoJason Diller
 
Conquistando el Servidor con Node.JS
Conquistando el Servidor con Node.JSConquistando el Servidor con Node.JS
Conquistando el Servidor con Node.JSCaridy Patino
 
node.js for front-end developers
node.js for front-end developersnode.js for front-end developers
node.js for front-end developersGarann Means
 
JS Tooling in Rails 3.1
JS Tooling in Rails 3.1JS Tooling in Rails 3.1
JS Tooling in Rails 3.1Duda Dornelles
 
Erlang: Bult for concurrent, distributed systems
Erlang: Bult for concurrent, distributed systemsErlang: Bult for concurrent, distributed systems
Erlang: Bult for concurrent, distributed systemsKen Pratt
 
TorqueBox - Ultrapassando a fronteira entre Java e Ruby
TorqueBox - Ultrapassando a fronteira entre Java e RubyTorqueBox - Ultrapassando a fronteira entre Java e Ruby
TorqueBox - Ultrapassando a fronteira entre Java e RubyBruno Oliveira
 
Using Java from Ruby with JRuby IRB
Using Java from Ruby with JRuby IRBUsing Java from Ruby with JRuby IRB
Using Java from Ruby with JRuby IRBHiro Asari
 
Lightning talks percona live mysql_2012
Lightning talks percona live mysql_2012Lightning talks percona live mysql_2012
Lightning talks percona live mysql_2012Giuseppe Maxia
 
Behat dpc12
Behat dpc12Behat dpc12
Behat dpc12benwaine
 
Introduction to JavaScriptMVC
Introduction to JavaScriptMVCIntroduction to JavaScriptMVC
Introduction to JavaScriptMVCPedro Pimentel
 
international PHP2011_ilia alshanetsky_Hidden Features of PHP
international PHP2011_ilia alshanetsky_Hidden Features of PHPinternational PHP2011_ilia alshanetsky_Hidden Features of PHP
international PHP2011_ilia alshanetsky_Hidden Features of PHPsmueller_sandsmedia
 
DevOps Introduction @Cegeka
DevOps Introduction @CegekaDevOps Introduction @Cegeka
DevOps Introduction @Cegekadieterdm
 

Similar to Ruby hollywood (20)

A Tour Through the Groovy Ecosystem
A Tour Through the Groovy EcosystemA Tour Through the Groovy Ecosystem
A Tour Through the Groovy Ecosystem
 
HootSuite Dev 2
HootSuite Dev 2HootSuite Dev 2
HootSuite Dev 2
 
The Fast, The Slow and the Lazy
The Fast, The Slow and the LazyThe Fast, The Slow and the Lazy
The Fast, The Slow and the Lazy
 
Carton CPAN dependency manager
Carton CPAN dependency managerCarton CPAN dependency manager
Carton CPAN dependency manager
 
CommonJS Frameworks
CommonJS FrameworksCommonJS Frameworks
CommonJS Frameworks
 
Node js techtalksto
Node js techtalkstoNode js techtalksto
Node js techtalksto
 
Caridy patino - node-js
Caridy patino - node-jsCaridy patino - node-js
Caridy patino - node-js
 
Conquistando el Servidor con Node.JS
Conquistando el Servidor con Node.JSConquistando el Servidor con Node.JS
Conquistando el Servidor con Node.JS
 
node.js for front-end developers
node.js for front-end developersnode.js for front-end developers
node.js for front-end developers
 
JS Tooling in Rails 3.1
JS Tooling in Rails 3.1JS Tooling in Rails 3.1
JS Tooling in Rails 3.1
 
Erlang: Bult for concurrent, distributed systems
Erlang: Bult for concurrent, distributed systemsErlang: Bult for concurrent, distributed systems
Erlang: Bult for concurrent, distributed systems
 
TorqueBox - Ultrapassando a fronteira entre Java e Ruby
TorqueBox - Ultrapassando a fronteira entre Java e RubyTorqueBox - Ultrapassando a fronteira entre Java e Ruby
TorqueBox - Ultrapassando a fronteira entre Java e Ruby
 
Using Java from Ruby with JRuby IRB
Using Java from Ruby with JRuby IRBUsing Java from Ruby with JRuby IRB
Using Java from Ruby with JRuby IRB
 
Lightning talks percona live mysql_2012
Lightning talks percona live mysql_2012Lightning talks percona live mysql_2012
Lightning talks percona live mysql_2012
 
Behat dpc12
Behat dpc12Behat dpc12
Behat dpc12
 
Introduction to JavaScriptMVC
Introduction to JavaScriptMVCIntroduction to JavaScriptMVC
Introduction to JavaScriptMVC
 
RunDeck
RunDeckRunDeck
RunDeck
 
Groke
GrokeGroke
Groke
 
international PHP2011_ilia alshanetsky_Hidden Features of PHP
international PHP2011_ilia alshanetsky_Hidden Features of PHPinternational PHP2011_ilia alshanetsky_Hidden Features of PHP
international PHP2011_ilia alshanetsky_Hidden Features of PHP
 
DevOps Introduction @Cegeka
DevOps Introduction @CegekaDevOps Introduction @Cegeka
DevOps Introduction @Cegeka
 

More from ehuard

Euroclojure 2017
Euroclojure 2017Euroclojure 2017
Euroclojure 2017ehuard
 
Ruby goes to Hollywood
Ruby goes to HollywoodRuby goes to Hollywood
Ruby goes to Hollywoodehuard
 
Concurrency: Rubies, plural
Concurrency: Rubies, pluralConcurrency: Rubies, plural
Concurrency: Rubies, pluralehuard
 
Concurrency
ConcurrencyConcurrency
Concurrencyehuard
 
Concurrency
ConcurrencyConcurrency
Concurrencyehuard
 
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 applicationehuard
 
Barcamp Ghent2009
Barcamp Ghent2009Barcamp Ghent2009
Barcamp Ghent2009ehuard
 
Tokyo Cabinet
Tokyo CabinetTokyo Cabinet
Tokyo Cabinetehuard
 
The real-time web
The real-time webThe real-time web
The real-time webehuard
 
Rails and the internet of things
Rails and the internet of thingsRails and the internet of things
Rails and the internet of thingsehuard
 

More from ehuard (11)

Euroclojure 2017
Euroclojure 2017Euroclojure 2017
Euroclojure 2017
 
Ruby goes to Hollywood
Ruby goes to HollywoodRuby goes to Hollywood
Ruby goes to Hollywood
 
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
 
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
 

Ruby hollywood

  • 1. Ruby goes to Hollywood @elise_huard LRUG Tuesday 12 April 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) Tuesday 12 April 2011
  • 4. Concurrent programs != Parallel computing Tuesday 12 April 2011
  • 5. 3 threads, 2 cores 1 1 2 2 3 1 3 3 2 1 core1 core2 core1 core2 Tuesday 12 April 2011
  • 6. Your program language VM OS (kernel processes, other processes) multicore - multiCPU Tuesday 12 April 2011
  • 7. Concurrency will melt your brain non-determinism shared state Tuesday 12 April 2011
  • 9. Hewitt et al. 1973 no shared state in response to a message that it receives, an actor can: make local decisions create more actors send more messages determine how to respond to the next message received Tuesday 12 April 2011
  • 10. Inspiration Artificial Intelligence quantum mechanics - we cannot observe the details by which the order of arrival of messages for an actor is determined. attempting to do so can affect result and push indeterminacy elsewhere. Tuesday 12 April 2011
  • 11. The point only actors no global state partial order of execution Tuesday 12 April 2011
  • 12. Actors in Ruby Tuesday 12 April 2011
  • 14. 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" Tuesday 12 April 2011
  • 15. Revactor sock = Revactor::TCP.connect(host, port) listener = Revactor::TCP.listen(addr, port) sock = listener.accept sock.controller = Actor.current sock.active = true Actor.receive do |filter| filter.when(Case[:tcp, sock, Object]) do |_, _, data| ... end filter.when(Case[:somethingelse, Object]) do |_, message| ... end end Tuesday 12 April 2011
  • 16. Concurrent gem theoretical - different concurrency models use rubinius style actors in other versions of Ruby https://github.com/mental/concurrent Tuesday 12 April 2011
  • 18. Cheat on Ruby Tuesday 12 April 2011
  • 19. Erlang light-weight processes = actors Tuesday 12 April 2011
  • 20. Erlectricity https://github.com/mojombo/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 Tuesday 12 April 2011
  • 21. Erlectricity -module(echo). -export([test/0]). test() -> Cmd = "ruby echo.rb", Port = open_port({spawn, Cmd}, [{packet, 4}, nouse_stdio, exit_status, binary]), Payload = term_to_binary({echo, <<"hello world!">>}), port_command(Port, Payload), receive {Port, {data, Data}} -> {result, Text} = binary_to_term(Data), io:format("~p~n", [Text]) end. Tuesday 12 April 2011
  • 22. BERT RPC BERT (Binary ERlang Term) serialization library for Ruby. convert data into erlang binary format before sending them over the wire Tuesday 12 April 2011
  • 23. 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 Tuesday 12 April 2011
  • 24. Akka https://github.com/danielribeiro/RubyOnAkka Tuesday 12 April 2011
  • 25. Back to Ruby Tuesday 12 April 2011
  • 26. Time to control shared state ? Change RubySpec ? default variables: not shared between threads have keyword for shared variables Tuesday 12 April 2011
  • 27. Let’s think about it. Tuesday 12 April 2011
  • 28. Thanks @elise_huard Tuesday 12 April 2011
  • 29. Ruby goes to Hollywood Elise Huard LRUG 11-04-2011 Tuesday 12 April 2011
  • 30. Ruby goes to Hollywood Elise Huard LRUG Tuesday 12 April 2011