[#70257] [Ruby trunk - Feature #11420] [Open] Introduce ID key table into MRI — ko1@...

Issue #11420 has been reported by Koichi Sasada.

11 messages 2015/08/06

[ruby-core:70377] [Ruby trunk - Bug #11443] DNS name resolution takes twice as long as it should when primary name server is unavailable

From: therealpatrobinson@...
Date: 2015-08-14 04:54:50 UTC
List: ruby-core #70377
Issue #11443 has been updated by Patrick Robinson.

Subject changed from DNS name resolution takes a twice as long as it should when primary name server is unavailable to DNS name resolution takes twice as long as it should when primary name server is unavailable
Description updated

----------------------------------------
Bug #11443: DNS name resolution takes twice as long as it should when primary name server is unavailable
https://bugs.ruby-lang.org/issues/11443#change-53781

* Author: Patrick Robinson
* Status: Open
* Priority: Normal
* Assignee: 
* ruby -v: ruby 2.2.2p95 (2015-04-13 revision 50295) [x86_64-linux]
* Backport: 2.0.0: UNKNOWN, 2.1: UNKNOWN, 2.2: UNKNOWN
----------------------------------------
On linux /etc/resolv.conf can be configured to set the timeout of a nameserver before trying the next one (defaults to 5 seconds). So in the event of a failed name server we expect the time taken to resolve a hostname will be timeout + query time. However testing shows it takes (2 * timeout) + query time. Example resolv.conf to replicate the problem of a failed name server:

~~~
nameserver 1.1.1.1
nameserver 8.8.8.8
nameserver 8.8.4.4
~~~

Example ruby code to test:

```
require 'net/protocol'
require 'uri'
require 'benchmark'
uri = URI.parse("http://google.com")
Benchmark.measure { TCPSocket.new(uri.host, uri.port) }.real
```

Example benchmark with a above resolv.conf:

```
irb(main):005:0> Benchmark.measure { TCPSocket.new(uri.host, uri.port) }.real
=> 10.593100978
```

Example benchmark with timeout set to 3 in resolv.conf (options timeout:3):

```
irb(main):005:0> Benchmark.measure { TCPSocket.new(uri.host, uri.port) }.real
=> 6.262138267
```

and without the invalid nameserver:

```
irb(main):005:0> Benchmark.measure { TCPSocket.new(uri.host, uri.port) }.real
=> 0.243385728
```

Example C code that proves the resolver is behaving as expected:

```
#include <stdio.h>
#include <netdb.h>

int main(int argc, char *argv[])
{
    struct hostent *hstnm;
    if (argc != 2) {
        fprintf(stderr, "usage: %s hostname\n", argv[0]);
        return 1;
    }
    hstnm = gethostbyname (argv[1]);
    if (!hstnm)
        return 1;
    printf ("Name: %s\n", hstnm->h_name);
    return 0;
}
```

Benchmark of C code with failed nameserver:

~~~
$ time ./gethostbyname google.com
Name: google.com

real	0m5.189s
user	0m0.000s
sys	0m0.000s
~~~

Benchmark of C code without failed nameserver:

~~~
$ time ./gethostbyname google.com
Name: google.com

real	0m0.040s
user	0m0.000s
sys	0m0.000s
~~~



-- 
https://bugs.ruby-lang.org/

In This Thread

Prev Next