From: Marek VavruĊĦa Date: Mon, 6 Jul 2015 00:06:41 +0000 (+0200) Subject: modules/prefetch: fixed lua error on bad queries, iterative X-Git-Tag: v1.0.0-beta1~88^2~1 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=8a9b628959352b7014e99b7b36797d4612f24864;p=thirdparty%2Fknot-resolver.git modules/prefetch: fixed lua error on bad queries, iterative --- diff --git a/daemon/bindings.c b/daemon/bindings.c index 4fe3265a5..c223cfe9f 100644 --- a/daemon/bindings.c +++ b/daemon/bindings.c @@ -581,11 +581,7 @@ static int wrk_resolve(lua_State *L) /* Resolve it */ int ret = worker_resolve(worker, pkt); knot_pkt_free(&pkt); - if (ret != 0) { - lua_pushstring(L, kr_strerror(ret)); - lua_error(L); - } - lua_pushboolean(L, true); + lua_pushboolean(L, ret == 0); return 1; } diff --git a/lib/layer/rrcache.c b/lib/layer/rrcache.c index d2db8a5e1..56f64b46c 100644 --- a/lib/layer/rrcache.c +++ b/lib/layer/rrcache.c @@ -51,8 +51,8 @@ static int loot_rr(struct kr_cache_txn *txn, knot_pkt_t *pkt, const knot_dname_t knot_pkt_put_question(pkt, qry->sname, qry->sclass, qry->stype); } - /* Mark as expiring if it has less than 5% TTL (or less than 5s) */ - if (100 * (drift + 5) > 95 * knot_rrset_ttl(&cache_rr)) { + /* Mark as expiring if it has less than 1% TTL (or less than 5s) */ + if (100 * (drift + 5) > 99 * knot_rrset_ttl(&cache_rr)) { qry->flags |= QUERY_EXPIRING; } diff --git a/modules/prefetch/prefetch.lua b/modules/prefetch/prefetch.lua index 8246ce7a8..b0c840557 100644 --- a/modules/prefetch/prefetch.lua +++ b/modules/prefetch/prefetch.lua @@ -7,9 +7,9 @@ -- @field window length of the coalescing window local prefetch = { queue = {}, - queue_max = 100, + queue_max = 1000, queue_len = 0, - window = 60, + window = 30, layer = { -- Schedule cached entries that are expiring soon finish = function(state, req, answer) @@ -38,11 +38,21 @@ local prefetch = { -- Resolve queued records and flush the queue function prefetch.batch(module) + -- Defer prefetching if the server is loaded + if worker.stats().concurrent > 10 then + return 0 + end + local to_delete = prefetch.queue_max / 5 + local deleted = 0 for key, val in pairs(prefetch.queue) do worker.resolve(string.sub(key, 2), string.byte(key)) prefetch.queue[key] = nil + deleted = deleted + 1 + if deleted == to_delete then + break + end end - prefetch.queue_len = 0 + prefetch.queue_len = prefetch.queue_len - deleted return 0 end