Why is this DRb code so slow?

Discussion in 'Ruby' started by Jim Freeze, May 15, 2005.

  1. Jim Freeze

    Jim Freeze Guest

    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.
    Jim Freeze, May 15, 2005
    #1
    1. Advertising

  2. Jim Freeze

    Chad Fowler Guest

    On 5/15/05, Jim Freeze <> 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.
    >=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!)
    Chad Fowler, May 15, 2005
    #2
    1. Advertising

  3. Jim Freeze

    Dick Davies Guest

    * Jim Freeze <> [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
    Dick Davies, May 15, 2005
    #3
  4. Jim Freeze

    Jim Freeze Guest

    * Chad Fowler <> [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.
    Jim Freeze, May 15, 2005
    #4
  5. Jim Freeze

    Jim Freeze Guest

    * Dick Davies <> [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.
    Jim Freeze, May 15, 2005
    #5
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Mr. SweatyFinger
    Replies:
    2
    Views:
    1,739
    Smokey Grindel
    Dec 2, 2006
  2. Miles Keaton
    Replies:
    3
    Views:
    170
    Miles Keaton
    Mar 30, 2005
  3. Kirk Haines

    More DRb; SSL & DRB & errors

    Kirk Haines, Jul 1, 2005, in forum: Ruby
    Replies:
    0
    Views:
    115
    Kirk Haines
    Jul 1, 2005
  4. J. Wook
    Replies:
    16
    Views:
    270
    Robert Klemme
    May 16, 2007
  5. Ittay Dror
    Replies:
    1
    Views:
    121
    Ittay Dror
    Oct 21, 2008
Loading...

Share This Page