Skip to content
Snippets Groups Projects
Commit 3f3848f7 authored by Marek Vavruša's avatar Marek Vavruša
Browse files

prefetch wip

parent 6edb8d29
No related merge requests found
...@@ -180,8 +180,8 @@ static int l_ffi_layer_consume(knot_layer_t *ctx, knot_pkt_t *pkt) ...@@ -180,8 +180,8 @@ static int l_ffi_layer_consume(knot_layer_t *ctx, knot_pkt_t *pkt)
static int l_ffi_layer_produce(knot_layer_t *ctx, knot_pkt_t *pkt) static int l_ffi_layer_produce(knot_layer_t *ctx, knot_pkt_t *pkt)
{ {
if (ctx->state & (KNOT_STATE_FAIL|KNOT_STATE_DONE)) { if (ctx->state & (KNOT_STATE_FAIL)) {
return ctx->state; /* Already resolved/failed, skip */ return ctx->state; /* Already failed, skip */
} }
LAYER_FFI_CALL(ctx, "produce"); LAYER_FFI_CALL(ctx, "produce");
lua_pushlightuserdata(L, ctx->data); lua_pushlightuserdata(L, ctx->data);
......
...@@ -16,7 +16,8 @@ endif ...@@ -16,7 +16,8 @@ endif
ifeq ($(HAS_lua),yes) ifeq ($(HAS_lua),yes)
modules_TARGETS += ketcd \ modules_TARGETS += ketcd \
graphite \ graphite \
block block \
prefetch
endif endif
# List of Golang modules # List of Golang modules
......
.. _mod-prefetch:
Prefetching
-----------
local prefetch = {
queue = {},
frequency = 2
}
-- @function Block layer implementation
prefetch.layer = {
produce = function(state, req, pkt)
-- Schedule cached entries that are expiring soon
local qry = kres.query_current(req)
if not kres.query_has_flag(qry, kres.query.CACHED) then
return state
end
local rr = pkt:get(kres.ANSWER, 0)
if rr and rr.ttl > 0 and rr.ttl < prefetch.frequency then
local key = rr.owner..rr.type
local val = prefetch.queue[key]
if not val then
prefetch.queue[key] = 1
else
prefetch.queue[key] = val + 1
end
end
return state
end
}
function prefetch.batch(module)
for key, val in pairs(prefetch.queue) do
print('prefetching',key,val)
end
prefetch.queue = {}
-- @TODO: next batch interval
event.after(prefetch.frequency * sec, prefetch.batch)
end
function prefetch.init(module)
event.after(prefetch.frequency * sec, prefetch.batch)
end
function prefetch.deinit(module)
if prefetch.ev then event.cancel(prefetch.ev) end
end
return prefetch
prefetch_SOURCES := prefetch.lua
$(call make_lua_module,prefetch)
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment