Skip to content
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

resource rules (flow/degrade/param/authority) support regex matching #3251

Merged
merged 1 commit into from
Dec 27, 2023

Conversation

LiYangSir
Copy link
Contributor

Describe what this PR does / why we need it

Resource rules support matching resource names according to regular rules, allowing users to configure traffic limiting rules or batch configuration.
When adding/deleting interfaces, there is no need to manually create/delete rules.

资源规则支持按照正则匹配资源名称,允许用户按照配置兜底限流规则或批量配置的能力。
当新增/删除接口时,无需手动创建/删除规则。

Does this pull request fix one issue?

Fixes #3247

Describe how you did it

Add a RuleManger to uniformly manage ordinary rules and regular rules. In order to reduce the performance loss caused by regular parsing/matching, the following two methods are used:

  1. Add a cache to cache the current limiting rules after regular parsing. When matching the current limiting rules, first search from the cache;
  2. Rebuild the cache. When the current limiting rule is updated, new cache data is rebuilt based on the old cache data to reduce the performance loss caused by cache failure after the rule is updated;

增加一个 RuleManger 统一管理普通规则和正则规则,为了减少正则解析/匹配所带来的性能损耗,使用下面两种方式:

  1. 增加缓存,缓存正则解析后的限流规则,匹配限流规则时先从缓存中去查找;
  2. 重建缓存,当限流规则出现更新时,依据旧缓存数据重建新的缓存数据,减少由于更新规则后,缓存失效带来的性能损耗;

Describe how to verify it

Regular unit tests have been added to each of the four rules to ensure normal performance; if regular rules are turned on, current limiting rules that meet regular matching but have different resource names will take effect.

对四种规则分别增加了正则的单元测试,用于保证表现正常;如果开启了正则规则,满足正则匹配但资源名称不同的限流规则均会生效。

  1. Authority Rule:com.alibaba.csp.sentinel.slots.block.authority.AuthorityPartialIntegrationTest
  2. Degrade Rule:com.alibaba.csp.sentinel.slots.block.degrade.DegradePartialIntegrationTest
  3. Flow Rule:com.alibaba.csp.sentinel.slots.block.flow.FlowPartialIntegrationTest
  4. Hot Pram Rule:com.alibaba.csp.sentinel.slots.block.flow.param.ParamFlowPartialIntegrationTest

Special notes for reviews

None

@LearningGp
Copy link
Collaborator

It would be helpful to have a benchmark report comparing the original rules. 🚀

@LearningGp LearningGp added to-review To review area/flow-control Issues or PRs related to flow control size/XL Indicate a PR that changes 500-999 lines. labels Dec 22, 2023
@LiYangSir
Copy link
Contributor Author

LiYangSir commented Dec 25, 2023

It would be helpful to have a benchmark report comparing the original rules. 🚀

Throughput (s)

image

Throughput (ns)

image

AverageTime (ns)

image

ps: testNormal: Original Type; testRegex: Direct use regex parse; testRegexWitchCache: use cache regex result

Due to the need to retrieve rules from the regex cache map and regular rules, the throughput of the previous retrieval method is twice that of direct retrieval, which means there is an additional get method, but it is also within an acceptable range.

Copy link
Collaborator

@LearningGp LearningGp left a comment

Choose a reason for hiding this comment

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

LGTM

@LearningGp LearningGp merged commit a524ab3 into alibaba:master Dec 27, 2023
7 checks passed
@LearningGp
Copy link
Collaborator

Thanks for contributing! 🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/flow-control Issues or PRs related to flow control size/XL Indicate a PR that changes 500-999 lines.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Resource rules support regular expression matching 【资源规则支持正则表达式匹配】
3 participants