diff options
author | Aleš Mrázek <ales.mrazek@nic.cz> | 2024-04-17 15:55:02 +0200 |
---|---|---|
committer | Aleš Mrázek <ales.mrazek@nic.cz> | 2024-04-22 12:43:52 +0200 |
commit | ee018de76f07d0e0da433913966708d01476aa48 (patch) | |
tree | 5abfa79aeb34af6191a9c478077233b767cdbc24 /modules | |
parent | modules: predict: prefetching expired records has been removed (diff) | |
download | knot-resolver-ee018de76f07d0e0da433913966708d01476aa48.tar.xz knot-resolver-ee018de76f07d0e0da433913966708d01476aa48.zip |
modules: prefetch: new module for prefetching expiring records
Diffstat (limited to 'modules')
-rw-r--r-- | modules/meson.build | 1 | ||||
-rw-r--r-- | modules/prefetch/README.rst | 18 | ||||
-rw-r--r-- | modules/prefetch/prefetch.lua | 21 |
3 files changed, 40 insertions, 0 deletions
diff --git a/modules/meson.build b/modules/meson.build index 38612254..73444e99 100644 --- a/modules/meson.build +++ b/modules/meson.build @@ -7,6 +7,7 @@ lua_mod_src = [ # add lua modules without separate meson.build files('dns64/dns64.lua'), files('etcd/etcd.lua'), files('graphite/graphite.lua'), + files('prefetch/prefetch.lua'), files('predict/predict.lua'), files('prefill/prefill.lua'), files('priming/priming.lua'), diff --git a/modules/prefetch/README.rst b/modules/prefetch/README.rst new file mode 100644 index 00000000..4d5a5e3e --- /dev/null +++ b/modules/prefetch/README.rst @@ -0,0 +1,18 @@ +.. SPDX-License-Identifier: GPL-3.0-or-later + +.. _mod-prefetch: + +Expiring records +---------------- + +The ``prefetch`` module helps to keep the cache hot by prefetching expiring records. + +This mechanism is activated when the module is loaded and it is not configurable. + +.. code-block:: lua + + modules.load('prefetch') + + +Any time the resolver answers with records that are about to expire, they get refreshed. (see :c:func:`is_expiring`) +That improves latency for records which get frequently queried, relatively to their TTL. diff --git a/modules/prefetch/prefetch.lua b/modules/prefetch/prefetch.lua new file mode 100644 index 00000000..673cf3e5 --- /dev/null +++ b/modules/prefetch/prefetch.lua @@ -0,0 +1,21 @@ +-- SPDX-License-Identifier: GPL-3.0-or-later +-- Speculative prefetching for repetitive and soon-expiring records to reduce latency. +-- @module prefetch +local prefetch = {} + + +prefetch.layer = { + -- Prefetch all expiring (sub-)queries immediately after the request finishes. + -- Doing that immediately is simplest and avoids creating (new) large bursts of activity. + finish = function (_, req) + local qrys = req.rplan.resolved + for i = 0, (tonumber(qrys.len) - 1) do -- size_t doesn't work for some reason + local qry = qrys.at[i] + if qry.flags.EXPIRING == true then + resolve(kres.dname2str(qry.sname), qry.stype, qry.sclass, {'NO_CACHE'}) + end + end + end +} + +return prefetch |