kmesh-net / kmesh

High Performance ServiceMesh Data Plane Based on Programmable Kernel
https://kmesh.net
Apache License 2.0
452 stars 66 forks source link

The binary size of `kmeshctl` seems too large #946

Open YaoZengzeng opened 1 week ago

YaoZengzeng commented 1 week ago

Task description:

The binary size of kmeshctl as follows:

root@dev:~# ls -lh /usr/local/bin/kmeshctl 
-rwxr-xr-x 1 root root 110M Oct 11 08:11 /usr/local/bin/kmeshctl

In contrast, the binary size of istioctl is:

root@dev:~# ls -lh /usr/local/bin/istioctl 
-rwxr-xr-x 1 root root 87M Sep 24 11:54 /usr/local/bin/istioctl

size of kubectl is:

root@dev:~# ls -lh /usr/local/bin/kubectl 
-rwxr-xr-x 1 root root 46M Sep 24 07:05 /usr/local/bin/kubectl

size of kmesh-daemon:

[root@kmesh-p6cb9 kmesh]# ls -lh /usr/bin/kmesh-daemon 
-r-xr--r-- 1 root root 120M Oct  8 02:59 /usr/bin/kmesh-daemon

Solution:

Maybe optimize go compilation options or remove unnecessary dependencies?

Who can join or take the task:

The good first issue is intended for first-time contributors to get started on his/her contributor journey.

After a contributor has successfully completed 1-2 good first issue's, they should be ready to move on to help wanted items, saving the remaining good first issue for other new contributors.

How to join or take the task:

Just reply on the issue with the message /assign in a separate line.

Then, the issue will be assigned to you.

How to ask for help:

If you need help or have questions, please feel free to ask on this issue. The issue author or other members of the community will guide you through the contribution process.

hzxuzhonghu commented 1 week ago

https://github.com/loov/goda And many other similar tools are there

am6737 commented 1 week ago

/assign

am6737 commented 1 week ago

Hey @hzxuzhonghu

I’ve used goda to generate the dependency graph, but I haven’t been able to identify any unnecessary dependencies. It’s possible that I’m not analyzing it correctly. I need your help

dependency graph

After adding -s -w to the ldflags, the sizes of the binaries are as follows:

ls -lh kmeshctl 
-rwxr-xr-x 1 root root 72M Oct 15 16:49 kmeshctl
ls -lh out/kmesh-daemon 
-r-xr--r-- 1 root root 87M Oct 15 16:43 out/kmesh-daemon

Do you think these sizes are sufficient? Should we consider adding DEBUG flags like all=-N -l, similar to what Kubernetes and Istio do?

kubernetes

  if [[ "${DBG:-}" == 1 ]]; then
      # Debugging - disable optimizations and inlining and trimPath
      gogcflags="${gogcflags} all=-N -l"
  else
      # Not debugging - disable symbols and DWARF, trim embedded paths
      goldflags="${goldflags} -s -w"
      goflags+=("-trimpath")
  fi

istio

ifeq ($(origin DEBUG), undefined)
  BUILDTYPE_DIR:=release
else ifeq ($(DEBUG),0)
  BUILDTYPE_DIR:=release
else
  BUILDTYPE_DIR:=debug
  export GCFLAGS:=all=-N -l
  $(info $(H) Build with debugger information)
endif
hzxuzhonghu commented 1 week ago

The graph is based on kmesh-daemon?

I agree with the suggestion by building with release flag

hzxuzhonghu commented 1 week ago

tree.txt

This is generated with goda tree, ptal, istio.io/istio/pkg/kube seems contains a lot of unneccessary packages. May try to not use it

hzxuzhonghu commented 1 week ago

We can construct port-forwarder from k8s.io/kubectl/pkg/cmd/portforward

am6737 commented 6 days ago

The graph is based on kmesh-daemon?

I agree with the suggestion by building with release flag

I apologize for my misunderstanding of how to use Goda. The graph was actually generated by the command goda graph "./..." | dot -Tsvg -o graph.svg. I realize that this is incorrect, and I appreciate you pointing that out.

am6737 commented 6 days ago

We can construct port-forwarder from k8s.io/kubectl/pkg/cmd/portforward

Thank you for your advice! I really appreciate it, and I will try to write it down.