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

Go binary size regression #26232

Closed
howardjohn opened this issue Aug 6, 2020 · 15 comments
Closed

Go binary size regression #26232

howardjohn opened this issue Aug 6, 2020 · 15 comments

Comments

@howardjohn
Copy link
Member

Agent:
master: 110m
1.6: 74m
1.5: 68m
1.4: 38m

Pilot:
master: 108m
1.6: 90m
1.5: 84m
1.4: 65m

Measured with

for tag in master 1.6.0 1.5.0 1.4.0; do
    echo $tag
    git checkout $tag
    go build -o /tmp/agent ./pilot/cmd/pilot-discovery
    ll /tmp/agent
    echo
done

My theory is the 1.4 -> 1.5 regression in agent is for gateway SDS (pulls in k8s) and then 1.6 -> master regression is google.golang.org/api/compute/v1

cc @rshriram @kyessenov

@howardjohn
Copy link
Member Author

istio-agent basically imports literally everything now since @costinm put an XDS server in it

@kyessenov
Copy link
Contributor

I think that's strange that the client agent is larger than the service. Go doesn't do a good job at code elimination as well.

@kyessenov
Copy link
Contributor

A minimalistic xDS server (e.g. go-control-plane test server) is around 22MB as a point of reference.

@howardjohn
Copy link
Member Author

We also import literally every proto in xds (including v2 and v4) so we can handle envoyfilters which adds a lot

@ericvn
Copy link
Contributor

ericvn commented Aug 11, 2020

@brian-avery Checking against 1.7 branch.

@mandarjog
Copy link
Contributor

Here is the actual effect on memory. Unshared ~= resident - shared.
TLDR;
1.7 Is using ~15 MB per pod more for istio-agent, which I don't think is release blocking.

Istio Version File size Resident Memory Unshared memory Overage
1.5 68M 55M 15M 0
1.6 74M 55M 17M 2M
1.7 110M 80M 30M 15M

Unshared memory costs increase per pod, whereas shared memory costs increase per node.

@mandarjog mandarjog modified the milestones: 1.7, 1.8 Aug 12, 2020
@howardjohn
Copy link
Member Author

howardjohn commented Aug 12, 2020 via email

@howardjohn
Copy link
Member Author

btw -

go 1.14: 101M
go 1.15: 97M

so some small wins..

@howardjohn howardjohn added this to P1 in Prioritization Sep 4, 2020
howardjohn added a commit to howardjohn/istio that referenced this issue Oct 21, 2020
We currently set `STATIC=0 LDFLAGS='-extldflags -static -s -w'` as part of the
build. This does not make much sense, since STATIC sets LDFLAGS to
empty, so we don't pass `-static -s -w`.

I believe we do want to pass these flags, as they were originally added
for a reason.

Binary size changes for istioctl, agent, and pilot in mb:
```
114 -> 81
104 -> 75
108 -> 77
```

Helps with istio#26232
@howardjohn
Copy link
Member Author

Notes to self: useful tools for analyzing:

goda graph -cluster -short ./pilot/cmd/pilot-agent | tee /tmp/goda
cat /tmp/goda | match 'tooltip.* color' | map 'i[9:-7]' | rg pilot/pkg/xds
goweight ./pilot/cmd/pilot-agent | tee /tmp/now | head -n 100
go build -o /tmp -ldflags '-extldflags -static -s -w' ./pilot/cmd/pilot-agent; ll /tmp/pilot-agent; file /tmp/pilot-agent; stat /tmp/pilot-agent

istio-testing pushed a commit that referenced this issue Oct 21, 2020
We currently set `STATIC=0 LDFLAGS='-extldflags -static -s -w'` as part of the
build. This does not make much sense, since STATIC sets LDFLAGS to
empty, so we don't pass `-static -s -w`.

I believe we do want to pass these flags, as they were originally added
for a reason.

Binary size changes for istioctl, agent, and pilot in mb:
```
114 -> 81
104 -> 75
108 -> 77
```

Helps with #26232
@ericvn ericvn modified the milestones: 1.8, Backlog Oct 27, 2020
@Stono
Copy link
Contributor

Stono commented Nov 6, 2020

1.7 Is using ~15 MB per pod more for istio-agent, which I don't think is release blocking.

Hi folks - as someone using istio with a lot of pods, a 25% increase in proxy usage, after we've just took a 10% increase 1.5 -> 1.6 for SDS, is certainly upgrade blocking for us. I have to be honest, as an end user I struggle to see how it wasn't release blocking either or as an absolute minimum, all over the upgrade notes in red to give folks a heads up - as it feels pretty substantial.

howardjohn added a commit to howardjohn/istio that referenced this issue Nov 6, 2020
Part of istio#26232

75mb -> 64mb

We could have also done massive refactoring to avoid using build tags,
but I think in the near future we will need build tags for dropping k8s
import, so it seems useful to implement this at least for the short
term.
@howardjohn
Copy link
Member Author

Doing a bunch of work on https://github.com/howardjohn/istio/pull/new/agent/tiny-binary-full-branch to trim the deps a lot. Down to 37mb currently. 30mb seems feasible. It contains about 15 changes so I will be splitting it out into many smaller prs

howardjohn added a commit to howardjohn/istio that referenced this issue Nov 9, 2020
I am not sure what changed between this being added and now, but I am
fairly sure this is not needed know, as its not possible to import
collections without importing the packages.

