From: Vladimír Čunát Date: Wed, 14 Aug 2019 14:53:23 +0000 (+0200) Subject: modules/ta_sentinel: optimize X-Git-Tag: v4.3.0~4^2~1 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=4d0485364728830deb11e9c4655abd4a5360bb24;p=thirdparty%2Fknot-resolver.git modules/ta_sentinel: optimize When all lua modules get unloaded, this change makes the module's contribution to QPS unmeasurable (for me), saving a few percent. The point is to almost always return very cheaply, in particular without creating any lua GC object (like FFI for kr_query). Note: some checks didn't make much sense, so I improved those as well. --- diff --git a/modules/ta_sentinel/ta_sentinel.lua b/modules/ta_sentinel/ta_sentinel.lua index 6a8a52ad1..6fa136ae8 100644 --- a/modules/ta_sentinel/ta_sentinel.lua +++ b/modules/ta_sentinel/ta_sentinel.lua @@ -3,22 +3,21 @@ M.layer = {} local ffi = require('ffi') function M.layer.finish(state, req, pkt) - if bit.band(state, kres.DONE) == 0 then - return state end -- not resolved yet, exit - - local qry = req:resolved() - if qry.parent ~= nil then - return state end -- an internal query, exit - - if not (pkt:qtype() == kres.type.A or pkt:qtype() == kres.type.AAAA) then - return state end - - -- fast filter by the length of the first label - local label_len = qry:name():byte(1) + -- fast filter by the length of the first QNAME label + if pkt.wire[5] == 0 then return state end -- QDCOUNT % 256 == 0, in case we produced that + local label_len = pkt.wire[12] if label_len ~= 29 and label_len ~= 30 then return state end -- end of hot path + + local qtype = pkt:qtype() + if not (qtype == kres.type.A or qtype == kres.type.AAAA) then + return state end + if bit.band(state, kres.FAIL) ~= 0 then + return state end + -- check the label name + local qry = req:resolved() local qname = kres.dname2str(qry:name()):lower() local sentype, keytag if label_len == 29 then