Nginx performance using resolver

Hello

I have nginx setup to create the upstream on the fly.

if ($request_uri ~* “^/(.*)/resource”)
{
set $user $1;
proxy_pass http://$user.resource.domain.com:7600$request_uri;
break;
}

so here if the url is

http://domain.com/nginx/resource

nginx will send that to nginx.resource.domain.com:7600

I have setup bind on the same machine (with zone files) and have the
resolver set to 127.0.0.1;

Local digs (dig @127.0.0.1 nginx.resource.domain.com +short) take ms.

When I include the upstream with the ip, the passing is instant, when I
don’t have the upstream which forces the use of the resolver it take
over 30 seconds.

Has anyone seen this behavior ? I didn’t find much info on the resolver
declaration.

Also how do I tell the resolver to use the systems resolver method ?
So I want nginx to use whatever the OS uses (dns entries in resolv.conf
or hardcoded ips in /etc/hosts.

Cheers

Additional debug information when nginx does the lookups.

2009/02/04 23:11:09 [debug] 26566#0: resolver DNS response 19567 fl:8580
1/1/1/1
2009/02/04 23:11:09 [debug] 26566#0: resolver DNS response qt:1 cl:1
2009/02/04 23:11:09 [debug] 26566#0: resolver
qs:user1.resource.domain.com
2009/02/04 23:11:09 [debug] 26566#0: resolver naddrs:1 cname:00000000
2009/02/04 23:11:09 [debug] 26566#0: resolver expire
2009/02/04 23:11:14 [debug] 26566#0: resolver resend handler
2009/02/04 23:11:19 [debug] 26566#0: resolver DNS response 35063 fl:8580
1/1/1/1
2009/02/04 23:11:19 [debug] 26566#0: resolver DNS response qt:1 cl:1
2009/02/04 23:11:19 [debug] 26566#0: resolver
qs:user1.resource.domain.com
2009/02/04 23:11:19 [debug] 26566#0: resolver naddrs:1 cname:00000000
2009/02/04 23:11:19 [debug] 26566#0: resolver expire
2009/02/04 23:11:20 [debug] 26566#0: resolver expire
2009/02/04 23:11:21 [debug] 26566#0: resolver expire
2009/02/04 23:11:22 [debug] 26566#0: resolver DNS response 26656 fl:8580
1/1/1/1
2009/02/04 23:11:22 [debug] 26566#0: resolver DNS response qt:1 cl:1
2009/02/04 23:11:22 [debug] 26566#0: resolver
qs:user1.resource2.domain.com
2009/02/04 23:11:22 [debug] 26566#0: resolver naddrs:1 cname:00000000
2009/02/04 23:11:22 [debug] 26566#0: resolver expire
2009/02/04 23:11:27 [debug] 26566#0: resolver resend handler
2009/02/04 23:11:36 [debug] 26566#0: resolver expire
2009/02/04 23:11:37 [debug] 26566#0: resolver expire
2009/02/04 23:11:37 [debug] 26566#0: resolver expire

On Wed, Feb 04, 2009 at 11:10:19PM +0100, Nginx L. wrote:

     }

Local digs (dig @127.0.0.1 nginx.resource.domain.com +short) take ms.

When I include the upstream with the ip, the passing is instant, when I
don’t have the upstream which forces the use of the resolver it take
over 30 seconds.

resolver_timeout  2s;

Has anyone seen this behavior ? I didn’t find much info on the resolver
declaration.

Also how do I tell the resolver to use the systems resolver method ?
So I want nginx to use whatever the OS uses (dns entries in resolv.conf
or hardcoded ips in /etc/hosts.

Currently, you have to set up resolver address in configuraton.

On Thu, Feb 05, 2009 at 04:20:31PM +0100, Nginx L. wrote:

resolver_timeout  2s;

Does this expire the records the resolver knows about ?

No, this resolving timeout only.
The expiration time is currently hardcoded to 5 minutes.

If so , why would this help ?

Where can I find more documentation on this ?
If it doesn’t exists I’d like to contribute.

As I know, there is no English documentation on this.

resolver_timeout  2s;

Does this expire the records the resolver knows about ?
If so , why would this help ?

Where can I find more documentation on this ?
If it doesn’t exists I’d like to contribute.

Cheers

Igor S. wrote:

On Thu, Feb 05, 2009 at 04:20:31PM +0100, Nginx L. wrote:

resolver_timeout  2s;

Does this expire the records the resolver knows about ?

No, this resolving timeout only.
The expiration time is currently hardcoded to 5 minutes.

So this sets the resolver to timeout at a specific type of search ?

first it checks upstreams then dns , so does this set the timeout for
upstreams to 2s ? then the dns to 2s ?

Thanks.

If so , why would this help ?

Where can I find more documentation on this ?
If it doesn’t exists I’d like to contribute.

As I know, there is no English documentation on this.

Hello Igor

Is there a way to enter 2 dns server to use for resolving ?
Trying to add some redundancy there. If not I would have to have a vip
which hits X number of name servers.

Thanks

Igor S. wrote:

On Thu, Feb 05, 2009 at 06:57:16PM +0100, Nginx L. wrote:

So this sets the resolver to timeout at a specific type of search ?

first it checks upstreams then dns , so does this set the timeout for
upstreams to 2s ? then the dns to 2s ?

No, first nginx looks up a host in upstream’s. There is no timeout.
If the host is not defined as upstream, then nginx tests it as IP
address.
If the host is not IP address, then nginx tries to resolve the host.
The timeout is used here while resolving.

On Thu, Feb 05, 2009 at 06:57:16PM +0100, Nginx L. wrote:

So this sets the resolver to timeout at a specific type of search ?

first it checks upstreams then dns , so does this set the timeout for
upstreams to 2s ? then the dns to 2s ?

No, first nginx looks up a host in upstream’s. There is no timeout.
If the host is not defined as upstream, then nginx tests it as IP
address.
If the host is not IP address, then nginx tries to resolve the host.
The timeout is used here while resolving.

Why there is no possibility to use system resolver? Or there is?

Posted at Nginx Forum:

On Mon, Sep 28, 2009 at 06:05:39AM -0400, midenok wrote:

Why there is no possibility to use system resolver? Or there is?

What do you mean by the system resolver ?

On Sat, May 30, 2009 at 03:43:46AM +0200, Nginx L. wrote:

Hello Igor

Is there a way to enter 2 dns server to use for resolving ?
Trying to add some redundancy there. If not I would have to have a vip
which hits X number of name servers.

No, currently only single IP.

Hello!

On Mon, Sep 28, 2009 at 06:05:39AM -0400, midenok wrote:

Why there is no possibility to use system resolver? Or there is?

For resolving names at configuration stage nginx uses system
resolver. It isn’t possible to use system resolver during request
processing though, as system resolvers are usually blocking.

Maxim D.