Introduction to Distributed Programming: The Ruby Way Auvi Rahman [email protected] Mutually Human Software, LLC 1 [bash-10.4 ~]$ ruby talk.rb Saturday, April 17, 2010
Introduction to Distributed Programming: The Ruby Way
Auvi [email protected]
Mutually Human Software, LLC
1
[bash-10.4 ~]$ ruby talk.rb
Saturday, April 17, 2010
[bash-10.4 ~]$ who am I
• Mechanical/Industrial Engineer by training
• Software developer by trade
• Human as a person
2
[bash-10.4 ~]$ who am I
Saturday, April 17, 2010
[bash-10.4 ~]$ whois mutuallyhuman.com
3
“Mutually Human Software is a custom software strategy and design consultancy specializing in mobile & web-based products and services.”
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’
6
“Distributed programming is like network programming—only the audience is different.”
- Lucas Carlson (Ruby Cookbook)
Saturday, April 17, 2010
7
[bash-10.4 ~]$ ri ‘distributed programming’
DRb Rinda rubyPVM MPI Ruby Starfish
SkyNet MRToolkit
Distribunaut
Politics
BackgrounDRbRabbitMQ
Starling
Delayed Job
MagLev
Erlectricity
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
9
Server Client
Saturday, April 17, 2010
Example method
10
def humanize(name) "#{name.capitalize} Human"end
humanize('auvi') # => "Auvi Human"
Saturday, April 17, 2010
server.rb
11
require 'drb'
class HumanServer def humanize(name) "#{name.capitalize} Human" endend
DRb.start_service("druby://127.0.0.1:48626", HumanServer.new)DRb.thread.join
Saturday, April 17, 2010
12
DRb.start_service("druby://127.0.0.1:48626", HumanServer.new)
Front object
Protocol IP address Port
Saturday, April 17, 2010
13
[bash-10.4 ~]$ ruby server.rb
Server
Saturday, April 17, 2010
client.rb
14
require 'drb'
server = DRbObject.new_with_uri("druby://127.0.0.1:48626")
puts server.humanize('auvi')
Saturday, April 17, 2010
15
Server Client
[bash-10.4 ~]$ ruby client.rb
Auvi Human[bash-10.4 ~]$
Saturday, April 17, 2010
server2.rb
16
require 'drb'
class Person attr_accessor :name def initialize(name) @name = name end
def humanize "#{@name.capitalize} Human" endend
class HumanServer def personify(name) Person.new(name) endend
DRb.start_service("druby://127.0.0.1:48626", HumanServer.new)DRb.thread.join
Saturday, April 17, 2010
17
[bash-10.4 ~]$ ruby server2.rb
Server
Saturday, April 17, 2010
client2.rb
18
require 'drb'
server = DRbObject.new_with_uri("druby://127.0.0.1:48626")p server
person = server.personify('auvi')p person
puts person.humanize
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="\004\bo:\vPerson\006:\n@name\"\tAuvi">client2.rb:9: undefined method `humanize' for #<DRb::DRbUnknown:0x1dc66c> (NoMethodError)
[bash-10.4 ~]$
Saturday, April 17, 2010
Solution?
20
include DRbUndumped
Saturday, April 17, 2010
server3.rb
21
require 'drb'
class Person include DRbUndumped attr_accessor :name def initialize(name) @name = name end
def humanize "#{@name.capitalize} Human" endend
class HumanServer def personify(name) Person.new(name) endend
DRb.start_service("druby://127.0.0.1:48626", HumanServer.new)DRb.thread.join
Saturday, April 17, 2010
22
[bash-10.4 ~]$ ruby server3.rb
Server
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 ~]$
Saturday, April 17, 2010
Pass by value24
Saturday, April 17, 2010
Pass by Reference25
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
Saturday, April 17, 2010
27
3-tier architecture
9
Service Client
RingServer
Saturday, April 17, 2010
A Ring Server?
28
Saturday, April 17, 2010
ringserver.rb
29
require 'rinda/ring'require 'rinda/tuplespace'
DRb.start_serviceRinda::RingServer.new(Rinda::TupleSpace.new)DRb.thread.join
Saturday, April 17, 2010
What is a TupleSpace?
30
Saturday, April 17, 2010
31
Saturday, April 17, 2010
3213
[bash-10.4 ~]$ ruby ringserver.rb
RingServer
Default port : 7647
Saturday, April 17, 2010
33
service.rb
require 'rinda/ring'
class HumanServer include DRbUndumped
def humanize(name) "#{name.capitalize} Human" endend
DRb.start_service
server = Rinda::RingFinger.primary
server.write([ :human_service, :HumanServer, HumanServer.new, 'Human Server'], Rinda::SimpleRenewer.new)
DRb.thread.join
Saturday, April 17, 2010
34
Rinda::RingFinger.primary
Saturday, April 17, 2010
Format of a Tuple
35
[:human_service, :HumanServer, HumanServer.new, 'Human Server']
Saturday, April 17, 2010
36
Saturday, April 17, 2010
373213
[bash-10.4 ~]$ ruby service.rb
Service
RingServer
Saturday, April 17, 2010
client.rb
38
require 'rinda/ring'
DRb.start_serviceserver = Rinda::RingFinger.primary
service = server.read([:human_service, nil, nil, nil])[2]
puts service.humanize('auvi')
Saturday, April 17, 2010
39
service = server.read([:human_service, nil, nil, nil])[2]
0 21 3
#<DRb::DRbObject>
Saturday, April 17, 2010
[bash-10.4 ~]$ ruby client.rbAuvi Human[bash-10.4 ~]$
40
Service Client
RingServer
1
2
4
3
Saturday, April 17, 2010
41
千里之行,始于足下“A journey of a thousand miles begins with a single step”
Saturday, April 17, 2010
42
Saturday, April 17, 2010
43
[bash-10.4 ~]$ cat distributed_programming.txt | grep ruby | less
DRb Rinda rubyPVM MPI Ruby Starfish
SkyNet MRToolkit
Distribunaut
Politics
BackgrounDRbRabbitMQ
Starling
Delayed Job
MagLev
Erlectricity
Saturday, April 17, 2010
[bash-10.4 ~]$ exit
44
logout[Process completed]
Saturday, April 17, 2010
Questions?
45
Saturday, April 17, 2010