# How does drb work

**URL:** <https://www.ruby-forum.com/t/how-does-drb-work/124545>\
**Category:** Ruby\
**Created:** [December 30, 2007, 2:20am UTC](https://www.ruby-forum.com/t/how-does-drb-work/124545 "2007-12-30T02:20:48Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![Junkone](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/e274bd/32.png) [@Junkone](https://www.ruby-forum.com/u/Junkone)\
**Post date:** [December 30, 2007, 2:20am UTC](https://www.ruby-forum.com/t/how-does-drb-work/124545/1 "2007-12-30T02:20:48Z")

</div>

I am trying to understand how drb works and need some clarificaiton.

DRbServer.start\_service nil, method(params)

I then do a client call  
DRbClient.start\_service  
Then how do i trigger the DRbServer so that the mehods is triggered  
including a parameter passing.

appreciate help

---

<div class="post-metadata">

**Author:** ![Junkone](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/e274bd/32.png) [@Junkone](https://www.ruby-forum.com/u/Junkone)\
**Post date:** [December 30, 2007, 1:15pm UTC](https://www.ruby-forum.com/t/how-does-drb-work/124545/2 "2007-12-30T13:15:57Z")

</div>

On 30.12.2007 02:16, Junkone wrote:

> I am trying to understand how drb works and need some clarificaiton.
> 
> DRbServer.start\_service nil, method(params)
> 
> I then do a client call  
> DRbClient.start\_service  
> Then how do i trigger the DRbServer so that the mehods is triggered  
> including a parameter passing.

Please look at the documentation. There is a complete example that  
explains this. The Pickaxe is also a good source of information.

Regards

robert

---

<div class="post-metadata">

**Author:** ![Junkone](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/e274bd/32.png) [@Junkone](https://www.ruby-forum.com/u/Junkone)\
**Post date:** [December 30, 2007, 1:31pm UTC](https://www.ruby-forum.com/t/how-does-drb-work/124545/3 "2007-12-30T13:31:17Z")

</div>

> Please look at the documentation. There is a complete example that  
> explains this. The Pickaxe is also a good source of information.

Well I have the pickaxe, several examples too and use drb optionally to  
trigger  
compiling and installing packages … but for some reason, after some  
time of not using anything of that… i forget almost everything I read  
before about it.

drb usage is either not easy enough IMHO, or underdocumented. What’s  
also unfortunate is that … are there other ways for “distributed” ruby  
like in a local LAN?

---

<div class="post-metadata">

**Author:** ![Junkone](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/e274bd/32.png) [@Junkone](https://www.ruby-forum.com/u/Junkone)\
**Post date:** [December 30, 2007, 5:56pm UTC](https://www.ruby-forum.com/t/how-does-drb-work/124545/4 "2007-12-30T17:56:41Z")

</div>

On Dec 30, 2007, at 8:31 AM, Marcin R. wrote:

> Basically DRb.start\_service should be used for either starting  
> client or server - which is strange already.

just to clarify: not really. all drb processes are servants.  
neither server nor client exist separately. the definitions are  
determines dynamically based on usage.

> now run DRbServer.new(“strange://usrl”, object) starts drb server.
> 
> and @object = SRbObject.new(nil, “strange://url”) creates object in  
> client

you have to start\_service in both, perhaps with a front object and  
perhaps not. when you look up and object using DRbObject service is  
started for you iff it’s not already on. the reason is that DRb  
supports blocks. consider:

remote\_array = DRbObject.new nil, “druby://localhost:1234”

remote\_array.each do |element|  
element.upcase!  
end

if you think about this for a bit you’ll see a complex interaction  
between two servants. first, “remote\_array.each” is going to make a  
call on a remote object. that call is going to be passed a _block_  
but, wait a minute, blocks cannot be marshaled so how does that  
work? it doesn’t. the block stays on the “client” and is executed  
on that machine, on that cpu - but with a handle on remote “element”  
objects. depending on how those objects are setup they might be  
objects which are totally dumped/copied to the client and therefore  
changes are going to be local _or_ they may be proxies on remote  
objects and destructive methods might actually change the remote  
object behind the proxy. see DRbUndumped for more on this.

in any case the first step to understanding drb is doing away with  
the idea of static servers and clients - in drb every machine can  
potentially be both, sometimes within a given method. the  
distribution contains a _ton_ of examples:

cfp:~/build/ruby-1.8.6/sample/drb \> ls  
README.rd dbiff.rb dhasen.rb dqin.rb drbc.rb drbs-  
acl.rb extserv\_test.rb holderc.rb name.rb  
rindac.rb ring\_place.rb  
README.rd.ja dcdbiff.rb dhasenc.rb dqlib.rb drbch.rb  
drbs.rb gw\_ct.rb holders.rb namec.rb  
rindas.rb simpletuple.rb  
darray.rb dchatc.rb dlogc.rb dqout.rb drbm.rb  
drbssl\_c.rb gw\_cu.rb http0.rb old\_tuplespace.rb  
ring\_echo.rb speedc.rb  
darrayc.rb dchats.rb dlogd.rb dqueue.rb drbmc.rb  
drbssl\_s.rb gw\_s.rb http0serv.rb rinda\_ts.rb  
ring\_inspect.rb speeds.rb

which is a great place for people get started.

btw: favourite way to use drb is for ipc between two processes on the  
same machine via:

process a:  
DRb.start\_service “druby:localhost:0”,  
some\_object\_that\_acts\_as\_a\_server  
uri = DRb.uri

process b:  
DRb.start\_service “druby:localhost:0”  
remote\_object = DRbObject.new nil, uri

by starting service this way you basically setup drb to function  
perfectly for ipc situations and accept connections on all  
interfaces. it turns out that using remote/localhost objects for ipc  
is a portable way to accomplish something that’s generally non-  
portable on windows/unix/whatever. recently i used this

[http://drawohara.com/post/22540307](http://drawohara.com/post/22540307)

to solve a sticky windows signal issue - took only 4 or 5 lines of  
code. really good stuff that drb 😉

cheers.

a @ [http://codeforpeople.com/](http://codeforpeople.com/)

---

<div class="post-metadata">

**Author:** ![Junkone](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/e274bd/32.png) [@Junkone](https://www.ruby-forum.com/u/Junkone)\
**Post date:** [December 30, 2007, 4:32pm UTC](https://www.ruby-forum.com/t/how-does-drb-work/124545/5 "2007-12-30T16:32:14Z")

</div>

Marc H. wrote:

> also unfortunate is that … are there other ways for “distributed” ruby  
> like in a local LAN?

DRb documentation is mostly either bad, or for experts.

Basically DRb.start\_service should be used for either starting client or  
server - which is strange already.

now run DRbServer.new(“strange://usrl”, object) starts drb server.

and @object = SRbObject.new(nil, “strange://url”) creates object in  
client

now each method call to @object is marshaled and sent to DRBServer,  
where it’s executed, and results is again marshaled and sent back.

have phun

---

<div class="post-metadata">

**Author:** ![Junkone](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/e274bd/32.png) [@Junkone](https://www.ruby-forum.com/u/Junkone)\
**Post date:** [December 30, 2007, 6:45pm UTC](https://www.ruby-forum.com/t/how-does-drb-work/124545/6 "2007-12-30T18:45:25Z")

</div>

Don’t get me wrong, I like drb, but as you said it’s complex, and people  
usually want simple solutions 😉

I even used drb as lock that would not allow program to be run if  
another instance was running

require ‘drb’

begin  
DRbServer.new(“drb://localhost:23422”,nil)  
rescue Exception  
puts “only once!”  
exit 1  
end

but that doesn’t change the fact that it’s often confuising, blocking,  
have some memory problems, and it’s slow

---

<div class="post-metadata">

**Author:** ![Junkone](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/e274bd/32.png) [@Junkone](https://www.ruby-forum.com/u/Junkone)\
**Post date:** [December 30, 2007, 8:59pm UTC](https://www.ruby-forum.com/t/how-does-drb-work/124545/7 "2007-12-30T20:59:35Z")

</div>

On Dec 30, 2007, at 10:44 AM, Marcin R. wrote:

> Don’t get me wrong, I like drb, but as you said it’s complex, and  
> people usually want simple solutions 😉

conceded. ever check out romp?

> end  
> that’s very clever and i’m sure i’ll use it one day soon!

> but that doesn’t change the fact that it’s often confuising,  
> blocking, have some memory problems, and it’s slow

i haven’t seen blocking issues - but i rarely touch windows so i  
expect that’s the issue. speed hasn’t been an issue for me but  
that’s because my uses have had zero performance requirements. the  
romp site, old as it may be, claimed to be much faster.

kind regards.

a @ [http://codeforpeople.com/](http://codeforpeople.com/)
