SlideShare ist ein Scribd-Unternehmen logo
1 von 44
Distributed Ruby
   An Introduction and Overview
Eric Hodel - drbrain@segment7.net
      http://blog.segment7.net
What is DRb?

• Remote Method Invocation for Ruby
• Peer to peer
 • Client and server
• Multiplatform
• Multiprotocol
• More...
Why Do I Need DRb?

• Parallelism
• Distribute work
• Interprocess communication
• Monitoring
Example
# Server
require ‘drb’
here = 'druby://127.0.0.1:10000'
DRb.start_service here, [1, 2, ‘III’, 4, ‘five’, 6]
DRb.thread.join

# Client
require ‘drb’

there = 'druby://127.0.0.1:10000'
DRb.start_service
ro = DRbObject.new nil, there

p ro.size
a = ro.collect { |x| x + x }
pa
Example Server
require ‘drb’ # load DRb

here = ‘druby://127.0.0.1:10000’ # server URI

# start DRb
DRb.start_service here, # our local URI
                  [1, 2, ‘III’, 4, ‘five’, 6]
                  # our front object

DRb.thread.join # wait until DRb is done
Front Object

• Optional
• Default object
• Passed by reference
 • Only one copy
Example Client
require ‘drb’ # load DRb
                                        How does it
                                           work?
there = ‘druby://127.0.0.1:10000’ #   remote server   URI

DRb.start_service # start local DRb server

                         Can’t dump
ro = DRbObject.new_with_uri there # connect to the server
                              code!
#   work with the remote object
p   ro.size
a   = ro.collect { |x| x + x }
p   a
ro.collect { |x| x + x }
    Server               Client

  [1, 2, 'III',
                    #<DRb::DRbObject>
  4, 'five', 6]



#<DRb::DRbObject>     { |x| x + x }
ro.collect { |x| x + x }
Server                                                         Client
Array                                                     Array DRbObject




                                     size



                                    collect


                       Client                    Client
                  Block DRbObject                Block


         call 1
                                     call 1
         call 2
                                     call 2
         call 'III'
                                    call 'III'
DRbObject
• Proxy object
• Contains URI and reference
 • Which server
 • What object
• Be aware of garbage collection
 • May be collected on server
 • Usually doesn't matter
DRbObject
                                druby://127.0.0.1:10000


         DRbObject
                                          'Hello'
uri   druby://127.0.0.1:10000
                                         0x29587e
ref          0x29587e


         DRbObject
                                      [1, 2, 'III']
uri   druby://127.0.0.1:10000
                                         0x28c7fc
ref          0x28c7f6
Id Conversion

• Converts reference into object on server
 • DRbIdConv	 Default
   • object_id & ObjectSpace._id2ref
• Alternates:
 • TimerIdConv	 Keep alive
 • NamedIdConv	 Reference by name
 • GWIdConv	 Protocol gateway
TimerIdConv
require 'drb'
require 'drb/timeridconv'

id_conv = DRb::TimerIdConv.new 30

DRb.default_id_conv = id_conv

DRb.start_service

# ...
NamedIdConv

• Found in sample/drb/name.rb
• Persistent objects
 • You must store your state
• Good example id converter
Remote Method Invocation
 • Client
  • Marshal method arguments
  • Send message to server
    • Reference, method name, arguments
 • Server
  • Receive message
  • Unmarshal arguments
  • Find local object from reference
  • Invoke method with arguments
DRbUndumped
• Default DRb operation
 • Pass by value
 • Must share code
• With DRbUndumped
 • Pass by reference
 • No need to share code
Automatic DRbObjects
• Module and Class
• IO
 • File, TCPSocket, UNIXSocket, etc.
• Blocks, Procs, Methods
• Thread, ThreadGroup
• Dir, File::Stat, Binding, Continuation
Using DRbUndumped
require ‘drb’

class X
  include DRb::DRbUndumped

  # ...
end

object = [1, 2, ‘III’, 4, ‘five’]
object.extend DRb::DRbUndumped
Why Use DRbUndumped?

 • Big objects
 • Singleton objects
 • Lightweight clients
 • Rapidly changing software
Connection Types


• TCP Sockets
• UNIX Sockets
• SSL Sockets
UNIX Socket Server

require ‘drb’
require ‘drb/unix’

here = 'drbunix://tmp/darray.sock'

DRb.start_service here, [1, 2, quot;IIIquot;, 4, quot;fivequot;, 6]

DRb.thread.join
UNIX Socket Client
require ‘drb’
require ‘drb/unix’

there = 'drbunix://tmp/darray.sock'

DRb.start_service

ro = DRbObject.new nil, there

p ro.size
a = ro.collect { |x| x + x }
pa
SSL Socket Server
require ‘drb’
require ‘drb/ssl’

here = ‘drbssl://127.0.0.1:10000’
config = {}
config[:SSLPrivateKey] = OpenSSL::PKey::RSA.new
  File.read(‘server_keypair.pem’)
config[:SSLCertificate] = OpenSSL::X509::Certificate.new
  File.read(‘certificate.pem’)

DRb.start_service here, [1, 2, ‘III’, 4, ‘five’, 6],
                  config

DRb.thread.join
SSL Socket Client
require ‘drb’
require ‘drb/ssl’

here = ‘drbssl://127.0.0.1:10000’
config = {}
config[:SSLVerifyMode] = OpenSSL::SSL::VERIFY_PEER
config[:SSLCACertificateFile] = ‘ca_cert.pem’

DRb.start_service nil, nil, config

ro = DRbObject.new nil, there

p ro.size
a = ro.collect { |x| x + x }
pa
DRb + SSL
• Need to generate and distribute certificates
 • Use QuickCert (on the RAA)
• Lots more config options
 • Verify client and server
• Do it right
 • SSL is hard
 • Not magic
Rinda
• TupleSpace
 • Shared object space
 • Atomic access
• Ring
 • DNS for DRb
 • Automatically locate services
TupleSpace Operations
• Add a tuple
  •   ts.write [:Add, 1, 2]

• Read a tuple matching a template
  •   ts.read [:Add, nil, nil]

• Read all tuples matching a template
  •   ts.read_all [:Add, nil, nil]

• Remove a tuple matching a template
  •   ts.take [:Add, nil, nil]
TupleSpace Templates
include Rinda

# All match
Template.new([:foo, 5]).match     Tuple.new([:foo, 5])
Template.new([:foo, nil]).match   Tuple.new([:foo, 5])
Template.new([/ll/]).match        Tuple.new([‘hello’])
Template.new([String]).match      Tuple.new([‘hello’])

# No match
Template.new([:foo, 6]).match     Tuple.new([:foo, 5])
Template.new([:foo, 6]).match     Tuple.new([:foo])
Template.new([:foo, nil]).match   Tuple.new([:foo])
Template.new([:foo]).match        Tuple.new([:foo, 5])
TupleSpace Usage
require ‘drb’
require ‘rinda/tuplespace’

ts = Rinda::TupleSpace.new

ts.write [:Add, id, 1, 2]

tuple = ts.take [:Add, nil, nil, nil]

ts.write [:Sum, tuple[1], tuple[2] + tuple[3]]

p ts.read_all([:Sum, nil, nil]).map { |t| t[2] }
TupleSpace Activity
[:Add, id, 1, 2]
                                       [:Add, id, 1, 2]
        (1) write
                                   (2) take



                    TupleSpace                 Calculate!
                                               1+2=3



       (4) read_all              (3) write
                                   [:Sum, id, 3]
[[:Sum, id, 3]]
Rinda::RingServer
require 'rinda/ring'
require 'rinda/tuplespace'

# start DRb
DRb.start_service

# Create a TupleSpace to hold named services,
# start running
Rinda::RingServer.new Rinda::TupleSpace.new

DRb.thread.join
Rinda::RingProvider
require ‘rinda/ring’
require ‘rinda/tuplespace’
require ‘thread’

DRb.start_service

queue = Queue.new

# Registers [:name, :WorkQueue, queue, ‘Work Queue’]
provider = Rinda::RingProvider.new :WorkQueue, queue,
                                   'Work Queue'

provider.provide
DRb.thread.join
Rinda::RingFinger
require ‘rinda/ring’

DRb.start_service
ring_server = Rinda::RingFinger.primary

tuple = ring_server.read [:name, :WorkQueue, nil, nil]
queue = tuple[2]

