Glrb2010 auvi
Upcoming SlideShare
Loading in...5
×

Like this? Share it with your network

Share
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Be the first to comment
    Be the first to like this
No Downloads

Views

Total Views
1,064
On Slideshare
1,064
From Embeds
0
Number of Embeds
0

Actions

Shares
Downloads
8
Comments
0
Likes
0

Embeds 0

No embeds

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
    No notes for slide

Transcript

  • 1. [bash-10.4 ~]$ ruby talk.rb Introduction to Distributed Programming: The Ruby Way Auvi Rahman auvi@mutuallyhuman.com Mutually Human Software, LLC 1 Saturday, April 17, 2010
  • 2. [bash-10.4 ~]$ who am I • Mechanical/Industrial Engineer by training • Software developer by trade • Human as a person 2 Saturday, April 17, 2010
  • 3. [bash-10.4 ~]$ whois mutuallyhuman.com “Mutually Human Software is a custom software strategy and design consultancy specializing in mobile & web-based products and services.” 3 Saturday, April 17, 2010
  • 4. [bash-10.4 ~]$ cat .relevant_history • Parallel Fluid dynamics simulation (C++/MPI) • Distributed Analog Computing • Distributed control systems (Robotics) • Distributed Discrete-Event Simulation 4 Saturday, April 17, 2010
  • 5. [bash-10.4 ~]$ atq • Distributed programming and Ruby • DRb • Rinda • Others 5 Saturday, April 17, 2010
  • 6. [bash-10.4 ~]$ whatis ‘distributed programming’ “Distributed programming is like network programming—only the audience is different.” - Lucas Carlson (Ruby Cookbook) 6 Saturday, April 17, 2010
  • 7. [bash-10.4 ~]$ ri ‘distributed programming’ DRb Rinda rubyPVM MPI Ruby Starfish SkyNet MRToolkit MagLev Politics Starling Delayed RabbitMQ Distribunaut Erlectricity BackgrounDRb Job 7 Saturday, April 17, 2010
  • 8. [bash-10.4 ~]$ cd DRb • Distributed Ruby • Also known as dRuby • Part of the standard library • 100% Ruby • Easy to use • Universally available where Ruby is installed 8 Saturday, April 17, 2010
  • 9. 2-tier architecture Server Client 9 Saturday, April 17, 2010
  • 10. Example method def humanize(name) "#{name.capitalize} Human" end humanize('auvi') # => "Auvi Human" 10 Saturday, April 17, 2010
  • 11. server.rb require 'drb' class HumanServer def humanize(name) "#{name.capitalize} Human" end end DRb.start_service("druby://127.0.0.1:48626", HumanServer.new) DRb.thread.join 11 Saturday, April 17, 2010
  • 12. Protocol IP address Port DRb.start_service("druby://127.0.0.1:48626", HumanServer.new) Front object 12 Saturday, April 17, 2010
  • 13. [bash-10.4 ~]$ ruby server.rb Server 13 Saturday, April 17, 2010
  • 14. client.rb require 'drb' server = DRbObject.new_with_uri("druby://127.0.0.1:48626") puts server.humanize('auvi') 14 Saturday, April 17, 2010
  • 15. [bash-10.4 ~]$ ruby client.rb Auvi Human [bash-10.4 ~]$ Server Client 15 Saturday, April 17, 2010
  • 16. server2.rb require 'drb' class Person attr_accessor :name def initialize(name) @name = name end def humanize "#{@name.capitalize} Human" end end class HumanServer def personify(name) Person.new(name) end end DRb.start_service("druby://127.0.0.1:48626", HumanServer.new) DRb.thread.join 16 Saturday, April 17, 2010
  • 17. [bash-10.4 ~]$ ruby server2.rb Server 17 Saturday, April 17, 2010
  • 18. client2.rb require 'drb' server = DRbObject.new_with_uri("druby://127.0.0.1:48626") p server person = server.personify('auvi') p person puts person.humanize 18 Saturday, April 17, 2010
  • 19. [bash-10.4 ~]$ ruby client2.rb #<DRb::DRbObject:0x959c @ref=nil, @uri="druby://127.0.0.1:48626"> #<DRb::DRbUnknown:0x1dc66c @name="Person", @buf="004bo:vPerson006:n@name"tAuvi"> client2.rb:9: undefined method `humanize' for #<DRb::DRbUnknown:0x1dc66c> (NoMethodError) [bash-10.4 ~]$ 19 Saturday, April 17, 2010
  • 20. Solution? include DRbUndumped 20 Saturday, April 17, 2010
  • 21. server3.rb require 'drb' class Person include DRbUndumped attr_accessor :name def initialize(name) @name = name end def humanize "#{@name.capitalize} Human" end end class HumanServer def personify(name) Person.new(name) end end DRb.start_service("druby://127.0.0.1:48626", HumanServer.new) DRb.thread.join 21 Saturday, April 17, 2010
  • 22. [bash-10.4 ~]$ ruby server3.rb Server 22 Saturday, April 17, 2010
  • 23. [bash-10.4 ~]$ ruby client2.rb #<DRb::DRbObject:0x959c @ref=nil, @uri="druby://127.0.0.1:48626"> #<DRb::DRbObject:0x1dc734 @ref=974550, @uri="druby://127.0.0.1:48626"> Auvi Human [bash-10.4 ~]$ 23 Saturday, April 17, 2010
  • 24. Pass by value 24 Saturday, April 17, 2010
  • 25. Pass by Reference 25 Saturday, April 17, 2010
  • 26. [bash-10.4 ~]$ cd Rinda • Implements the Linda distributed computing paradigm • Also part of the standard library • 100% Ruby • Universally available where Ruby is installed 26 Saturday, April 17, 2010
  • 27. 3-tier architecture RingServer Service Client 27 9 Saturday, April 17, 2010
  • 28. A Ring Server? 28 Saturday, April 17, 2010
  • 29. ringserver.rb require 'rinda/ring' require 'rinda/tuplespace' DRb.start_service Rinda::RingServer.new(Rinda::TupleSpace.new) DRb.thread.join 29 Saturday, April 17, 2010
  • 30. What is a TupleSpace? 30 Saturday, April 17, 2010
  • 31. 31 Saturday, April 17, 2010
  • 32. [bash-10.4 ~]$ ruby ringserver.rb RingServer Default port : 7647 13 32 Saturday, April 17, 2010
  • 33. service.rb require 'rinda/ring' class HumanServer include DRbUndumped def humanize(name) "#{name.capitalize} Human" end end DRb.start_service server = Rinda::RingFinger.primary server.write([ :human_service, :HumanServer, HumanServer.new, 'Human Server'], Rinda::SimpleRenewer.new) DRb.thread.join 33 Saturday, April 17, 2010
  • 34. Rinda::RingFinger.primary 34 Saturday, April 17, 2010
  • 35. Format of a Tuple [:human_service, :HumanServer, HumanServer.new, 'Human Server'] 35 Saturday, April 17, 2010
  • 36. 36 Saturday, April 17, 2010
  • 37. [bash-10.4 ~]$ ruby service.rb RingServer Service 13 32 37 Saturday, April 17, 2010
  • 38. client.rb require 'rinda/ring' DRb.start_service server = Rinda::RingFinger.primary service = server.read([:human_service, nil, nil, nil])[2] puts service.humanize('auvi') 38 Saturday, April 17, 2010
  • 39. #<DRb::DRbObject> service = server.read([:human_service, nil, nil, nil])[2] 0 1 2 3 39 Saturday, April 17, 2010
  • 40. [bash-10.4 ~]$ ruby client.rb Auvi Human [bash-10.4 ~]$ RingServer 1 2 3 Service Client 4 40 Saturday, April 17, 2010
  • 41. “A journey of a thousand miles begins with a single step” 41 Saturday, April 17, 2010
  • 42. 42 Saturday, April 17, 2010
  • 43. [bash-10.4 ~]$ cat distributed_programming.txt | grep ruby | less DRb Rinda rubyPVM MPI Ruby Starfish SkyNet MRToolkit MagLev Politics Starling Delayed RabbitMQ Distribunaut Erlectricity BackgrounDRb Job 43 Saturday, April 17, 2010
  • 44. [bash-10.4 ~]$ exit logout [Process completed] 44 Saturday, April 17, 2010
  • 45. Questions? 45 Saturday, April 17, 2010