Repository navigation
Replies: 1 comment
|
Thanks. This added and will be release in v1.9.0 |
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Would you consider adding an optional stale-while-revalidate mode for expired cache entries?
As I understand current implementation, SDNS intentionally treats
serve_staleprimarily as reliability feature rather than latency optimisation:That design makes sense, and I can understand why SDNS would prefer fresh data whenever resolution remains possible.
What I would like is an additional opt-in behaviour where, if SDNS already has an expired entry considered safe to serve stale, it can return that response immediately and refresh it asynchronously:
I would not suggest changing existing behaviour or making this default. This would be additional policy for deployments where predictable DNS latency is more important than always waiting for fresh answer.
Why I think this is useful
SDNS already has
prefetch, which provides very similar behaviour while entry is still valid.For example, with:
and upstream TTL of 300 seconds:
This works well for frequently queried names.
There is, however, a gap when no request arrives during prefetch window:
If nothing queries name between 270 and 300 seconds, prefetch never runs.
When client then asks at 305 seconds, SDNS has recently expired cached answer available, but client waits for normal recursive resolution before receiving response.
That first query after expiry can therefore have substantially different latency from surrounding cache hits.
Example
Imagine name with 5-minute TTL that application accesses every 5–10 minutes.
It is not hot enough to reliably hit prefetch window.
Current behaviour is roughly:
With stale-while-revalidate:
This would make latency much more predictable for intermittently accessed names.
Difference from existing
serve_staleI realise this is somewhat different from apparent intention behind SDNS's current stale implementation.
Current
serve_staleseems designed around:That is reasonable default.
Behaviour I am describing makes different trade-off:
Both policies seem useful depending on deployment.
For example:
I would therefore prefer this to be explicit option rather than changing what
serve_stalecurrently means.Why not just increase
prefetch?Increasing
prefetchhelps, but does not completely solve this case.For example:
makes refresh window much larger, so intermittently used name is more likely to receive query before expiry.
However, higher prefetch values also cause hot records to be refreshed significantly earlier.
For 300-second TTL:
For frequently queried records this can substantially increase upstream refresh traffic.
It also still cannot guarantee that query occurs during prefetch window.
Prefetch and stale-while-revalidate therefore solve slightly different problems:
They seem complementary rather than interchangeable.
Possible configuration
Something along these lines could preserve existing semantics:
Where
failureremains current behaviour.Alternative mode:
With:
Naming could obviously differ; main point is making behaviour explicitly opt-in.
Existing safeguards should still apply
I would not expect this mode to mean "return any expired entry".
Ideally it would use same stale eligibility checks SDNS already applies today.
For example, whatever existing protections apply around:
Those should remain unchanged.
Only point at which already eligible stale response is returned would differ.
Reusing existing prefetch machinery
From looking through cache code, SDNS already appears to have much of machinery needed for asynchronous refresh because of prefetch:
There also appears to be existing protection against duplicate refreshes and against late background refresh blindly replacing newer cache entry.
That makes me wonder whether immediate stale mode could reuse much of prefetch infrastructure rather than requiring separate refresh mechanism.
Implementation details are obviously better decided by someone familiar with resolver internals, but architecturally operations seem closely related:
Main difference is whether cached response still has authoritative TTL remaining.
Benefits
Lower tail latency
Normal cache hits are extremely fast, while first query after expiration may require complete recursive resolution.
Immediate stale serving removes much of that latency discontinuity.
More predictable application behaviour
DNS is often on critical path before TCP/TLS/application connection setup.
Small number of cold cache expirations can therefore show up as application latency even when DNS resolver itself is otherwise performing well.
This mode would allow operators to optimise for predictable response time.
Better behaviour for intermittently queried names
Prefetch naturally favours hot names.
Stale-while-revalidate particularly helps names that are queried often enough for cache usefulness but not often enough to reliably trigger prefetch.
Avoids needing aggressive prefetch values
Operators interested in avoiding post-expiry latency would not need to expand prefetch window purely to increase chance that refresh occurs before expiration.
This could reduce unnecessary upstream refresh traffic.
No behaviour change for existing users
If current behaviour remains default, deployments that prioritise freshness continue to operate exactly as today.
Users would have to deliberately select latency-oriented behaviour.
Trade-off
Obvious cost is that
immediatemode deliberately increases chance that client receives data past authoritative TTL even though fresh answer could potentially have been obtained.That is meaningful semantic difference, which is why I think it should be optional.
Operator would effectively choose between:
and:
Neither policy is universally better; they optimise for different requirements.
Overall request
Would you consider supporting optional stale-while-revalidate / immediate stale mode while retaining existing failure-only stale behaviour as default?
My main use case is eliminating latency spike on first query after cache expiry for records that are not queried frequently enough to trigger prefetch reliably.
I like conservative intention behind SDNS's existing
serve_stalebehaviour and would not want this feature to change that default. It would instead give operators explicit choice when they are willing to trade some freshness for lower and more predictable query latency.All reactions