pymumu / smartdns

A local DNS server to obtain the fastest website IP for the best Internet experience, support DoT, DoH. 一个本地DNS服务器,获取最快的网站IP,获得最佳上网体验,支持DoH,DoT。
https://pymumu.github.io/smartdns/
GNU General Public License v3.0
7.92k stars 1.05k forks source link

什麼狀況緩存紀錄會被踢掉?:serve-expired-ttl 0 #1729

Open kousyougi opened 2 months ago

kousyougi commented 2 months ago

问题现象
每天離峰時段重啟時發現緩存只有100KB。但尖峰時段重啟時,看到緩存有2MB

請問在serve-expired-ttl 0的設置下,緩存會一直變大,大到我設置的cache-size值嗎? 有什麼設置是會把緩存的域名踢掉的嗎?

涉及的配置(注意去除个人相关信息) rr-ttl-min 60 rr-ttl-max 3600 rr-ttl-reply-max 60 cache-size 20000 cache-persist yes cache-file /tmp/smartdns.cache cache-checkpoint-time 0 prefetch-domain yes serve-expired yes serve-expired-ttl 0 serve-expired-reply-ttl 2 serve-expired-prefetch-time 14400

PikuZheng commented 2 months ago

理论上缓存会一直增长直到达到cache-size。但受内存可用空间影响,可能有更小的限制。实际使用中不会有那么多域名查询,一般不会达到上限。 serve-expired-ttl 0 我理解就相当于serve-expired no。但由于prefetch-domain yes,在ttl降到0之前会重新查询,所以会一直ttl>0,直到一段时间内没有被下游查询,不触发预读

kousyougi commented 2 months ago

理论上缓存会一直增长直到达到cache-size。但受内存可用空间影响,可能有更小的限制。实际使用中不会有那么多域名查询,一般不会达到上限。 serve-expired-ttl 0 我理解就相当于serve-expired no。但由于prefetch-domain yes,在ttl降到0之前会重新查询,所以会一直ttl>0,直到一段时间内没有被下游查询,不触发预读

https://pymumu.github.io/smartdns/configuration/ 這邊寫 serve-expired-ttl :0 表示停用超时

這邊的敘述寫 0 表示停用超时 我以為是 serve-expired-ttl 無限大的意思。 我測測看把serve-expired-ttl 設到大一點的值,看看緩存大小會不會有我預期的反應。 謝謝

pymumu commented 2 months ago

代码有BUG,修改了

kousyougi commented 2 months ago

我测试了新版。跑了一天。设定 serve-expired-ttl 0 。cache好像还是没有持续膨胀。 serve-expired-ttl 设定 604800时cache有在膨胀。

PikuZheng commented 2 months ago

我测试了新版。跑了一天。设定 serve-expired-ttl 0 。cache好像还是没有持续膨胀。 serve-expired-ttl 设定 604800时cache有在膨胀。

还有一种可能 就是有大量域名只被查询了一次 有些系统或软件会发起很多不存在的域名来实现一些探测的目的 可以比较一下大缓存和小缓存中域名的差别 看有没有什么规律

pymumu commented 2 months ago

重新修改了一下