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

Feature: new slot chain #264

Merged
merged 8 commits into from Oct 14, 2020

Conversation

AlexStocks
Copy link
Contributor

Describe what this PR does / why we need it

Sentinel 包针对某个 Resource 无法确知其使用了那个组件,在运行时会针对某个 Resource 的 EntryContext 依次执行所有的组件的 Rule。本pr的目的就是减少下面函数 SlotChain.Entry() 中执行 RuleCheckSlot.Check() 执行次数

Describe how you did it

最后优化的效果的集合代码如下:

	sc, ok := rsSlotChain[rsName]
	if !ok {
		sc = base.NewSlotChain()
		sc.AddStatPrepareSlotLast(stat.DefaultResourceNodePrepareSlot)

		sc.AddStatSlotLast(stat.DefaultSlot)
		sc.AddStatSlotLast(log.DefaultSlot)
	}

	switch slotName {
	case system.RuleCheckSlotName:
		if !validateRuleCheckSlot(sc, system.DefaultAdaptiveSlot) {
			sc.AddRuleCheckSlotLast(system.DefaultAdaptiveSlot)
		}

	case flow.RuleCheckSlotName:
		if !validateRuleCheckSlot(sc, flow.DefaultSlot) {
			sc.AddRuleCheckSlotLast(flow.DefaultSlot)
			sc.AddStatSlotLast(flow.DefaultStandaloneStatSlot)
		}

	case isolation.RuleCheckSlotName:
		if !validateRuleCheckSlot(sc, isolation.DefaultSlot) {
			sc.AddRuleCheckSlotLast(isolation.DefaultSlot)
		}

	case circuitbreaker.RuleCheckSlotName:
		if !validateRuleCheckSlot(sc, circuitbreaker.DefaultSlot) {
			sc.AddRuleCheckSlotLast(circuitbreaker.DefaultSlot)
			sc.AddStatSlotLast(circuitbreaker.DefaultMetricStatSlot)
		}

	case hotspot.RuleCheckSlotName:
		if validateRuleCheckSlot(sc, hotspot.DefaultSlot) {
			sc.AddRuleCheckSlotLast(hotspot.DefaultSlot)
			sc.AddStatSlotLast(hotspot.DefaultConcurrencyStatSlot)
		}
	}

@CLAassistant
Copy link

CLAassistant commented Oct 3, 2020

CLA assistant check
All committers have signed the CLA.

@louyuting louyuting added area/performance Issues or PRs related to runtime performance kind/enhancement Category issues or PRs related to enhancement to-review PRs to review labels Oct 3, 2020
@louyuting louyuting added this to the 1.0.0 milestone Oct 5, 2020
api/api.go Outdated Show resolved Hide resolved
api/api_test.go Outdated Show resolved Hide resolved
@AlexStocks AlexStocks changed the title Feature/new slot chain Feature: new slot chain Oct 8, 2020
api/api_test.go Outdated Show resolved Hide resolved
api/api_test.go Outdated Show resolved Hide resolved
api/api_test.go Outdated Show resolved Hide resolved
@louyuting
Copy link
Collaborator

Otherwise, could you please resolve the conflicts(rebase the newest code from alibaba/sentinel-golang)

@sczyh30 sczyh30 added the kind/refactor Issue related to functional refactoring. label Oct 9, 2020
sdttttt
sdttttt previously approved these changes Oct 10, 2020
@louyuting louyuting linked an issue Oct 10, 2020 that may be closed by this pull request
api/api.go Outdated Show resolved Hide resolved
@codecov-io
Copy link

codecov-io commented Oct 13, 2020

Codecov Report

Merging #264 into master will increase coverage by 0.14%.
The diff coverage is 82.60%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master     #264      +/-   ##
==========================================
+ Coverage   51.09%   51.23%   +0.14%     
==========================================
  Files          79       79              
  Lines        4026     4048      +22     
==========================================
+ Hits         2057     2074      +17     
- Misses       1679     1684       +5     
  Partials      290      290              
Impacted Files Coverage Δ
api/api.go 19.44% <0.00%> (-0.85%) ⬇️
core/isolation/slot.go 0.00% <0.00%> (ø)
core/base/slot_chain.go 92.95% <78.57%> (-4.06%) ⬇️
api/slot_chain.go 93.33% <100.00%> (+12.08%) ⬆️
core/circuitbreaker/rule_manager.go 71.83% <100.00%> (+0.32%) ⬆️
core/circuitbreaker/slot.go 100.00% <100.00%> (ø)
core/circuitbreaker/stat_slot.go 14.28% <100.00%> (+14.28%) ⬆️
core/flow/rule_manager.go 61.36% <100.00%> (+0.29%) ⬆️
core/flow/slot.go 44.82% <100.00%> (+1.97%) ⬆️
core/flow/standalone_stat_slot.go 71.42% <100.00%> (+4.76%) ⬆️
... and 6 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update cb639b4...9e22877. Read the comment docs.

@louyuting louyuting self-requested a review October 13, 2020 05:32
api/slot_chain.go Show resolved Hide resolved
core/misc/slot_chain.go Outdated Show resolved Hide resolved
Copy link
Collaborator

@louyuting louyuting left a comment

Choose a reason for hiding this comment

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

Thanks for your nice work!

@louyuting louyuting merged commit d36315f into alibaba:master Oct 14, 2020
@sczyh30 sczyh30 removed the to-review PRs to review label Oct 16, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/performance Issues or PRs related to runtime performance kind/enhancement Category issues or PRs related to enhancement kind/refactor Issue related to functional refactoring.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Slot chain relates to resource
8 participants