Skip to content

avoid unnecessary copy virtual services for sidecar scope calculation #41101

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

Conversation

yingzhuivy
Copy link
Member

@yingzhuivy yingzhuivy commented Sep 21, 2022

Please provide a description of this PR:
Our production init push context time is very long (roughly 40s), and CPU profile shows that more than 20% of cpu time is spent on the VirtualServicesForGateway function:
https://github.com/istio/istio/blob/1.14.4/pilot/pkg/model/push_context.go#L863-L875

This function is called for every sidecar's egress host, for calculating the virtual services that are imported by the egress host. We have more than 10k sidecars and suppose each sidecar has 10 egress hosts, this function is called 100k times. This "make slice" and "slice copy" are expansive on such magnitude.

Such copy is unnecessary though. Instead of passing in the copied and merged version of the virtual services, just pass the virtualServiceIndex into the select function directly. From our testing, this improves the init context time to roughly 25s.

To help us figure out who should review this PR, please put an X in all the areas that this PR affects.

  • Ambient
  • Configuration Infrastructure
  • Docs
  • Installation
  • Networking
  • Performance and Scalability
  • Policies and Telemetry
  • Security
  • Test and Release
  • User Experience
  • Developer Infrastructure

Please check any characteristics that apply to this pull request.

  • Does not have any user-facing changes. This may include CLI changes, API changes, behavior changes, performance improvements, etc.

After DeepCopy improvements, init context time takes roughly 39s,
and more than 20% of cpu time is spent on the VirtualServicesForGateway
function:
https://github.com/istio/istio/blob/1.14.4/pilot/pkg/model/push_context.go#L863-L875

This function is called for every sidecar's egress host, for calculating
the virtual services that are imported by the egress host. We have more
than 10k sidecars and suppose each sidecar has 10 egress hosts, this
function is called 100k times. What makes it worse is that all our
virtual services are public (exportTo: *), so VirtualServicesForGateway
creates and copies all virtual services (roughly also more than 10k)
each time. This "make slice" and "slice copy" are expansive on such
magnitude.

This CL gets rid of such copy, instead of passing in the copied and
merged version of the virtual services, just pass the
virtualServiceIndex into the select function directly. This improves
the init context time to roughly 25s.

Change-Id: I48015e750a1019f12dfc35b0ca42b72fddfa87ba
Reviewed-on: https://gerrit.musta.ch/c/public/istio/+/3745
Reviewed-by: Jungho Ahn <jungho.ahn@airbnb.com>
Reviewed-by: Weibo He <weibo.he@airbnb.com>
@yingzhuivy yingzhuivy requested a review from a team as a code owner September 21, 2022 20:58
@istio-policy-bot istio-policy-bot added area/perf and scalability release-notes-none Indicates a PR that does not require release notes. labels Sep 21, 2022
@istio-testing istio-testing added the size/M Denotes a PR that changes 30-99 lines, ignoring generated files. label Sep 21, 2022
@hzxuzhonghu
Copy link
Member

cc @ramaraochavali I donot have bandwidth today, can you ptal

Copy link
Contributor

@ramaraochavali ramaraochavali left a comment

Choose a reason for hiding this comment

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

LGTM

@istio-testing istio-testing merged commit e40f57e into istio:master Sep 22, 2022
airbnb-gerrit pushed a commit to airbnb/istio that referenced this pull request Oct 4, 2022
This CL patches commit e40f57e from
upstream istio into air-release-1.14.4 to improve propagation delay.

Original PR:
istio#41101

Change-Id: I7b0da42f591a6da9e20342235ccbf93f2741132b
Reviewed-on: https://gerrit.musta.ch/c/public/istio/+/3822
Reviewed-by: Weibo He <weibo.he@airbnb.com>
airbnb-gerrit pushed a commit to airbnb/istio that referenced this pull request Oct 12, 2022
Apply the following list of patches to istio 1.14.5:
* sidecar: filter service ports to VS ports (istio#39067)
* istio: register init push context metric (istio#40049)
* istio: add metric for debouncing (istio#40523)
* istio: fix PILOT_ENABLE_RDS_CACHE flag not working (istio#40719)
* istio: support inline multi-values header in authz header match
(https://gerrit.musta.ch/c/public/istio/+/3622,
not yet merged upstream)
* istio: improve deep copy for ServiceAttribute (istio#40966)
* avoid unnecessary copy virtual services for sidecar scope calculation (istio#41101)

Change-Id: Ia4c9bfd619a0eb38c1a829bff2efbd21fd3b9cb2
Reviewed-on: https://gerrit.musta.ch/c/public/istio/+/3883
Reviewed-by: Ying Zhu <ying.zhu@airbnb.com>
Reviewed-by: Weibo He <weibo.he@airbnb.com>
airbnb-gerrit pushed a commit to airbnb/istio that referenced this pull request Nov 10, 2022
Apply the following list of upstream commits to istio 1.15.3:
* istio: add metric for debouncing (istio#40523)
* istio: fix PILOT_ENABLE_RDS_CACHE flag not working (istio#40719)
* istio: improve deep copy for ServiceAttribute (istio#40966)
* avoid unnecessary copy virtual services for sidecar scope calculation
  (istio#41101)

Change-Id: I2ee1d77d096a329dc8f590151223b37193dd4f1b
Reviewed-on: https://gerrit.musta.ch/c/public/istio/+/3990
Reviewed-by: Ying Zhu <ying.zhu@airbnb.com>
Reviewed-by: Ryan Smick <ryan.smick@airbnb.com>
@S-Chan
Copy link
Contributor

S-Chan commented Jan 4, 2023

/cherrypick release-1.15

@istio-testing
Copy link
Collaborator

@S-Chan: new pull request created: #42671

In response to this:

/cherrypick release-1.15

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository.

airbnb-gerrit pushed a commit to airbnb/istio that referenced this pull request Feb 10, 2023
Apply the following list of upstream commits to istio 1.15.5:
* istio: add metric for debouncing (istio#40523)
* istio: improve deep copy for ServiceAttribute (istio#40966)
* avoid unnecessary copy virtual services for sidecar scope calculation
  (istio#41101)

Change-Id: I25f31e5633b77982606912bcb2ad2bc4e2da87f4
Reviewed-on: https://gerrit.musta.ch/c/public/istio/+/4381
Reviewed-by: Weibo He <weibo.he@airbnb.com>
Reviewed-by: Stephen Chan <stephen.chan@airbnb.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/perf and scalability release-notes-none Indicates a PR that does not require release notes. size/M Denotes a PR that changes 30-99 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants