-
Notifications
You must be signed in to change notification settings - Fork 2.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
perf: accelerate the creation of the consumer cache #11840
base: master
Are you sure you want to change the base?
Conversation
Signed-off-by: xuruidong <[email protected]>
To purge local cache need to restart apisix? |
Signed-off-by: xuruidong <[email protected]>
ping @membphis |
apisix/consumer.lua
Outdated
conf_version = consumers.conf_version | ||
} | ||
end | ||
|
||
local cached_consumer = consumers_id_cache[val.value.id] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I do not know why we have to add consumers_id_cache
it seems useless
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The purpose of using consumer_id_cache is to avoid unnecessary table copies. I will refactor this part of the code to replace the table with an LRU cache.
yes |
Signed-off-by: xuruidong <[email protected]>
@@ -101,46 +152,21 @@ local function plugin_consumer() | |||
if not plugins[name] then | |||
plugins[name] = { | |||
nodes = {}, | |||
len = 0, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The purpose of introducing the len variable here is to reduce the redundant computation of the table length. Refer to the table.insert
section in this link: https://api7.ai/learning-center/openresty/lua-table-and-metatable
The code introduces a variable When the number of consumers exceeds twice the size of the LRU cache, the process of creating cache during the execution of the 代码中引入了一个变量 consumers_count_for_lrucache , 用来设置 lrucache 的大小。实际使用的时候,这个值需要配置为大于 consumer 的实际数量,并且如果一个consumer 中存在多个认证插件,则会被认为是不同的consumer 缓存到 lrucache 中。 当 consumer 数量大于2倍的lrucache 大小的时候,在执行 |
ping @membphis |
apisix/consumer.lua
Outdated
}) | ||
|
||
local function fill_consumer_secret(consumer) | ||
local new_consumer = core.table.clone(consumer) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
do you think we should use deep_clone
?
is it safer?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think deep-copy is not necessary. The consumer in the function fill_consumer_secret(consumer)
is created in the construct_consumer_data
function and is a copy of an element from the consumers.values
list.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I will check it carefully next week, I am busy this week
Description
In my case, there are approximately 17,000+ consumers. Any update from a consumer will trigger a long-tail request. I found the methods
consumer.plugin
andconsumer.consumers_kv
cost too much time.Test steps
Update one consumer, send a request. Repeat 5 times.
Test result:
Before optimization:
unit: second
After optimization:
unit: second
Fixes # (issue)
Checklist