Ruby hollywood

1,646 views

Published on

0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total views
1,646
On SlideShare
0
From Embeds
0
Number of Embeds
3
Actions
Shares
0
Downloads
11
Comments
0
Likes
0
Embeds 0
No embeds

No notes for slide

Ruby hollywood

  1. 1. Ruby goes to Hollywood @elise_huard LRUGTuesday 12 April 2011
  2. 2. Why Concurrency?Tuesday 12 April 2011
  3. 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. 4. Concurrent programs != Parallel computingTuesday 12 April 2011
  5. 5. 3 threads, 2 cores 1 1 2 2 3 1 3 3 2 1 core1 core2 core1 core2Tuesday 12 April 2011
  6. 6. Your program language VM OS (kernel processes, other processes) multicore - multiCPUTuesday 12 April 2011
  7. 7. Concurrency will melt your brain non-determinism shared stateTuesday 12 April 2011
  8. 8. Actor ModelTuesday 12 April 2011
  9. 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 receivedTuesday 12 April 2011
  10. 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. 11. The point only actors no global state partial order of executionTuesday 12 April 2011
  12. 12. Actors in RubyTuesday 12 April 2011
  13. 13. definitely not parallelTuesday 12 April 2011
  14. 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. 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 endTuesday 12 April 2011
  16. 16. Concurrent gem theoretical - different concurrency models use rubinius style actors in other versions of Ruby https://github.com/mental/concurrentTuesday 12 April 2011
  17. 17. Meh.Tuesday 12 April 2011
  18. 18. Cheat on RubyTuesday 12 April 2011
  19. 19. Erlang light-weight processes = actorsTuesday 12 April 2011
  20. 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 endTuesday 12 April 2011
  21. 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. 22. BERT RPC BERT (Binary ERlang Term) serialization library for Ruby. convert data into erlang binary format before sending them over the wireTuesday 12 April 2011
  23. 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 libraryTuesday 12 April 2011
  24. 24. Akka https://github.com/danielribeiro/RubyOnAkkaTuesday 12 April 2011
  25. 25. Back to RubyTuesday 12 April 2011
  26. 26. Time to control shared state ? Change RubySpec ? default variables: not shared between threads have keyword for shared variablesTuesday 12 April 2011
  27. 27. Let’s think about it.Tuesday 12 April 2011
  28. 28. Thanks @elise_huardTuesday 12 April 2011
  29. 29. Ruby goes to Hollywood Elise Huard LRUG 11-04-2011Tuesday 12 April 2011
  30. 30. Ruby goes to Hollywood Elise Huard LRUGTuesday 12 April 2011

×