Why is this DRb code so slow?

J

Jim Freeze

Ok, I'm stumped. I have a simple drb example, and it is
taking about 1 minute to get the value of an array with
two items in it.

% cat simple-server.rb
require 'drb'

def start_daemon
if (child_pid = fork)
File.open(__FILE__+".pid", "w") { |f| f.puts child_pid }
exit
end
Process.setsid
end

start_daemon

class MyClass
def files
%w(test1 test2)
end
end

DRb.start_service nil, MyClass.new

puts DRb.uri
File.open(__FILE__+".uri", "w") { |f| f.puts DRb.uri }
puts "Server started"
DRb.thread.join

% cat simple-client.rb
require 'drb'
DRb.start_service

server = File.read("simple-server.rb.uri").strip
puts "Connecting to #{server}"

begin
robj = DRbObject.new nil, server
p robj
p robj.object_id
p robj.files

rescue DRb::DRbConnError => err
puts "No response from server"
puts err
end

% ruby simple-server.rb
druby://cheetah.local:49506
Server started

% ruby simple-client.rb
Connecting to druby://cheetah.local:49506
#<DRb::DRbObject:0xb257c @ref=nil, @uri="druby://cheetah.local:49506">
365246
["test1", "test2"]

The last line takes about a minute to be printed.
 
C

Chad Fowler

Ok, I'm stumped. I have a simple drb example, and it is
taking about 1 minute to get the value of an array with
two items in it.
=20
% cat simple-server.rb
require 'drb'
=20
def start_daemon
if (child_pid =3D fork)
File.open(__FILE__+".pid", "w") { |f| f.puts child_pid }
exit
end
Process.setsid
end
=20
start_daemon
=20
class MyClass
def files
%w(test1 test2)
end
end
=20
DRb.start_service nil, MyClass.new
=20
puts DRb.uri
File.open(__FILE__+".uri", "w") { |f| f.puts DRb.uri }
puts "Server started"
DRb.thread.join
=20
% cat simple-client.rb
require 'drb'
DRb.start_service
=20
server =3D File.read("simple-server.rb.uri").strip
puts "Connecting to #{server}"
=20
begin
robj =3D DRbObject.new nil, server
p robj
p robj.object_id
p robj.files
=20
rescue DRb::DRbConnError =3D> err
puts "No response from server"
puts err
end
=20
% ruby simple-server.rb
druby://cheetah.local:49506
Server started
=20
% ruby simple-client.rb
Connecting to druby://cheetah.local:49506
#<DRb::DRbObject:0xb257c @ref=3Dnil, @uri=3D"druby://cheetah.local:4950= 6">
365246
["test1", "test2"]
=20
The last line takes about a minute to be printed.
=20

I don't know, but:

$ time ruby simple-client.rb=20
Connecting to druby://chad-fowlers-computer.local:51624
#<DRb::DRbObject:0x25639c
@uri=3D"druby://chad-fowlers-computer.local:51624", @ref=3Dnil>
1225166
["test1", "test2"]

real 0m0.215s
user 0m0.030s
sys 0m0.017s

--=20

Chad Fowler
http://chadfowler.com
http://rubycentral.org=20
http://rubygarden.org=20
http://rubygems.rubyforge.org (over 300,000 gems served!)
 
D

Dick Davies

* Jim Freeze said:
Ok, I'm stumped. I have a simple drb example, and it is
taking about 1 minute to get the value of an array with
two items in it.

I'd guess DNS. check your forward and reverse for both the client
and the server.
 
J

Jim Freeze

* Chad Fowler said:
$ time ruby simple-client.rb
Connecting to druby://chad-fowlers-computer.local:51624
#<DRb::DRbObject:0x25639c
@uri="druby://chad-fowlers-computer.local:51624", @ref=nil>
1225166
["test1", "test2"]

real 0m0.215s
user 0m0.030s
sys 0m0.017s

Hmm, interesting. That used to work for me. It is probably DNS
related like Dick Davies mentioned, but I don't know how
to debug it yet. When I use a fixed address and port (e.g
localhost:2000), it works as yours.
 
J

Jim Freeze

* Dick Davies said:
I'd guess DNS. check your forward and reverse for both the client
and the server.

That is what I was thinking too, but then I ran it on a different
machine, and I get a no response error instead of a delayed result.

In the two cases below I use

DRb.start_service nil, obj

and

DRb.start_service dri, obj

where dri is the value originally picked by DRb itself:

"druby://rabbit:50827"

# start the server - let drb decide
% ruby drb.server
URI: 'druby://rabbit:50827'
I am server

# run the client
% ruby drb.client
#<DRb::DRbObject:0x821d804 @uri="druby://rabbit:50827", @ref=nil>
68217858
No response from server
druby://rabbit:50827 - #<Errno::ECONNREFUSED: Connection refused -
connect(2)>

# kill the old server, and manually do start_service at the previous dri:
% ruby drb.server
URI: 'druby://rabbit:50827'
I am server

% ruby drb.client
#<DRb::DRbObject:0x821d804 @uri="druby://rabbit:50827", @ref=nil>
68217858
["test1", "test2"]
# it works


So, why does the client fail if the server is running at the same
address. The only difference is that I set the address explicitly
or I let DRb choose the address.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads

trying to get drb to work ... 0
drb load limit 3
DRB class in array 7
drb application in bots 0
DRb and ActiveRecord 3
drb question 1
DRB Program Error 2
DRb::DRbBadScheme when using drbunix sockets, why? 3

Members online

Forum statistics

Threads
473,962
Messages
2,570,134
Members
46,690
Latest member
MacGyver

Latest Threads

Top