Live data from Hacker News

Saving 100 terabytes of memory by optimizing 1.1.1.1's DNS cache

blog.cloudflare.com

191–200 of 304 posts

Re: Saving 100 terabytes of memory by optimizing 1.1.1.1's DNS cache

#191
post #175

Earlier quoted context omitted.

> The company is wildly popular and any service launched is going to have a lot of traffic and a lot of attacks right away. Doesn't this also inform you that your cache will be very large, so you shouldn't use growable structures with slack space when cache entries won't grow; slop space reduces the size of your cache. And also that the query volume will be high so the cached data should require as little work as pos…

RAM is cheap. I'd find myself far far more concerned with: * unbounded growth of the cache and properly invalidating after TTL expires (a few GBs of slop is nothing on a server with 64 or more GBs of ram, unbounded growth is a problem). * making sure the DNS implementation works correctly on both the serving side and recursive resolution side. * What strategy is best for deduping recursive requests across machines (i…

> The biggest performance gains cloudflare can provide in Web and DNS cache come from a cache hit.

Using twice as much ram per cache entry makes the cache half as large, assuming your cache is bounded by ram, unless the queried, unexpired result set is less than the ram budget (which I would tend to doubt... lots of randomized queries out there; maybe I'm wrong if the cache size dropped).

When you're storing billions of records, it makes sense to spend a few minutes to consider how they're used and make a good choice about how to store them.

When you're getting a cache hit tons of times per second, it makes sense to consider every step and which ones don't need to happen every time. You have to consider every step while you're pursing correctness anyway, so might as well have the performance lens active too.

I'm not asking for heroic optimization: I didn't ask for vectorized stuff or kernel/nic offloading or kernel bypass networking... Just you have to use some data structures, you might as well not use ones that are expensive for features you don't need; and you have to store something in your cache, you may as well store something that requires less munging on the way out.

If this were a small local cache, that didn't want to use something already existing like unbound for some reason then yeah, data structures don't make a huge difference, extra marshalling doesn't make a huge difference, just don't reimplement all the CVEs that BIND had in the 90s. But if you're going to allocate 100 TB of ram, make it count. Even if you do use twice the ram but you get value from it, maybe that's fine... I've run wacky systems with bloated storage when there was a benefit. Vec doesn't give any value over a Box in this case; convenience or lazyness would be fine except that the sheer number of objects makes it worth the few minutes it takes to do something better.

Re: Saving 100 terabytes of memory by optimizing 1.1.1.1's DNS cache

#192
This reminds me how you can save a bunch of bytes just by making sure your structs are aligned. In go for example:

  type Wasteful struct {
    a int16
    b int
    c byte
  }

  type Aligned struct {
    b int
    a int16
    c byte
  }

Will have sizes of 24bytes and 16bytes (on a 64bit system). Same data 8bytes more. If you are storing millions of those objects, then it adds up.

Re: Saving 100 terabytes of memory by optimizing 1.1.1.1's DNS cache

#193

Earlier quoted context omitted.

No, but if you didn’t, the internet wouldn’t really work all that well. It was the fact that participants, despite being independent, all agreed (either explicitly or implicitly) to adhere to the standards that it became a global network. If they hadn’t, the result would have been more of the same: independent networks that only had narrow interoperability at best. It’s a textbook example of how global cooperation ca…

It was the fact that adhering to the standard was in the best interest of each participant. When it isn't, they don't.

It's impossible to know how often participants chose to stick to the standards anyway despite it not being in their best interest. Do you have any specific examples?

Re: Saving 100 terabytes of memory by optimizing 1.1.1.1's DNS cache

#194

How much is this in euro or do we measure money in ram now?

Currently $15 per GB, he saved Cloudflare $1,500,000 and got exactly $0 bonus. He must really believe in cloudflare's vision (global enshittification). In related news, three times today Cloudflare told me that I'm a bot and shall not pass - not that it needs to check if I'm a bot before it lets me pass.

I saved an employer $4m/yr, entirely myself. I think I got a 10k bonus.

Re: Saving 100 terabytes of memory by optimizing 1.1.1.1's DNS cache

#195
post #23

One question the article doesn't answer is: why are they cacheing at all? If your cache is that big it isn't a cache. How much bigger is the dataset in question? There are 250 billion entries. Assuming 80/20, that implies 1.25 trillion records? What's the speed of service/response time relative to the data source? At that point it might be enough to replace your multiple caches with fewer in-RAM databases? It's an in…

> If your cache is that big it isn't a cache.

This is an incorrect statement. Caches do not have a requirement of being smaller than their source data set. CDN is an example of a cache that generally matches the size of the source data.

Re: Saving 100 terabytes of memory by optimizing 1.1.1.1's DNS cache

#196
post #68

This is the right way to deliver software. Produce working product first, validate the idea, stabilize the business, start generating profit, and then you can start optimizing your costs. In fact optimization is by far the easiest part of the process because there are many system programming experts on this HN thread who consider these optimizations to be trivial.

Or optimize a bit earlier and prevent having to scale out to a bazillion systems.

Remember that everything has an opportunity cost. Running a lot of servers might cost $10 million annually, but if the product team had to choose between a project that would recoup $5 million of that vs. an opportunity to earn $50 million ARR for the same amount of work, the logical answer would be obvious.

Re: Saving 100 terabytes of memory by optimizing 1.1.1.1's DNS cache

#197

This reminds me how you can save a bunch of bytes just by making sure your structs are aligned. In go for example: type Wasteful struct { a int16 b int c byte } type Aligned struct { b int a int16 c byte } Will have sizes of 24bytes and 16bytes (on a 64bit system). Same data 8bytes more. If you are storing millions of those objects, then it adds up.

Rust does that automatically unless you switch to the C layout.

In langages that don’t there’s a tension between memory use and human readability / consistency of the layout.

There are also other domains which can be affected e.g. databases, it’s a concern / issue when using postgres for instance as it uses aligned columns and stores them in schema order.

Re: Saving 100 terabytes of memory by optimizing 1.1.1.1's DNS cache

#198
The intermediate level Rust dogma is to try your hardest to avoid the heap, and to tear your hair out at the throne of monomorphization. While both are broadly true, it's articles like this that show that a single pointer (or call) indirection can sometimes be better.

Re: Saving 100 terabytes of memory by optimizing 1.1.1.1's DNS cache

#199
post #158

Earlier quoted context omitted.

You didn't read what I said. I mentioned acres of land. You normally don't have multiple acres of land in the suburbs.

Well then you didn't read parent's comment > is it possible to buy a reasonably nice home located in a reasonably nice amerikkkan city… for $300k in 2026? Who wants acreage? We want homes.

> is it possible to buy a reasonably nice home located in a reasonably nice amerikkkan city… for $300k in 2026?

What does "city" mean to you? For some, it's 500 people, or 5,000. For some, it's 5 million. Define that first. The US is a big place, and I know people that don't live within 50 miles of another human.

Otherwise:

https://www.zillow.com/homedetails/424-Olive-St-Kansas-City-...

4 bed, 3 bath, 1,580 sq ft, beautiful! $342,500, built in 1900.

https://www.zillow.com/homedetails/3508-N-College-Ave-Kansas...

4 bed, 4 bath, 2,295 sq ft, $365,000, built in 2022.

Re: Saving 100 terabytes of memory by optimizing 1.1.1.1's DNS cache

#200
One of my proudest professional moments was when me and three others managed to reduce memory load of the game Wavetale from 20+GiB to under 3GiB so we could port it to Nintendo Switch.

The 100 TiB number almost gives me vertigo. Though in this context it was "just" 50%

Post reply on HN