-
Notifications
You must be signed in to change notification settings - Fork 4.7k
feat(dns): add optimistic caching #5237
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
base: main
Are you sure you want to change the base?
Conversation
|
个人感觉过度折腾这玩意除了增加这玩意没什么实际用途 |
|
确实可以减少几十到数百毫秒的延迟,特别是一些 ttl 贼低的 cdn 比如 Akamai 我以前都是硬编码魔改着用的,没什么副作用 刚看到 @SukkaW 发文说 xray 和 sing-box 都没有乐观缓存 要不是因为太菜实在看不懂 sing-box 的配置文件,高低也得给他糊一个 |
|
I intentionally added +1 to TTL(if 0<untilExpire<1), because the returned-IP-list in routing (when using "IPOnDemand"/"IPIfNonMatch") should be same as returned-IP-list in outbound (when targetStrategy is "ForcrIP"/'UseIP"), the reasons have already been discussed. Anyway, this is a bit of an obsession, because the probability of TTL expire in outbound-use-of-built-in-dns (but not expired in routing-use-of-built-in-dns) is very low and it is nearly impossible (even adding 1ms (if 0<untilExpire<1ms) is enough). Also it is still possible we have different IPs in routing and outbound (for example DNS1 is not available in routing and it use DNS2, but DNS1 is available for outbound) The correct way is to save router-result-IPs in ctx, and use it in outbound if we have As a result, you can remove it, np. /// Also, cache_controller>updateIP function need some changes after allowing TTL to be negative. Xray-core/app/dns/cache_controller.go Lines 105 to 106 in b69a376
and Xray-core/app/dns/cache_controller.go Lines 97 to 98 in b69a376
should change to: |
|
以前你的版本遇到 ttl 问题是因为:
至于你上面提到的问题,实际上并不存在,因为你没有理解这块逻辑 |
|
suppose we don't want to use optimistic-cache and suppose A-ttl is expired but AAAA-ttl is not expired (before calling the code request for both A and AAAA ips (you can check the code) as a result, we should wait for new-v4-ips, because old-v4-IPs was outdated before calling /// instead of changing the code to Xray-core/app/dns/cache_controller.go Lines 104 to 109 in b69a376
and Xray-core/app/dns/cache_controller.go Lines 96 to 101 in b69a376
/// In short, it is not important A-ttl expired during returning-new-AAAA-result, we can still use it even if optimistic-cache is but if a record expired before calling |
d4276fb to
61f2f8b
Compare
|
大哥你想玩能不能 fork 一份在自己仓库魔改 |
61f2f8b to
cd4f1cd
Compare
|
some of my changes is related to your code and fix your code. if i open new PR, it would be many conflicts-codes. |
|
before revert please read my code carefully, and if you have any question i can answer. |
|
|
|
首先你至少本地测试跑通了再提交,更何况这是别人的 PR 其次这份 PR 在我这里工作得很好,已经好几周了没发现什么问题 你上面讲的那一长串 “BUG” 我没理解 |
|
it is impossible to open new PR, there are many nested-codes. I took the time to read your code, please take the time to read mine too. this is yourPR+patch please read it first: https://github.com/XTLS/Xray-core/tree/optimistic-dns-with-patch /// in the patch i add these optimization:
/// if you don't understand why i did these, please read #5237 (comment) /// Anyway this PR alone has this: #5237 (comment) problem and should not be merged. |
|
你说的问题已经修复了, 因为你的 patch 会导致高命中率本应积极更新的域名得不到主动更新 接下来我会 review 你的每一个 PR |
|
乐观缓存提前返回导致上下文被取消,算bug吗? |
|
@j2rong4cn 你这是 fork 一份干了个啥,我手机不方便看 乐观缓存提前返回不应该取消并发查询的 ctx 因为这会影响到预热效果 可以看下我之前修复的 commit 在并行查询请求那直接包一层把 ctx.cancel 传播链截断,同时不能影响 ctx 携带的 attr |
不是手动取消,是响应结束,ctx被取消,导致乐观缓存有效期内无法更新缓存 |
|
是的,就是这个意思 |
我没合并 并行查询的pr,原来修复了😂 |
|
不过这提醒了我 乐观缓存这块也得处理 |
|
@j2rong4cn |
我觉这样改比较好 j2rong4cn@2baa33e |
|
@j2rong4cn 我 golang 是散装的 我不理解为啥你那样包个 valueCtx 能实现截断 cancel 的目的 我看了它没有 override Deadline() Done() Err() 这些 |
这是新的一版j2rong4cn@2baa33e 用的context.WithoutCancel Xray-core/app/dns/nameserver.go Line 231 in 2baa33e
|
看到了,你这样的确比较好 功能上两种修复是等价的,我都 rebase 完了就这样吧先 |
j2rong4cn@591674b 更激进一点,只在刷新乐观缓存时重新设置Deadline |

再也不能续一秒了{ // 示例配置: 过期时间不超过 48 小时的记录,先返回缓存再刷新 "dns": { "servers": [ { "address": "8.8.8.8", "serveStale": true, // 开启乐观缓存 "serveExpiredTTL": 172800 // 默认为 nil 以继承自全局 }, "1.1.1.1" ], "serveStale": false, // 默认为 false 不开启 "serveExpiredTTL": 3600 // 默认为 0 永不过期 } }缓存重构(#5248)、乐观缓存(#5237)、并行查询(#5239)
三个 PR 相互冲突,如果全部接受得按这个顺序 merge
我好 rebase
另外,如果准备接受此 PR,但不接受缓存重构(#5248)的话
无法处理楼下 @j2rong4cn 提到的 BUG
因为我仅在 rebase #5248 的基础之上修复
实在是不想顶着恶心写过度冗余的代码
此 PR rebase 后的 diff
https://github.com/Meo597/Xray-core/compare/fix-p-dns-CacheCleanup..rebased-new-dns/optimistic-caching