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

performance: optimized string and various other XDS improvements #1016

Merged
merged 19 commits into from
May 3, 2024

Conversation

howardjohn
Copy link
Member

@howardjohn howardjohn commented May 3, 2024

Fixes #988

This PR introduces a new string representation. See issue above for some more background.

I initially implemented this using internment::ArcIntern<str>. This showed improvements over master, but I compared to using ArcStr and found actually better memory utilization with ArcStr, and much less complexity and risk. Conveniently, due to the strng module abstracting things, the swap was pretty much trivial (just a few small changes due to different conversion helpers in the libraries). So if we do want to switch things in the future, it shouldn't be too bad.

This optimizes the XDS path (and, presumably, others -- but I only measured XDS much).

My test covered 30k pods with 2k services. I loaded this up and checked memory usage (total and peak).

Before: 1.8GB total, 700mb retained
After: 1.1GB total, 520mb retained

Roughly 100mb of improvement came from switching the string representation, and 80mb came from other optimizations. Not confident in that breakdown as I was going back and forth moving things over + optimizing.

All optimizations here are guided by profiling. End profile (github
2024-05-03_13-31-45

Not much low hanging fruit left, most of the memory is in our hashmaps.

Optimizations aside from string changes:

  • Optimizing string concat in hotpaths
  • Avoid buffering up a vector of all XDS updates; stream it
  • Avoid buffering up a copy of all endpoints; just iterate it
  • Avoid a clone on the XDS workload

@istio-testing
Copy link
Contributor

Skipping CI for Draft Pull Request.
If you want CI signal for your change, please convert it to an actual PR.
You can still manually trigger a test run with /test all

@istio-testing istio-testing added do-not-merge/work-in-progress Block merging of a PR because it isn't ready yet. size/XL Denotes a PR that changes 500-999 lines, ignoring generated files. labels May 3, 2024
@howardjohn howardjohn changed the title wip: string interning and various optimizations performance: optimized string and various other XDS improvements May 3, 2024
@howardjohn howardjohn marked this pull request as ready for review May 3, 2024 20:39
@howardjohn howardjohn requested a review from a team as a code owner May 3, 2024 20:39
@istio-testing istio-testing removed the do-not-merge/work-in-progress Block merging of a PR because it isn't ready yet. label May 3, 2024
@istio-testing istio-testing added size/XXL Denotes a PR that changes 1000+ lines, ignoring generated files. and removed size/XL Denotes a PR that changes 500-999 lines, ignoring generated files. labels May 3, 2024
@bleggett
Copy link
Contributor

bleggett commented May 3, 2024

Before: 1.8GB total, 700mb retained
After: 1.1GB total, 520mb retained

that's more than I thought we'd save, nice.

@howardjohn howardjohn added the do-not-merge/hold Block automatic merging of a PR. label May 3, 2024
Copy link
Contributor

@bleggett bleggett left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

relatively easy win

/// * Immutable
/// This is mostly provided by a library, ArcStr, we just provide a very thin wrapper around it
/// for some flexibility.
pub type Strng = ArcStr;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Strictly speaking we don't need this type alias, we could just have ArcStr + RichStrng(ArcStr)?

That's a little more obvious and it's also easy to look at a type named ArcStr and know what it does.

But that's mostly a stylistic nit I guess, and if we ever want to use a different ArcStr impl, this insulates from that a bit.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was on the fence about the Strng thing. It was more useful when doing the interning library since their type name was unwieldy

@bleggett bleggett added the cherrypick/release-1.22 Set this label on a PR to auto-merge it to the release-1.22 branch label May 3, 2024
@howardjohn howardjohn removed the do-not-merge/hold Block automatic merging of a PR. label May 3, 2024
@istio-testing istio-testing merged commit 5eb8906 into istio:master May 3, 2024
3 checks passed
@istio-testing
Copy link
Contributor

In response to a cherrypick label: #1016 failed to apply on top of branch "release-1.22":

Applying: Initial
Applying: wip
Using index info to reconstruct a base tree...
M	src/identity/manager.rs
M	src/metrics.rs
M	src/proxy/metrics.rs
Falling back to patching base and 3-way merge...
Auto-merging src/proxy/metrics.rs
CONFLICT (content): Merge conflict in src/proxy/metrics.rs
Auto-merging src/metrics.rs
CONFLICT (content): Merge conflict in src/metrics.rs
Auto-merging src/identity/manager.rs
error: Failed to merge in the changes.
hint: Use 'git am --show-current-patch=diff' to see the failed patch
Patch failed at 0002 wip
When you have resolved this problem, run "git am --continue".
If you prefer to skip this patch, run "git am --skip" instead.
To restore the original branch and stop patching, run "git am --abort".

@istio-testing
Copy link
Contributor

In response to a cherrypick label: new issue created for failed cherrypick: #1020

howardjohn added a commit to howardjohn/ztunnel that referenced this pull request May 3, 2024
…io#1016)

* Initial

* wip

* prod compiling

* bump max

* wip diagnostics

* performance: avoid clone of workload on conversion

* performance: avoid allocating vector for all resources

* intern: xds types

* performance: optimize endpoint_uid

* perf: do not allocate endpoints vector

* performance: do not clone services map

* use arcstr instead

* metrics back on

* Tests compile

* format

* fix and format

* Move rbac over too

* Move more over

* rebase

(cherry picked from commit 5eb8906)
istio-testing pushed a commit that referenced this pull request May 4, 2024
* logs: fix dst.namespace and missing dst.service (#1017)

(cherry picked from commit 543a45b)

* misc: remove Default identity from prod codepath (#1018)

We didn't use it anywhere which is good -- but it was a risk

(cherry picked from commit a84ce37)

* performance: optimized string and various other XDS improvements (#1016)

* Initial

* wip

* prod compiling

* bump max

* wip diagnostics

* performance: avoid clone of workload on conversion

* performance: avoid allocating vector for all resources

* intern: xds types

* performance: optimize endpoint_uid

* perf: do not allocate endpoints vector

* performance: do not clone services map

* use arcstr instead

* metrics back on

* Tests compile

* format

* fix and format

* Move rbac over too

* Move more over

* rebase

(cherry picked from commit 5eb8906)

* add missing local example (#1014)

* add missing local example

* lint

* fmt

(cherry picked from commit 3c7fc71)

* logging: disable regex (#987)

(cherry picked from commit c68413be4387680372df53fb496b50132fb6fef3)
(cherry picked from commit 4605fdb)

---------

Co-authored-by: Yuval Kohavi <yuval.kohavi@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
cherrypick/release-1.22 Set this label on a PR to auto-merge it to the release-1.22 branch size/XXL Denotes a PR that changes 1000+ lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

String optimizations for xDS
3 participants