-
Notifications
You must be signed in to change notification settings - Fork 370
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
Reduce Antrea binary sizes #5883
Comments
I was incorrect before: when using On a separate not, I have noticed the following discrepancy: the antctl binaries included in release assets have debug symbols stripped while the antctl binaries included in Docker images do not. |
It seems the discrepancy has been there for a long time: #517 stripped the binary in release asset since it was introduced. Maybe we should just add the flags to image build workflow?
I found there is an unnecessary import causing significant size increase: |
This reduces binary sizes by around 30%, which in turn reduces the size of Antrea container images. If by any chance someone needs to create a binary / image with debug symbols, they should edit LDFLAGS / GOFLAGS in the Makefile directly. We also remove system paths from binaries using the "-trimpath" Go flag, which is best practice when shipping Go binaries. For antrea-io#5883 Signed-off-by: Antonin Bas <[email protected]>
This reduces binary sizes by around 30%, which in turn reduces the size of Antrea container images. If by any chance someone needs to create a binary / image with debug symbols, they should edit LDFLAGS / GOFLAGS in the Makefile directly. We also remove system paths from binaries using the "-trimpath" Go flag, which is best practice when shipping Go binaries. For #5883 Signed-off-by: Antonin Bas <[email protected]>
Can we leverage the busybox way to combine all antrea executables into one binary?
|
@xliuxu thank you for the proposal and the data. I can see the benefit to the image sizes, but it would also increase sizes of smaller binaries which needs to be distributed as individual executables, i.e. antrea-cni and antctl.
Besides, the fact that the combined binary is not far larger than antrea-agent and antrea-controller may indicate that each component is almost fully importing the other's code and there should be some spaces to improve. @antoninbas what's your opinion? |
I feel the same way as @tnqn. That capability is great for programs that are meant to be shipped together most of the time, while preserving the ability to build them as separate binaries if needed. It may be better to put some additional effort into stripping unnecessary dependencies from |
We are in pretty good shape for the v2.0 release, and several improvements have been made to reduce binary sizes by re-organizing code to avoid unnecessary imports (#6037, #6038). I think that we should still make one more audit to confirm that we are in a good place and that there is no obvious improvement that can be made, so I will keep the issue open for now, but I will remove it from the v2.0 milestone. |
This issue is stale because it has been open 90 days with no activity. Remove stale label or comment, or this will be closed in 90 days |
@antoninbas do you see any TODO for the item |
It would be nice to check if some imports are responsible for a big chunk of the binary sizes. |
@tnqn pointed out at the Antrea community meeting that the
antctl
binary which we include in the Antrea Docker image (as well as in release assets) is pretty large, almost 100MB, compared to binaries from other projects (for example,kubectl
is only 50MB, yet packs more "features").K8s uses https://github.com/kubernetes/kubernetes/blob/master/hack/lib/golang.sh to build production binaries, and it is probably a good reference.
A quick experiment revealed that building
antctl
withgo build --ldflags "-s -w"
, which removes debug symbols, reduced the size ofantctl-linux
by around 30%.before:
after:
This is a pretty significant gain.
The obvious drawback is that if(not accurate: we still get useful stack traces). However, it is very common to trim debug symbols from production binaries.antctl
panics "in the field", we won't have a useful traceback to use for troubleshootingRemoving debug symbols is a pretty low-hanging fruit. There may be other things we can do to further reduce binary sizes. Use this issue to document investigations.
antctl
release binaries(we already remove them from release assets, but not from antctl binaries included in container images). We could also remove debug symbols from other Antrea binaries (antrea-agent
,antrea-controller
),but that may impact our ability to troubleshoot issues in live clusterswith no significant drawback (see below)..-trimpath
. Unlikely to reduce the size much, but this is good practice. There should be no drawback.The text was updated successfully, but these errors were encountered: