xuruidong commented on PR #11840:
URL: https://github.com/apache/apisix/pull/11840#issuecomment-2565004061

   The code introduces a variable `consumers_count_for_lrucache`, which is used 
to set the size of the LRU cache. In actual use, this value needs to be 
configured to be greater than the actual number of consumers. Additionally, if 
a consumer has multiple authentication plugins, each of them will be considered 
as a separate consumer and cached individually in the LRU cache.
   
   When the number of consumers exceeds twice the size of the LRU cache, the 
process of creating cache during the execution of the `consumer.plugin` 
function may result in cache misses, leading to performance degradation. This 
happens because the LRU cache can only store consumers within a single window, 
and each time a consumer is updated, the order of the consumer IDs in the 
`consumers.values` array is likely to either remain the same or change very 
little. As a result, new consumer objects are continuously created, causing the 
old consumer cache entries to be evicted.
   
   ---
   
   代码中引入了一个变量 consumers_count_for_lrucache , 用来设置 lrucache 
的大小。实际使用的时候,这个值需要配置为大于 consumer 的实际数量,并且如果一个consumer 
中存在多个认证插件,则会被认为是不同的consumer 缓存到 lrucache 中。
   
   当 consumer 数量大于2倍的lrucache 大小的时候,在执行 `consumer.plugin` 
函数创建缓存的过程中可能会一直不能命中缓存而导致性能下降。因为 lrucache 只能缓存一个窗口内的 consumer,而每次 consumer 
有更新时,consumers.values 数组中的 consumer id 的顺序大概率可能不变或者变化很小,此时会一直存在生成新的 consumer 
object ,淘汰旧的 consumer 缓存。
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to