SlideShare a Scribd company logo
1 of 45
Download to read offline
[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
[bash-10.4 ~]$ who am I


                      • Mechanical/Industrial Engineer by training
                      • Software developer by trade
                      • Human as a person

                                            2
Saturday, April 17, 2010
[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
[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
[bash-10.4 ~]$ atq

                    • Distributed programming and Ruby
                    • DRb
                    • Rinda
                    • Others


                                        5
Saturday, April 17, 2010
[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
[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
[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
2-tier architecture


                           Server           Client




                                    9
Saturday, April 17, 2010
Example method

                           def humanize(name)
                             "#{name.capitalize} Human"
                           end

                           humanize('auvi') # => "Auvi Human"




                                           10
Saturday, April 17, 2010
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
Protocol   IP address       Port


           DRb.start_service("druby://127.0.0.1:48626", HumanServer.new)




                                                               Front
                                                               object



                                           12
Saturday, April 17, 2010
[bash-10.4 ~]$ ruby server.rb



                           Server




                                    13
Saturday, April 17, 2010
client.rb




             require 'drb'

             server = DRbObject.new_with_uri("druby://127.0.0.1:48626")

             puts server.humanize('auvi')




                                            14
Saturday, April 17, 2010
[bash-10.4 ~]$ ruby client.rb
   Auvi Human
   [bash-10.4 ~]$



                           Server        Client




                                    15
Saturday, April 17, 2010
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
[bash-10.4 ~]$ ruby server2.rb



                           Server




                                    17
Saturday, April 17, 2010
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
[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
Solution?


          include DRbUndumped



                               20
Saturday, April 17, 2010
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
[bash-10.4 ~]$ ruby server3.rb



                           Server




                                    22
Saturday, April 17, 2010
[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
Pass by value
                                24
Saturday, April 17, 2010
Pass by Reference
                                   25
Saturday, April 17, 2010
[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
3-tier architecture
                                     RingServer




                           Service                Client




                                         27
                                          9
Saturday, April 17, 2010
A Ring Server?



                                 28
Saturday, April 17, 2010
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
What is a TupleSpace?




                                     30
Saturday, April 17, 2010
31
Saturday, April 17, 2010
[bash-10.4 ~]$ ruby ringserver.rb



                                RingServer




                           Default port : 7647


                                    13
                                    32
Saturday, April 17, 2010
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
Rinda::RingFinger.primary




                           34
Saturday, April 17, 2010
Format of a Tuple

                           [:human_service,
                            :HumanServer,
                            HumanServer.new,
                            'Human Server']




                                   35
Saturday, April 17, 2010
36
Saturday, April 17, 2010
[bash-10.4 ~]$ ruby service.rb


                                     RingServer




                           Service




                                         13
                                         32
                                         37
Saturday, April 17, 2010
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
#<DRb::DRbObject>



                 service = server.read([:human_service, nil, nil, nil])[2]

                                             0          1     2    3




                                            39
Saturday, April 17, 2010
[bash-10.4 ~]$ ruby client.rb
                 Auvi Human
                 [bash-10.4 ~]$


                                     RingServer
                                                      1
                                                  2


                                         3
                           Service                        Client
                                         4



                                         40
Saturday, April 17, 2010
“A journey of a thousand miles begins with a single step”




                              41
Saturday, April 17, 2010
42
Saturday, April 17, 2010
[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
[bash-10.4 ~]$ exit


                  logout
                  [Process completed]

                           44
Saturday, April 17, 2010
Questions?



                               45
Saturday, April 17, 2010

More Related Content

What's hot (7)

Practical ngx_mruby
Practical ngx_mrubyPractical ngx_mruby
Practical ngx_mruby
 
Middleware as Code with mruby
Middleware as Code with mrubyMiddleware as Code with mruby
Middleware as Code with mruby
 
Groovy.pptx
Groovy.pptxGroovy.pptx
Groovy.pptx
 
CouchDB in The Room
CouchDB in The RoomCouchDB in The Room
CouchDB in The Room
 
RubyGems 3 & 4
RubyGems 3 & 4RubyGems 3 & 4
RubyGems 3 & 4
 
IJTC%202009%20JRuby
IJTC%202009%20JRubyIJTC%202009%20JRuby
IJTC%202009%20JRuby
 
Sphinx autodoc - automated api documentation - PyCon.KR 2015
Sphinx autodoc - automated api documentation - PyCon.KR 2015Sphinx autodoc - automated api documentation - PyCon.KR 2015
Sphinx autodoc - automated api documentation - PyCon.KR 2015
 

Viewers also liked (7)

ICD- 10 is coming -Brenda Edwards
ICD- 10 is coming -Brenda EdwardsICD- 10 is coming -Brenda Edwards
ICD- 10 is coming -Brenda Edwards
 
Lawrence mm june 2011
Lawrence mm june 2011Lawrence mm june 2011
Lawrence mm june 2011
 
Medical identity theft handout june 2011
Medical identity theft handout june 2011Medical identity theft handout june 2011
Medical identity theft handout june 2011
 
Social networking fraud handout june 2011
Social networking fraud handout june 2011Social networking fraud handout june 2011
Social networking fraud handout june 2011
 
Jeff lanza id theft handout business march 2011
Jeff lanza id theft handout business march 2011Jeff lanza id theft handout business march 2011
Jeff lanza id theft handout business march 2011
 
Polozhenie o konkurse__moya_malaya_rodina
Polozhenie o konkurse__moya_malaya_rodinaPolozhenie o konkurse__moya_malaya_rodina
Polozhenie o konkurse__moya_malaya_rodina
 
Social networking fraud handout june 2011
Social networking fraud handout june 2011Social networking fraud handout june 2011
Social networking fraud handout june 2011
 

Similar to Glrb2010 auvi

CouchDB: A NoSQL database
CouchDB: A NoSQL databaseCouchDB: A NoSQL database
CouchDB: A NoSQL database
Rubyc Slides
 
Picking gem ruby for penetration testers
Picking gem ruby for penetration testersPicking gem ruby for penetration testers
Picking gem ruby for penetration testers
Paolo Perego
 
Distributed Ruby and Rails
Distributed Ruby and RailsDistributed Ruby and Rails
Distributed Ruby and Rails
Wen-Tien Chang
 

Similar to Glrb2010 auvi (12)

Node.js and Ruby
Node.js and RubyNode.js and Ruby
Node.js and Ruby
 
Ruby on CouchDB - SimplyStored and RockingChair
Ruby on CouchDB - SimplyStored and RockingChairRuby on CouchDB - SimplyStored and RockingChair
Ruby on CouchDB - SimplyStored and RockingChair
 
Node.js - A Quick Tour II
Node.js - A Quick Tour IINode.js - A Quick Tour II
Node.js - A Quick Tour II
 
CouchDB: A NoSQL database
CouchDB: A NoSQL databaseCouchDB: A NoSQL database
CouchDB: A NoSQL database
 
Rails ORM De-mystifying Active Record has_many
Rails ORM De-mystifying Active Record has_manyRails ORM De-mystifying Active Record has_many
Rails ORM De-mystifying Active Record has_many
 
TorqueBox: The beauty of Ruby with the power of JBoss. Presented at Devnexus...
TorqueBox: The beauty of Ruby with the power of JBoss.  Presented at Devnexus...TorqueBox: The beauty of Ruby with the power of JBoss.  Presented at Devnexus...
TorqueBox: The beauty of Ruby with the power of JBoss. Presented at Devnexus...
 
Why Ruby?
Why Ruby? Why Ruby?
Why Ruby?
 
Opening up the Social Web - Standards that are bridging the Islands
Opening up the Social Web - Standards that are bridging the Islands Opening up the Social Web - Standards that are bridging the Islands
Opening up the Social Web - Standards that are bridging the Islands
 
Ruby for Java Developers
Ruby for Java DevelopersRuby for Java Developers
Ruby for Java Developers
 
Picking gem ruby for penetration testers
Picking gem ruby for penetration testersPicking gem ruby for penetration testers
Picking gem ruby for penetration testers
 
The secret of programming language development and future
The secret of programming  language development and futureThe secret of programming  language development and future
The secret of programming language development and future
 
Distributed Ruby and Rails
Distributed Ruby and RailsDistributed Ruby and Rails
Distributed Ruby and Rails
 

Glrb2010 auvi

  • 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
  • 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
  • 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
  • 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