-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(core): improve entitlements performance (#1271)
### Context: While developing COP, we found that GetEntitlements could take around 5.5 seconds to return a response for the federal dataset. This forced us to increase the server timeout, increase the grpc message size, and implement caches. After investigating the latency, we determined the two main causes: [excess logs](https://github.com/opentdf/platform/blob/f275e25e4f986455fc536d2c93f7e9535f8519ab/service/authorization/authorization.go#L393) (33%) and [excess database queries](https://github.com/opentdf/platform/blob/cc15f25af2c3e839d7ad45283b7bd298a80e8728/service/policy/db/attribute_fqn.go#L188-L195) (66%). ### Proposed Solution: #### Primary 1. In the case of logging subject mappings, we now log their count instead of their content. 2. In the case of database calls, we now list attributes, list subject mappings, and match them based on their values. The database calls were O(n) time complexity because they were dependent on the number of attribute values. Now the database calls are constant time. We still loop through all the values to match their subject mappings; however we were already doing that in the `prepareValues` values function, so the new approach is strictly better (especially due to our ubiquitous use of maps). #### Rego Query Optimization: Yet if we simply match subject mappings and attribute values, the rego query becomes massive (65 mb). It takes 3 seconds to build (20%) and evaluate (80%). To optimize for not only time but also space, we remove unrelated values for each fqn/attribute pair in the rego input (unless the attribute rule is hierarchical). After all the optimizations, fetching entitlements using the federal dataset now takes about 125 ms. This is a **_latency reduction of 98%_**. resolves: #1259 --------- Co-authored-by: Sean Trantalis <[email protected]>
- Loading branch information
1 parent
de5be3c
commit f6a1b26
Showing
3 changed files
with
118 additions
and
46 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
This file contains 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