Skip to content

Commit

Permalink
perf(request-debugging): improve performance (#11722)
Browse files Browse the repository at this point in the history
Improve the performance of the request debugging feature.

- reduce the number of calls of ngx.ctx
- cache some functions at the module level
- delete debug request headers only when debug headers exist.
- reduce the number of calls of req_dyn_hook.runhooks().

KAG-2738
  • Loading branch information
ADD-SP committed Oct 12, 2023
1 parent 39a545d commit 35768ad
Show file tree
Hide file tree
Showing 7 changed files with 218 additions and 68 deletions.
33 changes: 22 additions & 11 deletions kong/dynamic_hook/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -74,17 +74,28 @@ function _M.hook(group_name, hook_name, handler)
end


function _M.run_hooks(group_name, hook_name, ...)
if not always_enabled_groups[group_name] then
local dynamic_hook = ngx.ctx.dynamic_hook
if not dynamic_hook then
return
end

local enabled_groups = dynamic_hook.enabled_groups
if not enabled_groups[group_name] then
return
end
function _M.is_group_enabled(group_name)
if always_enabled_groups[group_name] then
return true
end

local dynamic_hook = ngx.ctx.dynamic_hook
if not dynamic_hook then
return false
end

local enabled_groups = dynamic_hook.enabled_groups
if not enabled_groups[group_name] then
return false
end

return true
end


function _M.run_hooks(ctx, group_name, hook_name, ...)
if not _M.is_group_enabled(group_name) then
return
end

local hooks = non_function_hooks[group_name]
Expand Down
1 change: 1 addition & 0 deletions kong/dynamic_hook/wrap_function_gen.lua
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ local ngx_get_phase = ngx.get_phase
local TEMPLATE = [[
return function(always_enabled_groups, group_name, original_func, handlers)
-- we cannot access upvalue here as this function is generated
local ngx = ngx
local ngx_get_phase = ngx.get_phase
return function(%s)
Expand Down
Loading

1 comment on commit 35768ad

@khcp-gha-bot
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Bazel Build

Docker image available kong/kong:35768ad6abb45d29594064d0cde294c0a2602d4f
Artifacts available https://github.com/Kong/kong/actions/runs/6492079081

Please sign in to comment.