Skip to content

Commit

Permalink
refactor(clustering/rpc): cache the result of parse_method_name() (#…
Browse files Browse the repository at this point in the history
…12949)

Using lru_cache to improve the performance of `pares_method_name()`.

KAG-4441
  • Loading branch information
chronolaw authored Jul 3, 2024
1 parent 3eeb9c9 commit 7d4bcb3
Showing 1 changed file with 15 additions and 1 deletion.
16 changes: 15 additions & 1 deletion kong/clustering/rpc/utils.lua
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
local _M = {}
local cjson = require("cjson")
local snappy = require("resty.snappy")
local lrucache = require("resty.lrucache")


local string_sub = string.sub
Expand All @@ -12,13 +13,26 @@ local snappy_compress = snappy.compress
local snappy_uncompress = snappy.uncompress


local cap_names = lrucache.new(100)


function _M.parse_method_name(method)
local cap = cap_names:get(method)

if cap then
return cap[1], cap[2]
end

local pos = rfind(method, ".")
if not pos then
return nil, "not a valid method name"
end

return method:sub(1, pos - 1), method:sub(pos + 1)
local cap = { method:sub(1, pos - 1), method:sub(pos + 1) }

cap_names:set(method, cap)

return cap[1], cap[2]
end


Expand Down

1 comment on commit 7d4bcb3

@github-actions
Copy link
Contributor

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:7d4bcb3fc303368aed653718da9acc7e33244036
Artifacts available https://github.com/Kong/kong/actions/runs/9771325137

Please sign in to comment.