Unbound: caching / prefetching of queries not working as expected

Hi all,

I try to bring my unbound in a state where it caches queries longer than the given TTL of them or (better) to prefetch before there TTL expires.

But min_ttl is quite restricted with a max of 300 and setting recursion to aggressive seems to not enable prefetch correctly (but I see it in the generated unbound.conf).

In any case, after TTL is expired, queries getting slow again.

Am I doing something wrong?

(newest OpenWrt release)

Thanks and best regards

Check unbound docs.

You probably need prefetch and serve-expired. But be careful, using serve-expired can lead to problems. I used it a few month without problems, but went back to DNSMASQ with a external resolver.

Hi Ahuse,

I tried prefetch already (it is set implicit by uci setting recursion to aggressive).

But it seems to have no effect, repeated queries are fast after the first one within the TTL. After it has expired, one query is slow again before the others start to get fast afterwards.

Did the prefetching work for you?

Best regards

Read the docs, prefetch does prefetching. You want serving expired entries and therefore you have to activate serve-expired.

I did and as written in the initial post I already enabled prefetching. But it isn't working as expected (first query slow, all following not) but fullfilling the expection only sometimes (first query slow, afterwards some fast, some slow, so not always prefetched/from cache).

Maybe there is some kind of heuristic/statistic in use enabling prefetching only if a query was repeated often enough?

Nevertheless, will have a look at the serve expired one.

Best regards

It is explained in the Docs.

With prefetch, Unbound tries to update a cached record (after first replying to the client) when the current TTL is within 10% of the original TTL value. The logic is similar to serve-expired: if a cached record is found and the record is within 10% of the TTL, it is returned to the client but Unbound continues resolving in order to update the record. Although prefetching comes with a small penalty of ~10% in traffic and load from the extra upstream queries, the cache is kept up-to-date, at least for popular queries.

The behavior you see regarding prefetching is expected. Just read this page in the docs.

Hi Ahuse,

this was exactly the missing part of the puzzle for me.:slight_smile: Don't know why I missed this page in the documentation.

This explains everything relevant for me.

Best regards

1 Like

Another way: If cache is never reused, then it is allowed to fade away. If a cache hit occurs, then a prefetch query is made just before TTL 0. Normal fetching will use the cache until TTL runs out, and then it becomes a un-cached query.

This topic was automatically closed 10 days after the last reply. New replies are no longer allowed.