feat: change PolicyMap from nomal map to sync.map (#1495)#1511
Closed
D0000M wants to merge 1 commit intoapache:masterfrom
Closed
feat: change PolicyMap from nomal map to sync.map (#1495)#1511D0000M wants to merge 1 commit intoapache:masterfrom
D0000M wants to merge 1 commit intoapache:masterfrom
Conversation
|
Link/Related to: #1513 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
feat: change PolicyMap from nomal map to sync.map (#1495), may have some help.
I couldn't reproduce the issue on my side, but I suspect it might be due to the lock granularity in SyncedEnforcer, or maybe some methods are being called inside a locked context and then call other functions that aren't aware of the lock.
My proposed solution is to change Assertion.PolicyMap from a map[string]int to a sync.Map, which seems to fix the problem. But it does have a noticeable impact on performance—overall benchmark performance drops by about 3%, and BenchmarkAddPolicy and BenchmarkRemovePolicy drop by 10–46%.
So it's really a trade-off.