diff options
author | Mini Hawthorne <mini@f5.com> | 2023-07-12 12:20:45 -0700 |
---|---|---|
committer | Aleksei Bavshin <a.bavshin@f5.com> | 2024-11-07 07:57:42 -0800 |
commit | 29aec5720fdfc74dca8d99d5cf6dc0fcb4e4ce2f (patch) | |
tree | a04b9975051ba44f5dc7b1532b4d66f97de900a5 /src/stream/ngx_stream_upstream_zone_module.c | |
parent | ea4654550ab021b5576c03b708079e3ce3e5d9ed (diff) | |
download | nginx-29aec5720fdfc74dca8d99d5cf6dc0fcb4e4ce2f.tar.gz nginx-29aec5720fdfc74dca8d99d5cf6dc0fcb4e4ce2f.zip |
Upstream: copy upstream zone DNS valid time during config reload.
Previously, all upstream DNS entries would be immediately re-resolved
on config reload. With a large number of upstreams, this creates
a spike of DNS resolution requests. These spikes can overwhelm the
DNS server or cause drops on the network.
This patch retains the TTL of previous resolutions across reloads
by copying each upstream's name's expiry time across configuration
cycles. As a result, no additional resolutions are needed.
Diffstat (limited to 'src/stream/ngx_stream_upstream_zone_module.c')
-rw-r--r-- | src/stream/ngx_stream_upstream_zone_module.c | 12 |
1 files changed, 11 insertions, 1 deletions
diff --git a/src/stream/ngx_stream_upstream_zone_module.c b/src/stream/ngx_stream_upstream_zone_module.c index d92609feb..a6874dc33 100644 --- a/src/stream/ngx_stream_upstream_zone_module.c +++ b/src/stream/ngx_stream_upstream_zone_module.c @@ -542,6 +542,8 @@ ngx_stream_upstream_zone_preresolve(ngx_stream_upstream_rr_peer_t *resolve, peer->host = template->host; + template->host->valid = host->valid; + server = template->host->service.len ? &opeer->server : &template->server; @@ -623,6 +625,8 @@ ngx_stream_upstream_zone_remove_peer_locked( static ngx_int_t ngx_stream_upstream_zone_init_worker(ngx_cycle_t *cycle) { + time_t now; + ngx_msec_t timer; ngx_uint_t i; ngx_event_t *event; ngx_stream_upstream_rr_peer_t *peer; @@ -636,6 +640,7 @@ ngx_stream_upstream_zone_init_worker(ngx_cycle_t *cycle) return NGX_OK; } + now = ngx_time(); umcf = ngx_stream_cycle_get_module_main_conf(cycle, ngx_stream_upstream_module); @@ -672,7 +677,10 @@ ngx_stream_upstream_zone_init_worker(ngx_cycle_t *cycle) event->log = cycle->log; event->cancelable = 1; - ngx_add_timer(event, 1); + timer = (peer->host->valid > now) + ? (ngx_msec_t) 1000 * (peer->host->valid - now) : 1; + + ngx_add_timer(event, timer); } ngx_stream_upstream_rr_peers_unlock(peers); @@ -981,6 +989,8 @@ again: done: + host->valid = ctx->valid; + ngx_stream_upstream_rr_peers_unlock(peers); while (++i < ctx->naddrs) { |