Skip to content

perf(xds): cache the mTLS-injected cluster per entry (drop per-snapshot proto.Clone) #537

Closed

Description

@bpalermo

agent/internal/xds/cache/cluster.go:117-152 (clustersEndpointsAndVhosts): on every snapshot generation, for every cluster with a node SPIFFE ID, we:

  • proto.Clone(entry.cluster) (deep copy of the full cluster proto)
  • rebuild sanURIs with fmt.Sprintf("spiffe://%s/ns/%s/sa/%s", ...) per endpoint namespace
  • re-parse the service key via serviceref.ParseKey
  • re-concatenate the waypoint SNI (entry.sni + "." + proxy.ServiceClusterName(...))
  • call proxy.InjectUpstreamMTLS / proxy.EdgeUpstreamTransportSocket

None of these inputs change per snapshot — they change when the entry is (re)built, when sanNamespaces change, or when the netns→ID map changes. This is O(clusters) proto deep-copies on every push, on every node, constantly during churn.

Fix: precompute the injected cluster (or at minimum the transport socket + sanURIs + waypointSNI) at entry build/invalidation time and store it on clusterEntry; the snapshot path just reads it. Invalidate on the events that actually change the inputs (endpoint namespace set, netns map, node SVID).

Do NOT touch: snapshotMu scope (deliberately serializes version+read+SetSnapshot, see snapshot.go:34-38) and the unified full-snapshot model (partial per-type snapshots clobber other types — the #70-#75 bug class). Same pattern applies to the duplicate sprintf in capture.go:262-265 (captureTCPClusters).

Validation: existing tests + agent.snapshot.generate duration metric should visibly drop.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions