Saving 100 terabytes of memory by optimizing 1.1.1.1's DNS cache
Big Pineapple, the platform behind 1.1.1.1 and other Cloudflare DNS services, optimizes its DNS cache to save memory. The cache stores over 250 billion entries, and each entry consumes a significant amount of memory. By making changes to how cache entries are stored, the platform reduces memory usage by over 50%, freeing up roughly 100 terabytes of memory across its fleet.
Additionally, the optimizations improve cache throughput by 43% and reduce lookup latency by 19%. The cache stores key-value pairs, with the key identifying the queried item and the value containing the DNS response and metadata. The optimizations include replacing Vec and String fields with Box[T] and Box[str] to eliminate unnecessary capacity fields and reduce heap memory waste.
Additionally, record owners are dropped when possible, and name compression is used to avoid redundancies. These changes result in substantial memory savings across the cache entries, improving both memory usage and performance.
Written by urgent.news from Hacker News's reporting — not their text. Machine-written — may contain errors; check the original before relying on it.