Project

General

Profile

Actions

Bug #496

closed

DRb.start_service(nil) is very slow

Added by hongli (Hongli Lai) about 16 years ago. Updated over 13 years ago.

Status:
Closed
Target version:
ruby -v:
-
Backport:
[ruby-core:18381]

Description

=begin
On some systems - such as mine - DRB.start_service(nil) is very slow. This is caused by the fact that DRb.open_server calls TCPServer.open(nil, 0).addr[1]. On my system, this takes about 3 seconds, and during those 3 seconds there is 0% CPU usage.

I suspect it has got something to do with the fact that retrieving the port of a server socket that's bound to 0.0.0.0 is for some unknown reason very slow.

The problem can be fixed by replacing the following line in drb.rb

uri = 'druby://:0' unless uri

with:

uri = 'druby://localhost:0' unless uri

This does not violate DRb.start_service's contract, because a nil indicates that it will bind to the default local host name.

The following monkeypatch works around the issue:

module DRb
class << self
alias orig_start_service start_service
end

 def self.start_service(uri = nil, front = nil, config = nil)
   if uri.nil?
     orig_start_service("druby://localhost:0", front, config)
   else
     orig_start_service(uri, front, config)
   end
 end

end
=end


Related issues 1 (0 open1 closed)

Related to Ruby master - Feature #1811: Default BasicSocket.do_not_reverse_lookup to trueClosednobu (Nobuyoshi Nakada)07/23/2009Actions
Actions #1

Updated by candlerb (Brian Candler) about 16 years ago

=begin
I suspect a DNS/hostname resolution problem on your system.

Looking at 1.8.6p114, notice that DRbTCPSocket.getservername first calls Socket.gethostname to get the hostname, then calls Socket.gethostbyname which does both forward and reverse name resolution, presumably to map to a "canonical" name. Then DRbTCPSocket.open_server_inaddr_any also calls Socket.getaddrinfo, although it discards the results apart from using them to decide whether to bind to IPv4, IPv6, or both.

Try the following in irb - how long does each step take?

{{{
require 'socket'
h1 = Socket.gethostname
h2 = Socket.gethostbyname(h1)[0]
Socket.getaddrinfo(h2, nil, Socket::AF_UNSPEC, Socket::SOCK_STREAM, 0, Socket::AI_PASSIVE)
}}}

If one of these steps is slow, you may be able to solve the problem by adding an entry in /etc/resolv.conf to map your hostname to your primary interface IP.

=end

Actions #2

Updated by hongli (Hongli Lai) about 16 years ago

=begin
All of those steps finish instantaneously.

I'm on Ubuntu 8.04.
=end

Actions #3

Updated by candlerb (Brian Candler) about 16 years ago

=begin
OK, how about this:

require 'socket'
t = TCPServer.new("", nil)
t.addr
t.addr

Socket.do_not_reverse_lookup=true
t.addr

On my machine, the first 't.addr' invocations take about 5 seconds. The last one is instant. I believe this is because of the delay looking up 0.0.0.0 in the DNS.

=end

Actions #4

Updated by hongli (Hongli Lai) about 16 years ago

=begin
The last t.addr is instant for me as well.
=end

Actions #5

Updated by hongli (Hongli Lai) almost 16 years ago

=begin
Any update on this? Is my proposed fix acceptable?
=end

Actions #6

Updated by rogerdpack (Roger Pack) almost 16 years ago

=begin
Sounds like the problem is that
require 'socket'
t = TCPServer.new("", nil)
t.addr

is slow, is that the root of the problem?
-=r
=end

Actions #7

Updated by shyouhei (Shyouhei Urabe) almost 16 years ago

  • Assignee set to seki (Masatoshi Seki)

=begin

=end

Actions #8

Updated by marcandre (Marc-Andre Lafortune) about 15 years ago

  • Category set to lib
  • ruby -v set to -

=begin

=end

Actions #9

Updated by mame (Yusuke Endoh) over 14 years ago

  • Status changed from Open to Feedback
  • Target version set to 1.9.2

=begin
Hi,

I cannot reproduce the issue with trunk on Linux.
Does this still reproduce?
Could you elaborate your platform and network configuration?

--
Yusuke Endoh
=end

Actions #10

Updated by rogerdpack (Roger Pack) over 14 years ago

=begin
This might be fixed now, since Socket.do_not_reverse_lookup defaults to true now in trunk (maybe somebody should note that in the NEWS?)
Thanks.
-rp
=end

Actions #11

Updated by mame (Yusuke Endoh) over 14 years ago

  • Status changed from Feedback to Closed

=begin

=end

Actions

Also available in: Atom PDF

Like0
Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0