-
Notifications
You must be signed in to change notification settings - Fork 8.1k
Improve service deepcopy #37932
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
Improve service deepcopy #37932
Conversation
@@ -825,25 +825,29 @@ func GetServiceAccounts(svc *Service, ports []int, discovery ServiceDiscovery) [ | |||
} | |||
|
|||
// DeepCopy creates a clone of Service. | |||
// TODO : See if there is any efficient alternative to this function - copystructure can not be used as is because | |||
// Service has sync.RWMutex that can not be copied. | |||
func (s *Service) DeepCopy() *Service { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Wonder if for our DeepCopy implementations we should add Fuzz tests comparing them to copystructure or something. Then we can ensure our performance optimizations are also correct
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
SGTM
* optimize service deepcopy * benchmark * update * fix lint
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>
* istio: improve deep copy for service attributes 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: #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> * istio: fix lint 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>
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>
Please provide a description of this PR:
remove using copy structure for simple type.