This is not strictly neccesary, but allows splitting the kubernetes
imports out for istio#26232 much more
easily.
@Stono
Copy link
Contributor

Stono commented Nov 9, 2020

That's awesome @howardjohn - guessing we're looking at 1.9 for most of them however?

@howardjohn
Copy link
Member Author

Yeah unfortunately so. The bulk of the changes are from dropping Kubernetes imports which is not feasible on older versions.

istio-testing pushed a commit that referenced this issue Nov 9, 2020
* Trim agent binary by 11mb by conditionally compiled XDS filters

Part of #26232

75mb -> 64mb

We could have also done massive refactoring to avoid using build tags,
but I think in the near future we will need build tags for dropping k8s
import, so it seems useful to implement this at least for the short
term.

* Trim another 4mb
istio-testing pushed a commit that referenced this issue Nov 9, 2020
I am not sure what changed between this being added and now, but I am
fairly sure this is not needed know, as its not possible to import
collections without importing the packages.

This is not strictly neccesary, but allows splitting the kubernetes
imports out for #26232 much more
easily.
@howardjohn
Copy link
Member Author

Note sure how much this will impact once we are done trimming, but golang 1.16 will net us a few wins as well:

$ GOOS=linux GOARCH=amd64 LDFLAGS='-extldflags -static -s -w' common/scripts/gobuild.sh ./out/linux_amd64/ -tags="agent" ./pilot/cmd/pilot-agent; ll out/linux_amd64/pilot-agent

real    0m3.178s
user    0m5.407s
sys     0m0.816s
-rwxr-x--- 1 howardjohn primarygroup 61M Nov  9 09:33 out/linux_amd64/pilot-agent*
$ GOBINARY=/tmp/tmp.8k4Q6FfX0t/goroot/bin/go GOOS=linux GOARCH=amd64 LDFLAGS='-extldflags -static -s -w' common/scripts/gobuild.sh ./out/linux_amd64/ -tags="agent" ./pilot/cmd/pilot-agent; ll out/linux_amd64/pilot-agent

real    0m1.987s
user    0m3.605s
sys     0m0.735s
-rwxr-x--- 1 howardjohn primarygroup 55M Nov  9 09:33 out/linux_amd64/pilot-agent*

howardjohn added a commit to howardjohn/istio that referenced this issue Nov 9, 2020
…o#28670)

* Trim agent binary by 11mb by conditionally compiled XDS filters

Part of istio#26232

75mb -> 64mb

We could have also done massive refactoring to avoid using build tags,
but I think in the near future we will need build tags for dropping k8s
import, so it seems useful to implement this at least for the short
term.

* Trim another 4mb

(cherry picked from commit 19c8ea4)
howardjohn added a commit to howardjohn/istio that referenced this issue Nov 9, 2020
…o#28670)

* Trim agent binary by 11mb by conditionally compiled XDS filters

Part of istio#26232

75mb -> 64mb

We could have also done massive refactoring to avoid using build tags,
but I think in the near future we will need build tags for dropping k8s
import, so it seems useful to implement this at least for the short
term.

* Trim another 4mb

(cherry picked from commit 19c8ea4)
istio-testing pushed a commit that referenced this issue Nov 9, 2020
…) (#28718)

* Trim agent binary by 11mb by conditionally compiled XDS filters

Part of #26232

75mb -> 64mb

We could have also done massive refactoring to avoid using build tags,
but I think in the near future we will need build tags for dropping k8s
import, so it seems useful to implement this at least for the short
term.

* Trim another 4mb

(cherry picked from commit 19c8ea4)
istio-testing pushed a commit that referenced this issue Nov 9, 2020
…) (#28717)

* Trim agent binary by 11mb by conditionally compiled XDS filters

Part of #26232

75mb -> 64mb

We could have also done massive refactoring to avoid using build tags,
but I think in the near future we will need build tags for dropping k8s
import, so it seems useful to implement this at least for the short
term.

* Trim another 4mb

(cherry picked from commit 19c8ea4)
howardjohn added a commit to howardjohn/istio that referenced this issue Nov 18, 2020
* Move mesh configmap watcher out of the core `mesh` package
* Move security kubernetes `util`s to its own package

This drops the Kubernetes dependency for the agent completely.

This essentially completes istio#26232
for the agent (but not Istiod).
istio-testing pushed a commit that referenced this issue Nov 19, 2020
* Move mesh configmap watcher out of the core `mesh` package
* Move security kubernetes `util`s to its own package

This drops the Kubernetes dependency for the agent completely.

This essentially completes #26232
for the agent (but not Istiod).
daixiang0 pushed a commit to daixiang0/istio that referenced this issue Nov 19, 2020
…o#28670)

* Trim agent binary by 11mb by conditionally compiled XDS filters

Part of istio#26232

75mb -> 64mb

We could have also done massive refactoring to avoid using build tags,
but I think in the near future we will need build tags for dropping k8s
import, so it seems useful to implement this at least for the short
term.

* Trim another 4mb
@howardjohn
Copy link
Member Author

I am going with the assumption that we don't really care about istiod binary size and the agent is now a fraction of its size (38M), and considering this fixed

Prioritization automation moved this from P1 to Done Nov 24, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Development

No branches or pull requests

6 participants