Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow nginx startup without doing initial DNS lookup #76

Open
nicholaschiasson opened this issue May 19, 2022 · 2 comments
Open

Allow nginx startup without doing initial DNS lookup #76

nicholaschiasson opened this issue May 19, 2022 · 2 comments
Labels
enhancement New feature or request

Comments

@nicholaschiasson
Copy link
Owner

We should support a flag per jdomain instance indicating if we explicitly want nginx to do the DNS lookup or not on startup.

This has implications on memory management of course, but this could be a very important improvement.

Currently, the way nginx is forced to do a DNS lookup for each jdomain occurrence on startup, the startup time can become very very excessively long if the nginx config includes many jdomain directives (as is the case in my own production config now...).

If we were to allow nginx to start without doing the initial lookup, then nginx could start up very snappy as it usually does, and defer the lookups to later. This is effectively taking the fallback (backup server, as of jdomain 1.0) mechanism to the next step, so I think it shouldn't be that difficult to implement.

@nicholaschiasson nicholaschiasson added the enhancement New feature or request label May 19, 2022
@atomsnc
Copy link

atomsnc commented May 19, 2022

I think easiest way would be to create a new status state INIT and assign that to jdomains that have variable defer set.
Skip ngx_parse_url part on those during configuration load and set them as up with dummy values.

When we hit ngx_http_upstream_init_jdomain_peer, original init_peer will sometime send as deferred ones since it thinks they are up. We can do the usual and start DNS resolution for all instances like we do now and return NGX_ERROR at very end if the peer sent to us had INIT set.

One of the these might happen after that (I think these are all?)

  1. If we have an upstream with backup variable, that might get called if there is nothing else or all others are down as well.
  2. Nothing is found and client gets server or upstream error.

@splitice
Copy link
Contributor

We ran into this. Worked around it with a local dns cache.

Doesnt help on first server start, but subsequent reloads (which were the problem) are significantly improved. Doesnt help however in the case of low ttl (i.e 1s) or some DNS failure codes.

An init state makes sense to me as long as configuration complete can continue to block on DNS lookup. This could allow for parallel lookup and the continuation of configuration parsing and loading. Not sure however if this is possible as the nginx event loop isnt available AFAIK during configuration startup.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

3 participants