diff --git a/.requirements b/.requirements index 8ac77a2cae1..d834d859bd9 100644 --- a/.requirements +++ b/.requirements @@ -10,7 +10,7 @@ LUA_KONG_NGINX_MODULE=4fbc3ddc7dcbc706ed286b95344f3cb6da17e637 # 0.8.0 LUA_RESTY_LMDB=19a6da0616db43baf8197dace59e64244430b3c4 # 1.4.1 LUA_RESTY_EVENTS=8448a92cec36ac04ea522e78f6496ba03c9b1fd8 # 0.2.0 LUA_RESTY_WEBSOCKET=60eafc3d7153bceb16e6327074e0afc3d94b1316 # 0.4.0 -ATC_ROUTER=95f1d8fe10b244bba5b354e5ed3726442373325e # 1.4.0 +ATC_ROUTER=ac71b24ea5556b38b0f9903850ed666c36ad7843 # 1.4.1 KONG_MANAGER=nightly NGX_WASM_MODULE=b9037acf7fa2d6f9ff02898bfc05544a1edc1fad diff --git a/changelog/unreleased/kong/atc_reuse_context.yml b/changelog/unreleased/kong/atc_reuse_context.yml new file mode 100644 index 00000000000..3af76d0a2d7 --- /dev/null +++ b/changelog/unreleased/kong/atc_reuse_context.yml @@ -0,0 +1,3 @@ +message: "Reuse match copntext between requests to avoid frequent memory allocation/deallocation" +type: performance +scope: Core diff --git a/changelog/unreleased/kong/bump-atc-router.yml b/changelog/unreleased/kong/bump-atc-router.yml index 1696ebc9d3f..2013fd9dda6 100644 --- a/changelog/unreleased/kong/bump-atc-router.yml +++ b/changelog/unreleased/kong/bump-atc-router.yml @@ -1,3 +1,3 @@ -message: Bumped atc-router from 1.2.0 to 1.4.0 +message: Bumped atc-router from 1.2.0 to 1.4.1 type: dependency scope: Core diff --git a/kong/router/atc.lua b/kong/router/atc.lua index 6d2d32afed8..f05053f8eb0 100644 --- a/kong/router/atc.lua +++ b/kong/router/atc.lua @@ -4,6 +4,7 @@ local _MT = { __index = _M, } local buffer = require("string.buffer") local schema = require("resty.router.schema") +local context = require("resty.router.context") local router = require("resty.router.router") local lrucache = require("resty.lrucache") local tb_new = require("table.new") @@ -35,7 +36,7 @@ local check_select_params = utils.check_select_params local get_service_info = utils.get_service_info local route_match_stat = utils.route_match_stat local get_cache_key = fields.get_cache_key -local get_atc_context = fields.get_atc_context +local fill_atc_context = fields.fill_atc_context local DEFAULT_MATCH_LRUCACHE_SIZE = utils.DEFAULT_MATCH_LRUCACHE_SIZE @@ -223,7 +224,7 @@ local function new_from_scratch(routes, get_exp_and_priority) local fields = inst:get_fields() return setmetatable({ - schema = CACHED_SCHEMA, + context = context.new(CACHED_SCHEMA), router = inst, routes = routes_t, services = services_t, @@ -412,7 +413,9 @@ function _M:matching(params) params.host = host params.port = port - local c, err = get_atc_context(self.schema, self.fields, params) + self.context:reset() + + local c, err = fill_atc_context(self.context, self.fields, params) if not c then return nil, err @@ -552,7 +555,9 @@ function _M:matching(params) params.dst_ip, params.dst_port, sni) - local c, err = get_atc_context(self.schema, self.fields, params) + self.context:reset() + + local c, err = fill_atc_context(self.context, self.fields, params) if not c then return nil, err end diff --git a/kong/router/fields.lua b/kong/router/fields.lua index 11e2a09fe95..a33b27c8fcd 100644 --- a/kong/router/fields.lua +++ b/kong/router/fields.lua @@ -1,5 +1,4 @@ local buffer = require("string.buffer") -local context = require("resty.router.context") local type = type @@ -288,8 +287,8 @@ local function get_cache_key(fields, params, ctx) end -local function get_atc_context(schema, fields, params) - local c = context.new(schema) +local function fill_atc_context(context, fields, params) + local c = context local res, err = fields_visitor(fields, params, nil, function(field, value) @@ -354,7 +353,7 @@ end return { get_cache_key = get_cache_key, - get_atc_context = get_atc_context, + fill_atc_context = fill_atc_context, _set_ngx = _set_ngx, }