Why is this DRb code so slow?

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.

···

--
Jim Freeze
Ruby: I can explain it to ya but I can't understand it fer ya.

I don't know, but:

$ 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

···

On 5/15/05, Jim Freeze <jim@freeze.org> wrote:

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.

--

Chad Fowler
http://chadfowler.com

http://rubygems.rubyforge.org (over 300,000 gems served!)

* Jim Freeze <jim@freeze.org> [0501 16:01]:

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.

···

--
'Bender, Ship, stop arguing or I'll come back there and change
your opinions manually.'
    -- Leela
Rasputin :: Jack of All Trades - Master of Nuns

* Chad Fowler <chadfowler@gmail.com> [2005-05-16 01:51:49 +0900]:

$ 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.

···

--
Jim Freeze
Ruby: I can explain it to ya but I can't understand it fer ya.

* Dick Davies <rasputnik@hellooperator.net> [2005-05-16 02:45:29 +0900]:

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.

···

--
Jim Freeze
Ruby: I can explain it to ya but I can't understand it fer ya.