Mercurial > hg > nginx-quic
comparison src/core/ngx_resolver.c @ 6366:2e5c027f2a98
Resolver: per-request DNS server balancer.
Previously, a global server balancer was used to assign the next DNS server to
send a query to. That could lead to a non-uniform distribution of servers per
request. A request could be assigned to the same dead server several times in a
row and wait longer for a valid server or even time out without being processed.
Now each query is sent to all servers sequentially in a circle until a
response is received or timeout expires. Initial server for each request is
still globally balanced.
author | Roman Arutyunyan <arut@nginx.com> |
---|---|
date | Thu, 28 Jan 2016 15:28:20 +0300 |
parents | d35b4d590b2d |
children | 5a16d40c63de |
comparison
equal
deleted
inserted
replaced
6365:d35b4d590b2d | 6366:2e5c027f2a98 |
---|---|
683 } while (ctx); | 683 } while (ctx); |
684 | 684 |
685 return NGX_OK; | 685 return NGX_OK; |
686 } | 686 } |
687 | 687 |
688 rn->last_connection = r->last_connection++; | |
689 if (r->last_connection == r->connections.nelts) { | |
690 r->last_connection = 0; | |
691 } | |
692 | |
688 rn->naddrs = (u_short) -1; | 693 rn->naddrs = (u_short) -1; |
689 #if (NGX_HAVE_INET6) | 694 #if (NGX_HAVE_INET6) |
690 rn->naddrs6 = r->ipv6 ? (u_short) -1 : 0; | 695 rn->naddrs6 = r->ipv6 ? (u_short) -1 : 0; |
691 #endif | 696 #endif |
692 | 697 |
895 | 900 |
896 if (ngx_resolver_create_addr_query(r, rn, &ctx->addr) != NGX_OK) { | 901 if (ngx_resolver_create_addr_query(r, rn, &ctx->addr) != NGX_OK) { |
897 goto failed; | 902 goto failed; |
898 } | 903 } |
899 | 904 |
905 rn->last_connection = r->last_connection++; | |
906 if (r->last_connection == r->connections.nelts) { | |
907 r->last_connection = 0; | |
908 } | |
909 | |
900 rn->naddrs = (u_short) -1; | 910 rn->naddrs = (u_short) -1; |
901 #if (NGX_HAVE_INET6) | 911 #if (NGX_HAVE_INET6) |
902 rn->naddrs6 = (u_short) -1; | 912 rn->naddrs6 = (u_short) -1; |
903 #endif | 913 #endif |
904 | 914 |
1096 { | 1106 { |
1097 ssize_t n; | 1107 ssize_t n; |
1098 ngx_resolver_connection_t *rec; | 1108 ngx_resolver_connection_t *rec; |
1099 | 1109 |
1100 rec = r->connections.elts; | 1110 rec = r->connections.elts; |
1101 | 1111 rec = &rec[rn->last_connection]; |
1102 rec = &rec[r->last_connection++]; | |
1103 if (r->last_connection == r->connections.nelts) { | |
1104 r->last_connection = 0; | |
1105 } | |
1106 | 1112 |
1107 if (rec->udp == NULL) { | 1113 if (rec->udp == NULL) { |
1108 | 1114 |
1109 rec->log = *r->log; | 1115 rec->log = *r->log; |
1110 rec->log.handler = ngx_resolver_log_error; | 1116 rec->log.handler = ngx_resolver_log_error; |
1241 (size_t) rn->nlen, rn->name, rn->waiting); | 1247 (size_t) rn->nlen, rn->name, rn->waiting); |
1242 | 1248 |
1243 ngx_queue_remove(q); | 1249 ngx_queue_remove(q); |
1244 | 1250 |
1245 if (rn->waiting) { | 1251 if (rn->waiting) { |
1252 | |
1253 if (++rn->last_connection == r->connections.nelts) { | |
1254 rn->last_connection = 0; | |
1255 } | |
1246 | 1256 |
1247 (void) ngx_resolver_send_query(r, rn); | 1257 (void) ngx_resolver_send_query(r, rn); |
1248 | 1258 |
1249 rn->expire = now + r->resend_timeout; | 1259 rn->expire = now + r->resend_timeout; |
1250 | 1260 |