Skip to content

istio: improve deep copy for ServiceAttribute #40966

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

Merged
merged 2 commits into from
Sep 14, 2022

Conversation

yingzhuivy
Copy link
Member

@yingzhuivy yingzhuivy commented Sep 13, 2022

Please provide a description of this PR:

our istiod CPU profile shows that 10% of time is spent on DeepCopy of ServiceAttribute, so removing the use of copystructure. We already have fuzz test and benchmark for Service DeepCopy, which covers this part since ServiceAttribute is part of Service.

Benchmark results:
(before)

goarch: amd64
pkg: istio.io/istio/pilot/pkg/model
cpu: Intel(R) Core(TM) i9-9980HK CPU @ 2.40GHz
BenchmarkServiceDeepCopy
BenchmarkServiceDeepCopy-16    	  132760	      8190 ns/op
PASS

(after)

goarch: amd64
pkg: istio.io/istio/pilot/pkg/model
cpu: Intel(R) Core(TM) i9-9980HK CPU @ 2.40GHz
BenchmarkServiceDeepCopy
BenchmarkServiceDeepCopy-16    	 1213035	      1019 ns/op
PASS

DeepCopy using reflection is super slow, and a big chunk of init push
context time is doing deep copy. This is already improved a lot by
this PR: istio#37932 (init push context
time drop from 1m30s to 40s). ServiceAttribute DeepCopy is still
taking more than 10% cpu time, so improving this function can further
reduce the init push context time and hence our propagation delay.

Benchmark results:
(before)
goos: darwin
goarch: amd64
pkg: istio.io/istio/pilot/pkg/model
cpu: Intel(R) Core(TM) i9-9980HK CPU @ 2.40GHz
BenchmarkServiceDeepCopy
BenchmarkServiceDeepCopy-16    	  132760	      8190 ns/op
PASS

(after)
goos: darwin
goarch: amd64
pkg: istio.io/istio/pilot/pkg/model
cpu: Intel(R) Core(TM) i9-9980HK CPU @ 2.40GHz
BenchmarkServiceDeepCopy
BenchmarkServiceDeepCopy-16    	 1213035	      1019 ns/op
PASS

Change-Id: Ied3e81d252ccf226bbb8d1d56eb88bff7c146af4
Reviewed-on: https://gerrit.musta.ch/c/public/istio/+/3700
Reviewed-by: Douglas Jordan <douglas.jordan@airbnb.com>
Reviewed-by: Weibo He <weibo.he@airbnb.com>
@yingzhuivy yingzhuivy requested a review from a team as a code owner September 13, 2022 22:59
@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 13, 2022
@istio-testing istio-testing added the size/M Denotes a PR that changes 30-99 lines, ignoring generated files. label Sep 13, 2022
AddressMap contains a mutex which govet complains if we return a
copy, ignoring the vet error (behavior is the same as before).

Change-Id: If0274e6e1412eb50586ea609a07c302557297ad8
Reviewed-on: https://gerrit.musta.ch/c/public/istio/+/3706
Reviewed-by: Weibo He <weibo.he@airbnb.com>
@@ -566,7 +566,49 @@ func (s *ServiceAttributes) DeepCopy() ServiceAttributes {
// Nested mutexes are configured to be ignored by copystructure.Copy.
// Disabling `go vet` warning since this is actually safe in this case.
// nolint: vet
return copyInternal(*s).(ServiceAttributes)
out := *s
Copy link
Member

Choose a reason for hiding this comment

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

remove the above comment

Copy link
Member Author

Choose a reason for hiding this comment

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

followed up in #40990

Copy link
Member

@howardjohn howardjohn left a comment

Choose a reason for hiding this comment

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

#40987 tested it more, lgtm

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

Original PR:
istio#40966

Change-Id: Ib208d94a1f84cd0ac496528470928e35103539e8
Reviewed-on: https://gerrit.musta.ch/c/public/istio/+/3821
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: #42670

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