This repository has been archived by the owner on Jul 11, 2023. It is now read-only.
perf(client) reduce amount of timers on init_worker #130
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
We end up scheduling 1 timer for each hostname on the init_worker phase. To fix it we are "deduplicating" timers created to resolve the same hostname for the asynchronous case. That is, we are reusing timers for DNS queries of the same hostname. If we have 6k targets, and all of the targets are "httpbin.org" there's no reason to create 6k timers per worker. Instead, we should just create a maximum of 3 timers for 3 DNS queries (default: 1 for SRV, 1 for A and 1 for CNAME) and don't schedule more timers than that to resolve the same hostname. We should only schedule more timers if we try to resolve different hostnames. And the approach we're using in the patch is: if the current nginx phase can't be blocked by a semaphore (which is the case of init_worker context, but not of timer context, for example), then we should not schedule more timers for the same hostname, we should just return the previous query so that the previous timers can be reutilized (in the init_worker phase, for example). Otherwise, if the current nginx phase can blocked by a semaphore, then we will just block and wait for the DNS query to complete (in the timer context, for example, and this hasn't changed). In a nutshell: we are reutilizing timers scheduled to resolve the same hostname.