Skip to content

[v12] Improve performance of ListResources#23596

Merged
rosstimothy merged 1 commit intobranch/v12from
tross/backport-23534/v12
Mar 28, 2023
Merged

[v12] Improve performance of ListResources#23596
rosstimothy merged 1 commit intobranch/v12from
tross/backport-23534/v12

Conversation

@rosstimothy
Copy link
Copy Markdown
Contributor

@rosstimothy rosstimothy commented Mar 24, 2023

Backport #23534 to branch/v12

@rosstimothy rosstimothy changed the title Improve performance of ListResources (#23534) [v12] Improve performance of ListResources Mar 24, 2023
* Add benchmark for ListNodes

* Move RBAC logging to trace level

BenchmarkListNodes is twice as slow when RBAC logging is enabled.
By switching RBAC logging from debug to trace we can eliminate
the performance hit while still providing a way for users to opt
in to the behavior if they need to debug RBAC.

* Intern compiled regular expressions

Profiles of the benchmark test revealed that the `regexp.Compile`
done within `utils.matchString` was the most cpu and memory intensive
portion of the tests. By leveraging a `lru.Cache` to intern the
compiled regular expressions we get quite a performance improvement.

* Only fetch a single page of resources

Increases the request limit prior to loading the resources from
the cache so that we load enough items in a single page to determine
the start key of the next page.

* Remove version checking from `services.UnmarshalServer`

Unmarshal directly to a `types.ServerV2` instead of first creating
a `types.ResourceHeader` to inspect the version. There is only a
single version for `types.ServerV2` making the check unnecessary.

* Add `GetLabel` to `types.ResourceWithLables`

`GetAllLabels` can be overkill if one simply needs to look up the
value for a particular label. It creates a new `map[string]string`
and copies all of a resources existing labels. RBAC decisions
driven by labels incurred the penalty of the copy each time access
was checked. The impact of the copy is much more noticeable when
a resource has several labels or really long strings in the key
or value.

By leveraging `GetLabel` RBAC can avoid copying the labels altogether
and simply lookup each label key when required.
@rosstimothy rosstimothy force-pushed the tross/backport-23534/v12 branch from 4e5a0c3 to 976d0bd Compare March 25, 2023 15:06
@rosstimothy rosstimothy marked this pull request as ready for review March 27, 2023 12:51
@rosstimothy rosstimothy enabled auto-merge March 27, 2023 18:13
@rosstimothy rosstimothy added this pull request to the merge queue Mar 28, 2023
@public-teleport-github-review-bot public-teleport-github-review-bot Bot removed the request for review from fspmarshall March 28, 2023 09:05
@github-merge-queue github-merge-queue Bot removed this pull request from the merge queue due to failed status checks Mar 28, 2023
@rosstimothy rosstimothy added this pull request to the merge queue Mar 28, 2023
Merged via the queue into branch/v12 with commit 1d6eafb Mar 28, 2023
@rosstimothy rosstimothy deleted the tross/backport-23534/v12 branch March 28, 2023 18:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants