!SLIDE bullets
![the dRuby book](./slide/sidruby.jpeg)!SLIDE bullets incremental
- Author of dRuby, Rinda, and ERB
- Ruby core committer (Rubyist since 1998)
- C by Day, Ruby by Night
- Never used Rails (Can't install!!)
- Pokemon Master
!SLIDE bullets incremental
!SLIDE bullets incremental
!SLIDE bullets incremental
!SLIDE bullets incremental
!SLIDE bullets incremental
- dRuby == Creative & fun
- Mastering dRuby == Mastering Ruby
- Please buy the book(promo code in the last slide)
!SLIDE bullets incremental
- Basics of dRuby
- Internals of dRuby
- Pass by value, Pass by reference
- Rinda
- Drip
!SLIDE bullets incremental
- Distributed Ruby
- 100% written in Ruby
- Part of Ruby Standard libraries
- Proxy to remote object
!SLIDE
@@@ ruby
require 'drb/drb'
class Puts
def initialize(stream=$stdout)
@stream = stream
end
def puts(str)
@stream.puts(str)
end
end
!SLIDE
@@@ ruby
DRb.start_service(uri, Puts.new)
DRb.thread.join()
!SLIDE
@@@ ruby
require 'drb'
there = DRbObject.new_with_uri('druby://:12345')
there.puts("hello world")
!SLIDE bullets
- http://www.screenr.com/embed/lO18 <iframe src="http://www.screenr.com/embed/lO18" width="650" height="396" frameborder="0"></iframe>
!SLIDE bullets incremental
- DRb.start_service
- DRbObject.new_with_uri
- DRb.thread.join()
!SLIDE
@@@ sh
[.rvm]$ find . -name 'drb' -print
./src/ruby-1.9.3-p0/lib/drb
./src/ruby-1.9.3-p0/sample/drb
./src/ruby-1.9.3-p0/test/drb
!SLIDE
@@@ sh
ruby ~/.rvm/src/ruby-1.9.3-p0/sample/drb/drchats.rb
ruby ~/.rvm/src/ruby-1.9.3-p0/sample/drb/drchatc.rb
!SLIDE bullets
!SLIDE bullets
!SLIDE
@@@ruby
class DRbObject
def method_missing(msg_id, *a)
succ, result = DRbConn.new(@uri).
send_message(self, msg_id, *a)
raise result if ! succ
result
end
!SLIDE
@@@ruby
module DRbProtocol
def dump(obj, soc)
begin
str = Marshal::dump(obj)
!SLIDE
@@@ruby
rescue
ro = DRbObject.new(obj)
str = Marshal::dump(ro)
end
soc.write(str) if soc
return str
end
end
!SLIDE bullets incremental
- method_missing as proxy
- Marshal.dump everything
- If failed, dump DRbObject
!SLIDE bullets incremental
- IO,File, Socket, etc
- Proc
!SLIDE bullets
@@@ruby
front = {}
DRb.start_service('druby://:7640', front)
server_proc = Proc.new{ `pwd`}
front['server_proc'] = server_proc
while true
sleep 1; puts "\n"; pp front;
front.each { |k,v| p "#{k}: #{v[]}"}
end
!SLIDE
@@@ruby
DRb.start_service
remote = DRbObject.new_with_uri('druby://:7640')
client_proc = Proc.new{`pwd`}
remote['client_proc'] = client_proc
DRb.thread.join
!SLIDE bullets
-
http://www.screenr.com/embed/ZO18
<iframe src="http://www.screenr.com/embed/ZO18" width="650" height="396" frameborder="0"></iframe>
!SLIDE bullets incremental
- Client is also Server
- DRbObject keeps reference
!SLIDE
@@@ruby
require 'drb'
arry = Array.new(10){ Proc.new{ p `pwd`}}
DRb.start_service('druby://:7640', arry)
DRb.thread.join
!SLIDE
require 'drb'
DRb.start_service
arry = DRbObject.new_with_uri('druby://:7640')
arry.each{|a| p `pwd`; a[]}
!SLIDE bullets
- <iframe src="http://www.screenr.com/embed/kO18" width="650" height="396" frameborder="0"></iframe>
!SLIDE
!SLIDE bullets incremental
- "each" happens locally
- "yield" happens remotely
- No "deadlock" thanks to Thread
!SLIDE bullets incremental
- Battleship
- Testing, Debugging, Monitoring utilities
- Network server for embedded tool(eg: Sqlite)
!SLIDE bullets incremental
- Part of Ruby standard libraries
- Port of Linda
- Process Coordination Mechanism
- Distributed TupleSpace
- Share via dRuby
!SLIDE
@@@ ruby
['abc', 2, 5]
[:matrix, 1,6, 3.14]
['family', 'is-sister', 'Carolyn']
!SLIDE bullets incremental
- write
- read, read_all
- take = read+delete
!SLIDE
Example (TupleSpace)
@@@ruby
require 'drb/drb'
require 'rinda/tuplespace'
ts = Rinda::TupleSpace.new
DRb.start_service('druby://:7641', ts)
DRb.thread.join
!SLIDE bullets
- <iframe src="http://www.screenr.com/embed/Bp18" width="650" height="396" frameborder="0"></iframe>
!SLIDE
@@@ ruby
ts.take([/add|sub/, Integer])
ts.take([nil, (10..Float::INFINITY)])
!SLIDE
@@@ ruby
class Njet
def initialize(value)
@value = value
end
def ===(other)
! (@value === other)
end
end
ts.take['age', Njet.new(23)]
!SLIDE bullets incremental
- notify (trigger)
- Hash API
- Ring (Name Server)
!SLIDE bullets incremental
- Simple task management tools
- Use it with "fork"(gem install rinda_eval)
!SLIDE bullets incremental
- PTupleSpace (2007) = Persisted tuplespace
- MapReduce, OODB (2009)
- Drip (2011) = Immutable datastore
!SLIDE bullets
- gem install drip
!SLIDE bullets incremental
- Append Only
- Each data has key as time stamp
- Can traverse older/newer
- Can add "Tag"
!SLIDE bullet
@@@ruby
MyDrip.write(20, 'seki.age', 'male')
MyDrip.write(14, 'sora_h', 'male')
MyDrip.write(29, 'kate', 'female')
!SLIDE bullets
@@@ruby
k = 0
while k
sleep 2
r = MyDrip.read(k, 4, 1, 2)
pp r; puts "\n"
k = r[-1][0]
end
!SLIDE
@@@ruby
k,v, *tags = MyDrip.head(1, 'male')[0]
# => [1333437978553705, 30, "will", "male"]
!SLIDE
@@@ruby
k,v, *tags = MyDrip.older(k, 'male')
!SLIDE bullets
- <iframe src="http://www.screenr.com/embed/9X18" width="650" height="396" frameborder="0"></iframe>
!SLIDE bullets incremental
- newer
- read_tag
- []
!SLIDE bullets incremental
- Hash with History
- Recoverable Queue
- Multicast Messaging
- Tweets archive
- Desktop search engine
!SLIDE bullets incremental
- dRuby = Feels like Ruby
- Rinda = Cool pattern matching
- Drip = Immutable datastore
- [name of your cool new distributed tools]
!SLIDE bullets
!["the dRuby book"](./slide/sidruby.jpeg) * [@makoto_inoue](https://twitter.com/makoto_inoue) * [https://github.com/makoto](https://github.com/makoto/demystifying_druby_lrug_april_2012)