Cloudflare DNS 省出 100TB 内存
推荐指数 68.0 NO. 016 · 2026.08.28
发布2026/08/27Score524Comments142
为什么值得看
Cloudflare 通过五轮内存结构优化,将单条 DNS 缓存条目 footprint 削减 50% 以上,全局释放约 100TB 内存,同时插入吞吐提升 43%、查询延迟降低 19%。对于需要处理海量 KV 数据的基础设施团队,这是内存效率与性能兼得的高价值工程参考。
编辑判断
这篇的精髓不在优化本身,而在"wasting a single byte costs 250GB"的规模化思维。很多团队做缓存设计时只测单机 QPS,忽略了字节级浪费在万节点集群的复利效应。
五个改动里最值得借鉴的是从指针密集型结构切到扁平化数组+索引编码,这其实是游戏引擎和嵌入式领域的老手法,但在高并发网络服务里复用得很少。如果你在做类似 Redis Cluster、特征存储、或实时推荐缓存的系统,可以重点看他们怎么平衡压缩率与随机访问速度。
另外 43% 的插入吞吐提升来自减少 allocation,这对 Go/Rust 团队尤其有启发——GC 压力往往比算法复杂度更先成为瓶颈。
社区反馈
意见分歧 117 条评论
核心争论:早期设计是否应追求内存最优,还是优先快速交付再按需优化
相关内容
How we saved 100 terabytes of memory by optimizing 1.1.1.1's DNS cache Cloudflare 通过五项优化将 DNS 缓存每项内存占用从 953 字节降至 420 字节,减少 56%,生产环境共节省 100TB 内存。 我们如何将 DNS 记录的建立速度提高了 4000 倍以上 Cloudflare 优化 DNS 区域构建流程,将完整构建时间从 34 秒降至 8 毫秒,性能提升 4250 倍,大幅减少资源使用。 什么是 Cloudflare 1.1.1.1 DNS解析器 1.1.1.1 不挖掘用户数据,日志 24 小时清除,支持查询名称最小化等隐私功能,依托全球网络成为最快递归 DNS 服务。
> Once we store a DNS response in the cache, however, we never modify it again. The capacity field serves no purpose, but still costs 8 bytes per Vec Were there no design discussions/reviews when the system was setup to catch trivial things like this?
it was working so no one thought to check
Premature optimization argument fits right in. Now that memory is up to 10x more expensive it is worth considering optimizing programs with large memory footprint.