queue.push [1, 2]
Rinda::Ring Interactions
                                    RingServer
                                    TupleSpace




                                                  (4
                       ng




                                                     )
                                           (3
                     i              er




                                                      fi
                    r




                                             )
                                  t
              nd




                                                         n
                                s




                                                           d
                                                 fi
                              i
            i
                            eg
           f




                                                           Qu
                                                 nd
                          r
       )




                                                              e
    (1               2)




                                                               ue
                                                      ri
                   (




                                                      ng
RingProvider                                             RingFinger
                                 (5) use Queue
   Queue                                                 DRb Process
Hardening DRb
• Can’t completely
• ACL
• $SAFE
• default_load_limit
• SSL
• Don’t expose to untrusted parties
Why Not?

• Access arbitrary objects
• Run arbitrary methods
 • Infinite loops
 • Deadlocks
Access Control List
require ‘drb’
require ‘drb/acl’

acl = ACL.new %w[
  deny all
  allow 127.0.0.1
]

DRb.install_acl acl

DRb.start_service # ...
$SAFE & default_load_limit
 • DRb::DRbServer.default_safe_level
  • Sets $SAFE for remote method invocation
  • Protects from some dangerous operations
  • http://www.rubycentral.com/book/taint.html
 • DRb::DRbServer.default_load_limit
  • Maximum message size accepted by server
  • Defaults to 25MB
Advanced Features
• Gateway Id Conversion
 • Cross-protocol communication
 • DRb over SSH
• DRbObservable
• sample/drb
 • In Ruby tarball
Gateway Conversion
     ziz


DRb Process 1
                                      kaa
                       TCP



                                 DRb Process 3
  UNIX Socket




                X
                          cket
                       So
                UNIX

DRb Process 2
Gateway Conversion
             ziz

             Gateway
             Process
              et



                                                  TC
                                  Via G
                                                                kaa
           ck




                                                       P
         So

                   UNIX So
        X




                                        atewa
         I




                                                           DRb Process 3
      UN




DRb Process 1
                           cket

                                              y




             DRb Process 2
Gateway Conversion
                                        GWIdConv
                                         Unwraps
              DRbObject
  uri     druby://ziz:10000
  ref



                            DRbObject
                 uri      drbunix://tmp/drb.sock

                 ref            0x29587e
Re-Dispatch
 to Target
Gotchas
• DRb relies on accurate DNS
 • IPv6 needs DNS too!
• Sharing
 • Is it OK to copy?
• Peer to peer
 • Connects back to other processes
• Garbage Collection
Further Reading                   Ques
                                                tion
                                           Time
                                                 !

• dRuby                 Web

 • (Distributed and Web Programming with dRuby)
• http://www2a.biglobe.ne.jp/~seki/ruby/druby.html
 • via http://excite.co.jp/world/english/web
• http://www.chadfowler.com/ruby/drb.html
• http://segment7.net/projects/ruby/drb/

Weitere ähnliche Inhalte

Was ist angesagt?

Java script objects 2
Java script objects 2Java script objects 2
Java script objects 2H K
 
Using QString effectively
Using QString effectivelyUsing QString effectively
Using QString effectivelyRoman Okolovich
 
How to not write a boring test in Golang
How to not write a boring test in GolangHow to not write a boring test in Golang
How to not write a boring test in GolangDan Tran
 
Declarative Internal DSLs in Lua: A Game Changing Experience
Declarative Internal DSLs in Lua: A Game Changing ExperienceDeclarative Internal DSLs in Lua: A Game Changing Experience
Declarative Internal DSLs in Lua: A Game Changing ExperienceAlexander Gladysh
 
Qtp+real time+test+script
Qtp+real time+test+scriptQtp+real time+test+script
Qtp+real time+test+scriptRamu Palanki
 
Rust Workshop - NITC FOSSMEET 2017
Rust Workshop - NITC FOSSMEET 2017 Rust Workshop - NITC FOSSMEET 2017
Rust Workshop - NITC FOSSMEET 2017 pramode_ce
 
Hijacking Ruby Syntax in Ruby
Hijacking Ruby Syntax in RubyHijacking Ruby Syntax in Ruby
Hijacking Ruby Syntax in RubySATOSHI TAGOMORI
 
そうだ、bf処理系作ろう!もちろんSQLで!
そうだ、bf処理系作ろう!もちろんSQLで!そうだ、bf処理系作ろう!もちろんSQLで!
そうだ、bf処理系作ろう!もちろんSQLで!bleis tift
 

Was ist angesagt? (13)

Java script objects 2
Java script objects 2Java script objects 2
Java script objects 2
 
Using QString effectively
Using QString effectivelyUsing QString effectively
Using QString effectively
 
Why rust?
Why rust?Why rust?
Why rust?
 
How to not write a boring test in Golang
How to not write a boring test in GolangHow to not write a boring test in Golang
How to not write a boring test in Golang
 
Breaking the wall
Breaking the wallBreaking the wall
Breaking the wall
 
Declarative Internal DSLs in Lua: A Game Changing Experience
Declarative Internal DSLs in Lua: A Game Changing ExperienceDeclarative Internal DSLs in Lua: A Game Changing Experience
Declarative Internal DSLs in Lua: A Game Changing Experience
 
Book
BookBook
Book
 
Qtp+real time+test+script
Qtp+real time+test+scriptQtp+real time+test+script
Qtp+real time+test+script
 
Groovy
GroovyGroovy
Groovy
 
Rust Workshop - NITC FOSSMEET 2017
Rust Workshop - NITC FOSSMEET 2017 Rust Workshop - NITC FOSSMEET 2017
Rust Workshop - NITC FOSSMEET 2017
 
Groovy intro for OUDL
Groovy intro for OUDLGroovy intro for OUDL
Groovy intro for OUDL
 
Hijacking Ruby Syntax in Ruby
Hijacking Ruby Syntax in RubyHijacking Ruby Syntax in Ruby
Hijacking Ruby Syntax in Ruby
 
そうだ、bf処理系作ろう!もちろんSQLで!
そうだ、bf処理系作ろう!もちろんSQLで!そうだ、bf処理系作ろう!もちろんSQLで!
そうだ、bf処理系作ろう!もちろんSQLで!
 

Andere mochten auch

Hoja de vida
Hoja de vidaHoja de vida
Hoja de vidagevisdiaz
 
Primer borrador.
Primer borrador.Primer borrador.
Primer borrador.dianapj455
 
Mobile Tagging
Mobile TaggingMobile Tagging
Mobile Taggingus468
 
It Service Green Tech V5webprint
It Service Green Tech V5webprintIt Service Green Tech V5webprint
It Service Green Tech V5webprintmanavsingh
 
Diagrama Junio/2013 - www.visio-es.com
Diagrama Junio/2013 - www.visio-es.comDiagrama Junio/2013 - www.visio-es.com
Diagrama Junio/2013 - www.visio-es.comNicolas Lopez Cisneros
 
Solar4s [Solar Force] Energía Renovable
Solar4s [Solar Force] Energía RenovableSolar4s [Solar Force] Energía Renovable
Solar4s [Solar Force] Energía RenovableAdrian Escutia Soto
 
Enoturismo Universidad Abat Oliva CEU - Postgrado de Comunicación Gastronómic...
Enoturismo Universidad Abat Oliva CEU - Postgrado de Comunicación Gastronómic...Enoturismo Universidad Abat Oliva CEU - Postgrado de Comunicación Gastronómic...
Enoturismo Universidad Abat Oliva CEU - Postgrado de Comunicación Gastronómic...Can Bonastre Wine Resort
 
Recursos Para El Aprendizaje. Grupo 1. Diplomado UPEL 2014
Recursos Para El Aprendizaje. Grupo 1. Diplomado UPEL 2014Recursos Para El Aprendizaje. Grupo 1. Diplomado UPEL 2014
Recursos Para El Aprendizaje. Grupo 1. Diplomado UPEL 2014EdixiYepez
 
Libro blanco de_los_viajes_sociales_revolucion_movil
Libro blanco de_los_viajes_sociales_revolucion_movilLibro blanco de_los_viajes_sociales_revolucion_movil
Libro blanco de_los_viajes_sociales_revolucion_movilSAP
 
Agenda culturală ARCH-I pe luna octombrie 2015, actualizată
Agenda culturală ARCH-I pe luna octombrie 2015, actualizatăAgenda culturală ARCH-I pe luna octombrie 2015, actualizată
Agenda culturală ARCH-I pe luna octombrie 2015, actualizatăCosminCH
 
Enzo merletti y guillermo blanco
Enzo merletti y guillermo blancoEnzo merletti y guillermo blanco
Enzo merletti y guillermo blancoGuillermo Blanco
 
Voces juveniles (Radio escolar como mecanismo de difusión y promoción de dere...
Voces juveniles (Radio escolar como mecanismo de difusión y promoción de dere...Voces juveniles (Radio escolar como mecanismo de difusión y promoción de dere...
Voces juveniles (Radio escolar como mecanismo de difusión y promoción de dere...CTeI Putumayo
 
Lineamientos generales de la política
Lineamientos generales de la políticaLineamientos generales de la política
Lineamientos generales de la políticaReciclajeESAP
 
MachinesHUB investment proposal (Feb2015)
MachinesHUB investment proposal (Feb2015)MachinesHUB investment proposal (Feb2015)
MachinesHUB investment proposal (Feb2015)Parthiban Elangovan
 
[Bioforce] presentation de la formation à distance gestion financière
[Bioforce] presentation de la formation à distance gestion financière[Bioforce] presentation de la formation à distance gestion financière
[Bioforce] presentation de la formation à distance gestion financièreDigiDago
 
Trendlines: Perspectives on Utah's Economy, Nov/Dec 2009
Trendlines: Perspectives on Utah's Economy, Nov/Dec 2009Trendlines: Perspectives on Utah's Economy, Nov/Dec 2009
Trendlines: Perspectives on Utah's Economy, Nov/Dec 2009State of Utah, Salt Lake City
 

Andere mochten auch (20)

Hoja de vida
Hoja de vidaHoja de vida
Hoja de vida
 
Primer borrador.
Primer borrador.Primer borrador.
Primer borrador.
 
Mobile Tagging
Mobile TaggingMobile Tagging
Mobile Tagging
 
It Service Green Tech V5webprint
It Service Green Tech V5webprintIt Service Green Tech V5webprint
It Service Green Tech V5webprint
 
Diagrama Junio/2013 - www.visio-es.com
Diagrama Junio/2013 - www.visio-es.comDiagrama Junio/2013 - www.visio-es.com
Diagrama Junio/2013 - www.visio-es.com
 
Solar4s [Solar Force] Energía Renovable
Solar4s [Solar Force] Energía RenovableSolar4s [Solar Force] Energía Renovable
Solar4s [Solar Force] Energía Renovable
 
Enoturismo Universidad Abat Oliva CEU - Postgrado de Comunicación Gastronómic...
Enoturismo Universidad Abat Oliva CEU - Postgrado de Comunicación Gastronómic...Enoturismo Universidad Abat Oliva CEU - Postgrado de Comunicación Gastronómic...
Enoturismo Universidad Abat Oliva CEU - Postgrado de Comunicación Gastronómic...
 
Recursos Para El Aprendizaje. Grupo 1. Diplomado UPEL 2014
Recursos Para El Aprendizaje. Grupo 1. Diplomado UPEL 2014Recursos Para El Aprendizaje. Grupo 1. Diplomado UPEL 2014
Recursos Para El Aprendizaje. Grupo 1. Diplomado UPEL 2014
 
Libro blanco de_los_viajes_sociales_revolucion_movil
Libro blanco de_los_viajes_sociales_revolucion_movilLibro blanco de_los_viajes_sociales_revolucion_movil
Libro blanco de_los_viajes_sociales_revolucion_movil
 
Frases de empresarios y emprendedores
Frases de empresarios y emprendedoresFrases de empresarios y emprendedores
Frases de empresarios y emprendedores
 
Agenda culturală ARCH-I pe luna octombrie 2015, actualizată
Agenda culturală ARCH-I pe luna octombrie 2015, actualizatăAgenda culturală ARCH-I pe luna octombrie 2015, actualizată
Agenda culturală ARCH-I pe luna octombrie 2015, actualizată
 
ITB2016 - ContentBox Modular CMS
ITB2016 - ContentBox Modular CMSITB2016 - ContentBox Modular CMS
ITB2016 - ContentBox Modular CMS
 
Enzo merletti y guillermo blanco
Enzo merletti y guillermo blancoEnzo merletti y guillermo blanco
Enzo merletti y guillermo blanco
 
Voces juveniles (Radio escolar como mecanismo de difusión y promoción de dere...
Voces juveniles (Radio escolar como mecanismo de difusión y promoción de dere...Voces juveniles (Radio escolar como mecanismo de difusión y promoción de dere...
Voces juveniles (Radio escolar como mecanismo de difusión y promoción de dere...
 
Lineamientos generales de la política
Lineamientos generales de la políticaLineamientos generales de la política
Lineamientos generales de la política
 
MachinesHUB investment proposal (Feb2015)
MachinesHUB investment proposal (Feb2015)MachinesHUB investment proposal (Feb2015)
MachinesHUB investment proposal (Feb2015)
 
Sevilla se mueve
Sevilla se mueve Sevilla se mueve
Sevilla se mueve
 
[Bioforce] presentation de la formation à distance gestion financière
[Bioforce] presentation de la formation à distance gestion financière[Bioforce] presentation de la formation à distance gestion financière
[Bioforce] presentation de la formation à distance gestion financière
 
El diseño
El diseñoEl diseño
El diseño
 
Trendlines: Perspectives on Utah's Economy, Nov/Dec 2009
Trendlines: Perspectives on Utah's Economy, Nov/Dec 2009Trendlines: Perspectives on Utah's Economy, Nov/Dec 2009
Trendlines: Perspectives on Utah's Economy, Nov/Dec 2009
 

Ähnlich wie D Rb Silicon Valley Ruby Conference

Distributed Ruby and Rails
Distributed Ruby and RailsDistributed Ruby and Rails
Distributed Ruby and RailsWen-Tien Chang
 
DRb at the Ruby Drink-up of Sophia, December 2011
DRb at the Ruby Drink-up of Sophia, December 2011DRb at the Ruby Drink-up of Sophia, December 2011
DRb at the Ruby Drink-up of Sophia, December 2011rivierarb
 
Getting Distributed (With Ruby On Rails)
Getting Distributed (With Ruby On Rails)Getting Distributed (With Ruby On Rails)
Getting Distributed (With Ruby On Rails)martinbtt
 
How to create multiprocess server on windows with ruby - rubykaigi2016 Ritta ...
How to create multiprocess server on windows with ruby - rubykaigi2016 Ritta ...How to create multiprocess server on windows with ruby - rubykaigi2016 Ritta ...
How to create multiprocess server on windows with ruby - rubykaigi2016 Ritta ...Ritta Narita
 
Middleware as Code with mruby
Middleware as Code with mrubyMiddleware as Code with mruby
Middleware as Code with mrubyHiroshi SHIBATA
 
Picking gem ruby for penetration testers
Picking gem ruby for penetration testersPicking gem ruby for penetration testers
Picking gem ruby for penetration testersPaolo Perego
 
Cs757 ns2-tutorial-exercise
Cs757 ns2-tutorial-exerciseCs757 ns2-tutorial-exercise
Cs757 ns2-tutorial-exercisePratik Joshi
 
Hiveminder - Everything but the Secret Sauce
Hiveminder - Everything but the Secret SauceHiveminder - Everything but the Secret Sauce
Hiveminder - Everything but the Secret SauceJesse Vincent
 
Background Jobs - Com BackgrounDRb
Background Jobs - Com BackgrounDRbBackground Jobs - Com BackgrounDRb
Background Jobs - Com BackgrounDRbJuan Maiz
 
Concept of BlockChain & Decentralized Application
Concept of BlockChain & Decentralized ApplicationConcept of BlockChain & Decentralized Application
Concept of BlockChain & Decentralized ApplicationSeiji Takahashi
 
Create your own PHP extension, step by step - phpDay 2012 Verona
Create your own PHP extension, step by step - phpDay 2012 VeronaCreate your own PHP extension, step by step - phpDay 2012 Verona
Create your own PHP extension, step by step - phpDay 2012 VeronaPatrick Allaert
 
Code is not text! How graph technologies can help us to understand our code b...
Code is not text! How graph technologies can help us to understand our code b...Code is not text! How graph technologies can help us to understand our code b...
Code is not text! How graph technologies can help us to understand our code b...Andreas Dewes
 
Neo4j after 1 year in production
Neo4j after 1 year in productionNeo4j after 1 year in production
Neo4j after 1 year in productionAndrew Nikishaev
 
Distributes objects and Rmi
Distributes objects and RmiDistributes objects and Rmi
Distributes objects and RmiMayank Jain
 
Build microservice with gRPC in golang
Build microservice with gRPC in golangBuild microservice with gRPC in golang
Build microservice with gRPC in golangTing-Li Chou
 
Apache thrift-RPC service cross languages
Apache thrift-RPC service cross languagesApache thrift-RPC service cross languages
Apache thrift-RPC service cross languagesJimmy Lai
 
Performance measurement and tuning
Performance measurement and tuningPerformance measurement and tuning
Performance measurement and tuningAOE
 
Benchmarking and PHPBench
Benchmarking and PHPBenchBenchmarking and PHPBench
Benchmarking and PHPBenchdantleech
 

Ähnlich wie D Rb Silicon Valley Ruby Conference (20)

Distributed Ruby and Rails
Distributed Ruby and RailsDistributed Ruby and Rails
Distributed Ruby and Rails
 
DRb at the Ruby Drink-up of Sophia, December 2011
DRb at the Ruby Drink-up of Sophia, December 2011DRb at the Ruby Drink-up of Sophia, December 2011
DRb at the Ruby Drink-up of Sophia, December 2011
 
Getting Distributed (With Ruby On Rails)
Getting Distributed (With Ruby On Rails)Getting Distributed (With Ruby On Rails)
Getting Distributed (With Ruby On Rails)
 
Profiling Ruby
Profiling RubyProfiling Ruby
Profiling Ruby
 
How to create multiprocess server on windows with ruby - rubykaigi2016 Ritta ...
How to create multiprocess server on windows with ruby - rubykaigi2016 Ritta ...How to create multiprocess server on windows with ruby - rubykaigi2016 Ritta ...
How to create multiprocess server on windows with ruby - rubykaigi2016 Ritta ...
 
Middleware as Code with mruby
Middleware as Code with mrubyMiddleware as Code with mruby
Middleware as Code with mruby
 
Picking gem ruby for penetration testers
Picking gem ruby for penetration testersPicking gem ruby for penetration testers
Picking gem ruby for penetration testers
 
Cs757 ns2-tutorial-exercise
Cs757 ns2-tutorial-exerciseCs757 ns2-tutorial-exercise
Cs757 ns2-tutorial-exercise
 
Hiveminder - Everything but the Secret Sauce
Hiveminder - Everything but the Secret SauceHiveminder - Everything but the Secret Sauce
Hiveminder - Everything but the Secret Sauce
 
Background Jobs - Com BackgrounDRb
Background Jobs - Com BackgrounDRbBackground Jobs - Com BackgrounDRb
Background Jobs - Com BackgrounDRb
 
Concept of BlockChain & Decentralized Application
Concept of BlockChain & Decentralized ApplicationConcept of BlockChain & Decentralized Application
Concept of BlockChain & Decentralized Application
 
Create your own PHP extension, step by step - phpDay 2012 Verona
Create your own PHP extension, step by step - phpDay 2012 VeronaCreate your own PHP extension, step by step - phpDay 2012 Verona
Create your own PHP extension, step by step - phpDay 2012 Verona
 
Code is not text! How graph technologies can help us to understand our code b...
Code is not text! How graph technologies can help us to understand our code b...Code is not text! How graph technologies can help us to understand our code b...
Code is not text! How graph technologies can help us to understand our code b...
 
Ns tutorial
Ns tutorialNs tutorial
Ns tutorial
 
Neo4j after 1 year in production
Neo4j after 1 year in productionNeo4j after 1 year in production
Neo4j after 1 year in production
 
Distributes objects and Rmi
Distributes objects and RmiDistributes objects and Rmi
Distributes objects and Rmi
 
Build microservice with gRPC in golang
Build microservice with gRPC in golangBuild microservice with gRPC in golang
Build microservice with gRPC in golang
 
Apache thrift-RPC service cross languages
Apache thrift-RPC service cross languagesApache thrift-RPC service cross languages
Apache thrift-RPC service cross languages
 
Performance measurement and tuning
Performance measurement and tuningPerformance measurement and tuning
Performance measurement and tuning
 
Benchmarking and PHPBench
Benchmarking and PHPBenchBenchmarking and PHPBench
Benchmarking and PHPBench
 

Mehr von nextlib

Hadoop Map Reduce Arch
Hadoop Map Reduce ArchHadoop Map Reduce Arch
Hadoop Map Reduce Archnextlib
 
Multi-core architectures
Multi-core architecturesMulti-core architectures
Multi-core architecturesnextlib
 
Aldous Huxley Brave New World
Aldous Huxley Brave New WorldAldous Huxley Brave New World
Aldous Huxley Brave New Worldnextlib
 
Social Graph
Social GraphSocial Graph
Social Graphnextlib
 
Ajax Prediction
Ajax PredictionAjax Prediction
Ajax Predictionnextlib
 
Closures for Java
Closures for JavaClosures for Java
Closures for Javanextlib
 
A Content-Driven Reputation System for the Wikipedia
A Content-Driven Reputation System for the WikipediaA Content-Driven Reputation System for the Wikipedia
A Content-Driven Reputation System for the Wikipedianextlib
 
SVD review
SVD reviewSVD review
SVD reviewnextlib
 
Mongrel Handlers
Mongrel HandlersMongrel Handlers
Mongrel Handlersnextlib
 
Blue Ocean Strategy
Blue Ocean StrategyBlue Ocean Strategy
Blue Ocean Strategynextlib
 
日本7-ELEVEN消費心理學
日本7-ELEVEN消費心理學日本7-ELEVEN消費心理學
日本7-ELEVEN消費心理學nextlib
 
Comparing State-of-the-Art Collaborative Filtering Systems
Comparing State-of-the-Art Collaborative Filtering SystemsComparing State-of-the-Art Collaborative Filtering Systems
Comparing State-of-the-Art Collaborative Filtering Systemsnextlib
 
Item Based Collaborative Filtering Recommendation Algorithms
Item Based Collaborative Filtering Recommendation AlgorithmsItem Based Collaborative Filtering Recommendation Algorithms
Item Based Collaborative Filtering Recommendation Algorithmsnextlib
 
Agile Adoption2007
Agile Adoption2007Agile Adoption2007
Agile Adoption2007nextlib
 
Modern Compiler Design
Modern Compiler DesignModern Compiler Design
Modern Compiler Designnextlib
 
透过众神的眼睛--鸟瞰非洲
透过众神的眼睛--鸟瞰非洲透过众神的眼睛--鸟瞰非洲
透过众神的眼睛--鸟瞰非洲nextlib
 
Improving Quality of Search Results Clustering with Approximate Matrix Factor...
Improving Quality of Search Results Clustering with Approximate Matrix Factor...Improving Quality of Search Results Clustering with Approximate Matrix Factor...
Improving Quality of Search Results Clustering with Approximate Matrix Factor...nextlib
 
Support Vector Machines
Support Vector MachinesSupport Vector Machines
Support Vector Machinesnextlib
 
Bigtable
BigtableBigtable
Bigtablenextlib
 

Mehr von nextlib (20)

Nio
NioNio
Nio
 
Hadoop Map Reduce Arch
Hadoop Map Reduce ArchHadoop Map Reduce Arch
Hadoop Map Reduce Arch
 
Multi-core architectures
Multi-core architecturesMulti-core architectures
Multi-core architectures
 
Aldous Huxley Brave New World
Aldous Huxley Brave New WorldAldous Huxley Brave New World
Aldous Huxley Brave New World
 
Social Graph
Social GraphSocial Graph
Social Graph
 
Ajax Prediction
Ajax PredictionAjax Prediction
Ajax Prediction
 
Closures for Java
Closures for JavaClosures for Java
Closures for Java
 
A Content-Driven Reputation System for the Wikipedia
A Content-Driven Reputation System for the WikipediaA Content-Driven Reputation System for the Wikipedia
A Content-Driven Reputation System for the Wikipedia
 
SVD review
SVD reviewSVD review
SVD review
 
Mongrel Handlers
Mongrel HandlersMongrel Handlers
Mongrel Handlers
 
Blue Ocean Strategy
Blue Ocean StrategyBlue Ocean Strategy
Blue Ocean Strategy
 
日本7-ELEVEN消費心理學
日本7-ELEVEN消費心理學日本7-ELEVEN消費心理學
日本7-ELEVEN消費心理學
 
Comparing State-of-the-Art Collaborative Filtering Systems
Comparing State-of-the-Art Collaborative Filtering SystemsComparing State-of-the-Art Collaborative Filtering Systems
Comparing State-of-the-Art Collaborative Filtering Systems
 
Item Based Collaborative Filtering Recommendation Algorithms
Item Based Collaborative Filtering Recommendation AlgorithmsItem Based Collaborative Filtering Recommendation Algorithms
Item Based Collaborative Filtering Recommendation Algorithms
 
Agile Adoption2007
Agile Adoption2007Agile Adoption2007
Agile Adoption2007
 
Modern Compiler Design
Modern Compiler DesignModern Compiler Design
Modern Compiler Design
 
透过众神的眼睛--鸟瞰非洲
透过众神的眼睛--鸟瞰非洲透过众神的眼睛--鸟瞰非洲
透过众神的眼睛--鸟瞰非洲
 
Improving Quality of Search Results Clustering with Approximate Matrix Factor...
Improving Quality of Search Results Clustering with Approximate Matrix Factor...Improving Quality of Search Results Clustering with Approximate Matrix Factor...
Improving Quality of Search Results Clustering with Approximate Matrix Factor...
 
Support Vector Machines
Support Vector MachinesSupport Vector Machines
Support Vector Machines
 
Bigtable
BigtableBigtable
Bigtable
 

Kürzlich hochgeladen

"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii SoldatenkoFwdays
 
"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr BaganFwdays
 
My INSURER PTE LTD - Insurtech Innovation Award 2024
My INSURER PTE LTD - Insurtech Innovation Award 2024My INSURER PTE LTD - Insurtech Innovation Award 2024
My INSURER PTE LTD - Insurtech Innovation Award 2024The Digital Insurer
 
Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024Scott Keck-Warren
 
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Mark Simos
 
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024BookNet Canada
 
SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024Lorenzo Miniero
 
Designing IA for AI - Information Architecture Conference 2024
Designing IA for AI - Information Architecture Conference 2024Designing IA for AI - Information Architecture Conference 2024
Designing IA for AI - Information Architecture Conference 2024Enterprise Knowledge
 
My Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationMy Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationRidwan Fadjar
 
The Future of Software Development - Devin AI Innovative Approach.pdf
The Future of Software Development - Devin AI Innovative Approach.pdfThe Future of Software Development - Devin AI Innovative Approach.pdf
The Future of Software Development - Devin AI Innovative Approach.pdfSeasiaInfotech2
 
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...Patryk Bandurski
 
DevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache MavenDevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache MavenHervé Boutemy
 
Training state-of-the-art general text embedding
Training state-of-the-art general text embeddingTraining state-of-the-art general text embedding
Training state-of-the-art general text embeddingZilliz
 
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek SchlawackFwdays
 
Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 365Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 3652toLead Limited
 
Commit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easyCommit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easyAlfredo García Lavilla
 
Dev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebDev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebUiPathCommunity
 
DevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsDevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsSergiu Bodiu
 
Search Engine Optimization SEO PDF for 2024.pdf
Search Engine Optimization SEO PDF for 2024.pdfSearch Engine Optimization SEO PDF for 2024.pdf
Search Engine Optimization SEO PDF for 2024.pdfRankYa
 
CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):comworks
 

Kürzlich hochgeladen (20)

"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko
 
"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan
 
My INSURER PTE LTD - Insurtech Innovation Award 2024
My INSURER PTE LTD - Insurtech Innovation Award 2024My INSURER PTE LTD - Insurtech Innovation Award 2024
My INSURER PTE LTD - Insurtech Innovation Award 2024
 
Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024
 
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
 
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
 
SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024
 
Designing IA for AI - Information Architecture Conference 2024
Designing IA for AI - Information Architecture Conference 2024Designing IA for AI - Information Architecture Conference 2024
Designing IA for AI - Information Architecture Conference 2024
 
My Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationMy Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 Presentation
 
The Future of Software Development - Devin AI Innovative Approach.pdf
The Future of Software Development - Devin AI Innovative Approach.pdfThe Future of Software Development - Devin AI Innovative Approach.pdf
The Future of Software Development - Devin AI Innovative Approach.pdf
 
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
 
DevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache MavenDevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache Maven
 
Training state-of-the-art general text embedding
Training state-of-the-art general text embeddingTraining state-of-the-art general text embedding
Training state-of-the-art general text embedding
 
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
 
Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 365Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 365
 
Commit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easyCommit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easy
 
Dev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebDev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio Web
 
DevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsDevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platforms
 
Search Engine Optimization SEO PDF for 2024.pdf
Search Engine Optimization SEO PDF for 2024.pdfSearch Engine Optimization SEO PDF for 2024.pdf
Search Engine Optimization SEO PDF for 2024.pdf
 
CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):
 

D Rb Silicon Valley Ruby Conference

  • 1. Distributed Ruby An Introduction and Overview Eric Hodel - drbrain@segment7.net http://blog.segment7.net
  • 2. What is DRb? • Remote Method Invocation for Ruby • Peer to peer • Client and server • Multiplatform • Multiprotocol • More...
  • 3. Why Do I Need DRb? • Parallelism • Distribute work • Interprocess communication • Monitoring
  • 4. Example # Server require ‘drb’ here = 'druby://127.0.0.1:10000' DRb.start_service here, [1, 2, ‘III’, 4, ‘five’, 6] DRb.thread.join # Client require ‘drb’ there = 'druby://127.0.0.1:10000' DRb.start_service ro = DRbObject.new nil, there p ro.size a = ro.collect { |x| x + x } pa
  • 5. Example Server require ‘drb’ # load DRb here = ‘druby://127.0.0.1:10000’ # server URI # start DRb DRb.start_service here, # our local URI [1, 2, ‘III’, 4, ‘five’, 6] # our front object DRb.thread.join # wait until DRb is done
  • 6. Front Object • Optional • Default object • Passed by reference • Only one copy
  • 7. Example Client require ‘drb’ # load DRb How does it work? there = ‘druby://127.0.0.1:10000’ # remote server URI DRb.start_service # start local DRb server Can’t dump ro = DRbObject.new_with_uri there # connect to the server code! # work with the remote object p ro.size a = ro.collect { |x| x + x } p a
  • 8. ro.collect { |x| x + x } Server Client [1, 2, 'III', #<DRb::DRbObject> 4, 'five', 6] #<DRb::DRbObject> { |x| x + x }
  • 9. ro.collect { |x| x + x } Server Client Array Array DRbObject size collect Client Client Block DRbObject Block call 1 call 1 call 2 call 2 call 'III' call 'III'
  • 10. DRbObject • Proxy object • Contains URI and reference • Which server • What object • Be aware of garbage collection • May be collected on server • Usually doesn't matter
  • 11. DRbObject druby://127.0.0.1:10000 DRbObject 'Hello' uri druby://127.0.0.1:10000 0x29587e ref 0x29587e DRbObject [1, 2, 'III'] uri druby://127.0.0.1:10000 0x28c7fc ref 0x28c7f6
  • 12. Id Conversion • Converts reference into object on server • DRbIdConv Default • object_id & ObjectSpace._id2ref • Alternates: • TimerIdConv Keep alive • NamedIdConv Reference by name • GWIdConv Protocol gateway
  • 13. TimerIdConv require 'drb' require 'drb/timeridconv' id_conv = DRb::TimerIdConv.new 30 DRb.default_id_conv = id_conv DRb.start_service # ...
  • 14. NamedIdConv • Found in sample/drb/name.rb • Persistent objects • You must store your state • Good example id converter
  • 15. Remote Method Invocation • Client • Marshal method arguments • Send message to server • Reference, method name, arguments • Server • Receive message • Unmarshal arguments • Find local object from reference • Invoke method with arguments
  • 16. DRbUndumped • Default DRb operation • Pass by value • Must share code • With DRbUndumped • Pass by reference • No need to share code
  • 17. Automatic DRbObjects • Module and Class • IO • File, TCPSocket, UNIXSocket, etc. • Blocks, Procs, Methods • Thread, ThreadGroup • Dir, File::Stat, Binding, Continuation
  • 18. Using DRbUndumped require ‘drb’ class X include DRb::DRbUndumped # ... end object = [1, 2, ‘III’, 4, ‘five’] object.extend DRb::DRbUndumped
  • 19. Why Use DRbUndumped? • Big objects • Singleton objects • Lightweight clients • Rapidly changing software
  • 20. Connection Types • TCP Sockets • UNIX Sockets • SSL Sockets
  • 21. UNIX Socket Server require ‘drb’ require ‘drb/unix’ here = 'drbunix://tmp/darray.sock' DRb.start_service here, [1, 2, quot;IIIquot;, 4, quot;fivequot;, 6] DRb.thread.join
  • 22. UNIX Socket Client require ‘drb’ require ‘drb/unix’ there = 'drbunix://tmp/darray.sock' DRb.start_service ro = DRbObject.new nil, there p ro.size a = ro.collect { |x| x + x } pa
  • 23. SSL Socket Server require ‘drb’ require ‘drb/ssl’ here = ‘drbssl://127.0.0.1:10000’ config = {} config[:SSLPrivateKey] = OpenSSL::PKey::RSA.new File.read(‘server_keypair.pem’) config[:SSLCertificate] = OpenSSL::X509::Certificate.new File.read(‘certificate.pem’) DRb.start_service here, [1, 2, ‘III’, 4, ‘five’, 6], config DRb.thread.join
  • 24. SSL Socket Client require ‘drb’ require ‘drb/ssl’ here = ‘drbssl://127.0.0.1:10000’ config = {} config[:SSLVerifyMode] = OpenSSL::SSL::VERIFY_PEER config[:SSLCACertificateFile] = ‘ca_cert.pem’ DRb.start_service nil, nil, config ro = DRbObject.new nil, there p ro.size a = ro.collect { |x| x + x } pa
  • 25. DRb + SSL • Need to generate and distribute certificates • Use QuickCert (on the RAA) • Lots more config options • Verify client and server • Do it right • SSL is hard • Not magic
  • 26. Rinda • TupleSpace • Shared object space • Atomic access • Ring • DNS for DRb • Automatically locate services
  • 27. TupleSpace Operations • Add a tuple • ts.write [:Add, 1, 2] • Read a tuple matching a template • ts.read [:Add, nil, nil] • Read all tuples matching a template • ts.read_all [:Add, nil, nil] • Remove a tuple matching a template • ts.take [:Add, nil, nil]
  • 28. TupleSpace Templates include Rinda # All match Template.new([:foo, 5]).match Tuple.new([:foo, 5]) Template.new([:foo, nil]).match Tuple.new([:foo, 5]) Template.new([/ll/]).match Tuple.new([‘hello’]) Template.new([String]).match Tuple.new([‘hello’]) # No match Template.new([:foo, 6]).match Tuple.new([:foo, 5]) Template.new([:foo, 6]).match Tuple.new([:foo]) Template.new([:foo, nil]).match Tuple.new([:foo]) Template.new([:foo]).match Tuple.new([:foo, 5])
  • 29. TupleSpace Usage require ‘drb’ require ‘rinda/tuplespace’ ts = Rinda::TupleSpace.new ts.write [:Add, id, 1, 2] tuple = ts.take [:Add, nil, nil, nil] ts.write [:Sum, tuple[1], tuple[2] + tuple[3]] p ts.read_all([:Sum, nil, nil]).map { |t| t[2] }
  • 30. TupleSpace Activity [:Add, id, 1, 2] [:Add, id, 1, 2] (1) write (2) take TupleSpace Calculate! 1+2=3 (4) read_all (3) write [:Sum, id, 3] [[:Sum, id, 3]]
  • 31. Rinda::RingServer require 'rinda/ring' require 'rinda/tuplespace' # start DRb DRb.start_service # Create a TupleSpace to hold named services, # start running Rinda::RingServer.new Rinda::TupleSpace.new DRb.thread.join
  • 32. Rinda::RingProvider require ‘rinda/ring’ require ‘rinda/tuplespace’ require ‘thread’ DRb.start_service queue = Queue.new # Registers [:name, :WorkQueue, queue, ‘Work Queue’] provider = Rinda::RingProvider.new :WorkQueue, queue, 'Work Queue' provider.provide DRb.thread.join
  • 33. Rinda::RingFinger require ‘rinda/ring’ DRb.start_service ring_server = Rinda::RingFinger.primary tuple = ring_server.read [:name, :WorkQueue, nil, nil] queue = tuple[2] queue.push [1, 2]
  • 34. Rinda::Ring Interactions RingServer TupleSpace (4 ng ) (3 i er fi r ) t nd n s d fi i i eg f Qu nd r ) e (1 2) ue ri ( ng RingProvider RingFinger (5) use Queue Queue DRb Process
  • 35. Hardening DRb • Can’t completely • ACL • $SAFE • default_load_limit • SSL • Don’t expose to untrusted parties
  • 36. Why Not? • Access arbitrary objects • Run arbitrary methods • Infinite loops • Deadlocks
  • 37. Access Control List require ‘drb’ require ‘drb/acl’ acl = ACL.new %w[ deny all allow 127.0.0.1 ] DRb.install_acl acl DRb.start_service # ...
  • 38. $SAFE & default_load_limit • DRb::DRbServer.default_safe_level • Sets $SAFE for remote method invocation • Protects from some dangerous operations • http://www.rubycentral.com/book/taint.html • DRb::DRbServer.default_load_limit • Maximum message size accepted by server • Defaults to 25MB
  • 39. Advanced Features • Gateway Id Conversion • Cross-protocol communication • DRb over SSH • DRbObservable • sample/drb • In Ruby tarball
  • 40. Gateway Conversion ziz DRb Process 1 kaa TCP DRb Process 3 UNIX Socket X cket So UNIX DRb Process 2
  • 41. Gateway Conversion ziz Gateway Process et TC Via G kaa ck P So UNIX So X atewa I DRb Process 3 UN DRb Process 1 cket y DRb Process 2
  • 42. Gateway Conversion GWIdConv Unwraps DRbObject uri druby://ziz:10000 ref DRbObject uri drbunix://tmp/drb.sock ref 0x29587e Re-Dispatch to Target
  • 43. Gotchas • DRb relies on accurate DNS • IPv6 needs DNS too! • Sharing • Is it OK to copy? • Peer to peer • Connects back to other processes • Garbage Collection
  • 44. Further Reading Ques tion Time ! • dRuby Web • (Distributed and Web Programming with dRuby) • http://www2a.biglobe.ne.jp/~seki/ruby/druby.html • via http://excite.co.jp/world/english/web • http://www.chadfowler.com/ruby/drb.html • http://segment7.net/projects/ruby/drb/