-
Notifications
You must be signed in to change notification settings - Fork 571
Optimize ACL Parser Performance by Conditional Application of Recursive Analysis #1226
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
Optimize ACL Parser Performance by Conditional Application of Recursive Analysis #1226
Conversation
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.
Pull Request Overview
This PR optimizes ACL parser performance by conditionally applying deep recursive analysis only when needed.
- Introduces a boolean flag (useDeepRationalization) in ACL update methods to determine whether to perform the expensive recursive rationalization.
- Updates the RationalizeACLDescription method signature and replaces the unconditional recursion loop with a conditional one.
Reviewed Changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.
File | Description |
---|---|
test/Garnet.test/Resp/ACL/AclParserTests.cs | Added new test cases to verify correct ACL description outputs and performance improvements. |
libs/server/ACL/User.cs | Modified ACL update methods to incorporate conditional deep rationalization and updated the RationalizeACLDescription accordingly. |
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.
Longer term it's probably worth just reworking this algorithm, but a small patch to fix excessive runtimes is fine for now.
Problem
When the ACL SETUSER command is invoked with a large number of commands in the ACL (15+) the Garnet Server spins for a long time (1-2+ min) and can exceed the default timeout settings of a client in some cases.
The degraded runtime performance can be attributed to the
RationalizeACLDescription
method which unconditionally applies a recursive algorithm to eliminate duplicate commands in the ACL description returned to the user. This method has a high time complexity (n^3 according to copilot) and performance of the method degrades quickly when there are a large number of ACLs. Comments surrounding the method also indicate that it is expensive. In some test cases, execution of the method can take minutes.Fix
This change applies an optimization that avoids the expensive recursive analysis/rationalization when it is unnecessary, significantly improving the performance of the ACL parser.
The logic works on the following premises:
CommandPermissionSet
contains all commands the user has permission to execute.CommandPermissionSet
does not grant access to execute the current command to be added, there is no redundancy in the command description that needs to be reduced.RationalizeACLDescription
method.Testing Approach
To validate the change, I took the following steps:
Performance
I captured before / after results of my test executions in Visual Studio. Here are the results. I believe the first test suffers from a cold start problem, however there are significant improvements on the long running tests.
ParseACLRuleDescriptionTest
ParseACLRuleDescriptionTimeoutsTest
Follow On Work
The approach taken to producing the ACL description should be evaluated to see if a simpler strategy can be used. For example, a strategy could be used that only reduces at the same level, meaning we would not reduce individual commands when their category is specified.
Fixes #1225