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

Further fixes to context handling in LookupResources and performance improvements #1397

Merged
merged 2 commits into from
Jun 19, 2023

Conversation

josephschorr
Copy link
Member

@josephschorr josephschorr commented Jun 15, 2023

(See commit messages for detailed information)

@josephschorr josephschorr requested a review from a team as a code owner June 15, 2023 17:41
@github-actions github-actions bot added area/api v1 Affects the v1 API area/dispatch Affects dispatching of requests area/tooling Affects the dev or user toolchain (e.g. tests, ci, build tools) labels Jun 15, 2023
internal/dispatch/graph/lookupresources_test.go Outdated Show resolved Hide resolved
internal/graph/context.go Outdated Show resolved Hide resolved
internal/graph/context.go Show resolved Hide resolved
internal/graph/limits.go Show resolved Hide resolved
internal/services/v1/permissions.go Outdated Show resolved Hide resolved
internal/graph/context.go Show resolved Hide resolved
internal/graph/lookupresources.go Show resolved Hide resolved
internal/graph/reachableresources.go Outdated Show resolved Hide resolved
internal/dispatch/caching/caching.go Show resolved Hide resolved
internal/graph/checkingresourcestream.go Show resolved Hide resolved
The previous approach of having the limit tracker control the context was causing parallelized branches of the Reachable Resources to be canceled early; we were ignoring this error (incorrectly) and thus, reachable resources could return partial results.

Instead, we now manually and explicitly detach the context and cancel it explicitly when no further dispatching is needed.
This changes the datastore query to no longer have a limit, and instead produce a series of chunks for parallelized processing using the same parallelization code as the entrypoint cursor parallelization system.

This is done in service of performance: a single database query is faster than making multiple roundtrips.

This change also removes the limits on dispatching reachable resources and lookup resources in favor of grabbing as many results as possible and canceling dispatch once the overall limit has been reached. While this results in slightly more work being done than is necessary, it is far more performant from the caller's perspective (especially for no-limit calls), because there is no need to re-enter the reachable resources dispatch tree.

As per the above change around limits, this change also further adjusts how context cancelation functions and adds a slew of tests to cover these new cases
@josephschorr
Copy link
Member Author

Updated

@vroldanbet vroldanbet added this pull request to the merge queue Jun 19, 2023
Merged via the queue into authzed:main with commit 666d083 Jun 19, 2023
@github-actions github-actions bot locked and limited conversation to collaborators Jun 19, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
area/api v1 Affects the v1 API area/dispatch Affects dispatching of requests area/tooling Affects the dev or user toolchain (e.g. tests, ci, build tools)
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants