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

perf: remove expensive reflection from xDS hot path #14934

Merged
merged 6 commits into from
Oct 14, 2022

Conversation

boxofrad
Copy link
Contributor

Description

Replaces the reflection-based implementation of proxycfg's ConfigSnapshot.Clone with code generated by deep-copy.

While load testing server-based xDS (for consul-dataplane) we discovered this method is extremely expensive.

Screenshot 2022-10-06 at 12 16 42

The ConfigSnapshot struct, directly or indirectly, contains a copy of many of the structs in the agent/structs package, which creates a large graph for copystructure.Copy to traverse at runtime, on every proxy reconfiguration. This is particularly a problem when updating "global" resources such as wildcard intentions or proxy-defaults which triggers a thundering herd of updates (and in our tests caused Raft leadership instability).

Testing & Reproduction steps

We test the completeness of Clone by using gofuzz to construct a "full" snapshot, cloning it, and then comparing the clone to the original.

The Envoy integration tests should also catch any regressions.

@boxofrad boxofrad requested review from rboyer and riddhi89 October 10, 2022 21:47
Replaces the reflection-based implementation of proxycfg's
ConfigSnapshot.Clone with code generated by deep-copy.

While load testing server-based xDS (for consul-dataplane) we discovered
this method is extremely expensive. The ConfigSnapshot struct, directly
or indirectly, contains a copy of many of the structs in the agent/structs
package, which creates a large graph for copystructure.Copy to traverse
at runtime, on every proxy reconfiguration.
@boxofrad boxofrad force-pushed the boxofrad/proxycfg-snapshot-clone-no-reflection branch from f6101cb to ff3a827 Compare October 10, 2022 21:52

package pbpeering

// DeepCopy generates a deep copy of *PeeringTrustBundle
Copy link
Member

Choose a reason for hiding this comment

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

Shouldn't protobufs use proto.Clone instead?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Maybe, yeah. Although it'd be a bit of a shame to introduce reflection (or at least protobuf's reflection thing) when this type doesn't use any fancy protobuf features.

proto/pbpeering/peering.go Outdated Show resolved Hide resolved
GNUmakefile Show resolved Hide resolved
@boxofrad boxofrad requested a review from rboyer October 13, 2022 11:04
@boxofrad boxofrad merged commit e6b55d1 into main Oct 14, 2022
@boxofrad boxofrad deleted the boxofrad/proxycfg-snapshot-clone-no-reflection branch October 14, 2022 09:26
boxofrad added a commit that referenced this pull request Feb 15, 2023
Backport of #14934 to 1.13 release series.

Replaces the reflection-based implementation of proxycfg's
ConfigSnapshot.Clone with code generated by deep-copy.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants