]> git.ipfire.org Git - thirdparty/knot-resolver.git/commitdiff
modules/ta_sentinel: optimize
authorVladimír Čunát <vladimir.cunat@nic.cz>
Wed, 14 Aug 2019 14:53:23 +0000 (16:53 +0200)
committerPetr Špaček <petr.spacek@nic.cz>
Mon, 2 Dec 2019 12:34:52 +0000 (13:34 +0100)
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.

modules/ta_sentinel/ta_sentinel.lua

index 6a8a52ad1f22a4a89b01740fb76abb8908eeb26f..6fa136ae8eca05595c6738750185ca92b89d832c 100644 (file)
@@ -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