kubernetes-sigs / kube-scheduler-wasm-extension

All the things to make the scheduler extendable with wasm.
Apache License 2.0
86 stars 17 forks source link

Add profile make target #24

Closed codefromthecrypt closed 11 months ago

codefromthecrypt commented 11 months ago

What type of PR is this?

/kind feature

What this PR does / why we need it:

This adds the profile make target, which uses wzprof to generate cpu and memory profiling data from the webassembly guest. This is a basic implementation to help people understand the costs of the current plugin. Ideas welcome to simplify the flow.

Which issue(s) this PR fixes:

NONE

Special notes for your reviewer:

here's an example run:

$ make profile
Main binary filename not available.
Type: cpu
Time: Jun 3, 2023 at 12:43pm (+08)
Duration: 2.11ms, Total samples = 1802.46us (85.52%)
Showing nodes accounting for 1786.46us, 99.11% of 1802.46us total
Dropped 7 nodes (cum <= 9.01us)
      flat  flat%   sum%        cum   cum%
  652.78us 36.22% 36.22%   990.91us 54.98%  runtime.alloc
  174.60us  9.69% 45.90%   174.60us  9.69%  (runtime.gcBlock).state
  163.53us  9.07% 54.98%   163.53us  9.07%  (runtime.gcBlock).setState
  107.92us  5.99% 60.96%   396.75us 22.01%  runtime.stringFromBytes
  100.59us  5.58% 66.54%   527.29us 29.25%  interface:{UnmarshalVT:func:{slice:basic:uint8}{named:error}}.UnmarshalVT$invoke
   83.46us  4.63% 71.17%   422.38us 23.43%  (*sigs.k8s.io/kube-scheduler-wasm-extension/kubernetes/proto/api.NodeStatus).UnmarshalVT
   72.25us  4.01% 75.18%   556.96us 30.90%  (*sigs.k8s.io/kube-scheduler-wasm-extension/kubernetes/proto/api.PodSpec).UnmarshalVT
   46.54us  2.58% 77.76%     1793us 99.48%  main.nameEqualsPodSpec
   43.17us  2.39% 80.16%   412.04us 22.86%  (*sigs.k8s.io/kube-scheduler-wasm-extension/kubernetes/proto/api.Container).UnmarshalVT
   34.87us  1.93% 82.09%   988.71us 54.85%  (sigs.k8s.io/kube-scheduler-wasm-extension/guest.filterArgs).Pod
   33.75us  1.87% 83.97%    57.33us  3.18%  runtime.hashmapSet
   31.04us  1.72% 85.69%   148.21us  8.22%  runtime.hashmapStringSet
   22.34us  1.24% 86.93%   100.50us  5.58%  (*sigs.k8s.io/kube-scheduler-wasm-extension/kubernetes/proto/api.ContainerStatus).UnmarshalVT
   20.71us  1.15% 88.08%   103.17us  5.72%  (*sigs.k8s.io/kube-scheduler-wasm-extension/kubernetes/proto/api.Probe).UnmarshalVT
   20.33us  1.13% 89.20%    51.83us  2.88%  (*sigs.k8s.io/kube-scheduler-wasm-extension/kubernetes/proto/api.EnvVar).UnmarshalVT
   20.29us  1.13% 90.33%    93.17us  5.17%  runtime.hashmapMake
   18.25us  1.01% 91.34%    58.17us  3.23%  (*sigs.k8s.io/kube-scheduler-wasm-extension/kubernetes/proto/meta.Time).UnmarshalVT
   18.17us  1.01% 92.35%   110.62us  6.14%  (*sigs.k8s.io/kube-scheduler-wasm-extension/kubernetes/proto/api.ResourceRequirements).UnmarshalVT
   17.05us  0.95% 93.30%    54.09us  3.00%  runtime.sliceAppend
   15.88us  0.88% 94.18%    19.67us  1.09%  (*sigs.k8s.io/kube-scheduler-wasm-extension/kubernetes/proto/api.SecurityContext).UnmarshalVT
   15.83us  0.88% 95.06%    39.04us  2.17%  (*sigs.k8s.io/kube-scheduler-wasm-extension/kubernetes/proto/api.ContainerState).UnmarshalVT
   15.54us  0.86% 95.92%    61.29us  3.40%  (*sigs.k8s.io/kube-scheduler-wasm-extension/kubernetes/proto/api.HTTPGetAction).UnmarshalVT
   14.33us   0.8% 96.71%    22.67us  1.26%  runtime.hashmapStringHash
   10.12us  0.56% 97.27%    10.12us  0.56%  runtime.hash32
       8us  0.44% 97.72%    22.50us  1.25%  (*sigs.k8s.io/kube-scheduler-wasm-extension/kubernetes/proto/api.ContainerPort).UnmarshalVT
    7.33us  0.41% 98.13%    17.88us  0.99%  (*sigs.k8s.io/kube-scheduler-wasm-extension/kubernetes/proto/meta.OwnerReference).UnmarshalVT
    6.13us  0.34% 98.46%  1802.46us   100%  filter
       6us  0.33% 98.80%   133.17us  7.39%  sigs.k8s.io/kube-scheduler-wasm-extension/guest/internal/imports.getBytes
    3.33us  0.18% 98.98%  1796.33us 99.66%  (sigs.k8s.io/kube-scheduler-wasm-extension/guest/api.FilterFunc).Filter
    2.33us  0.13% 99.11%    11.38us  0.63%  (*sigs.k8s.io/kube-scheduler-wasm-extension/kubernetes/proto/api.ObjectFieldSelector).UnmarshalVT
Main binary filename not available.
Type: alloc_space
Time: Jun 3, 2023 at 12:43pm (+08)
Duration: 80.40ms, Total samples = 26.52kB 
Showing nodes accounting for 26.52kB, 100% of 26.52kB total
Dropped 7 nodes (cum <= 0.13kB)
      flat  flat%   sum%        cum   cum%
   26.52kB   100%   100%    26.52kB   100%  runtime.alloc
         0     0%   100%     3.12kB 11.77%  (*sigs.k8s.io/kube-scheduler-wasm-extension/kubernetes/proto/api.Container).UnmarshalVT
         0     0%   100%     0.28kB  1.04%  (*sigs.k8s.io/kube-scheduler-wasm-extension/kubernetes/proto/api.ContainerState).UnmarshalVT
         0     0%   100%     0.90kB  3.41%  (*sigs.k8s.io/kube-scheduler-wasm-extension/kubernetes/proto/api.ContainerStatus).UnmarshalVT
         0     0%   100%     0.26kB  0.99%  (*sigs.k8s.io/kube-scheduler-wasm-extension/kubernetes/proto/api.EnvVar).UnmarshalVT
         0     0%   100%     0.19kB   0.7%  (*sigs.k8s.io/kube-scheduler-wasm-extension/kubernetes/proto/api.HTTPGetAction).UnmarshalVT
         0     0%   100%     6.27kB 23.64%  (*sigs.k8s.io/kube-scheduler-wasm-extension/kubernetes/proto/api.NodeStatus).UnmarshalVT
         0     0%   100%     4.13kB 15.56%  (*sigs.k8s.io/kube-scheduler-wasm-extension/kubernetes/proto/api.PodSpec).UnmarshalVT
         0     0%   100%     0.39kB  1.47%  (*sigs.k8s.io/kube-scheduler-wasm-extension/kubernetes/proto/api.Probe).UnmarshalVT
         0     0%   100%     1.37kB  5.15%  (*sigs.k8s.io/kube-scheduler-wasm-extension/kubernetes/proto/api.ResourceRequirements).UnmarshalVT
         0     0%   100%     0.40kB  1.50%  (*sigs.k8s.io/kube-scheduler-wasm-extension/kubernetes/proto/meta.Time).UnmarshalVT
         0     0%   100%    11.69kB 44.07%  (sigs.k8s.io/kube-scheduler-wasm-extension/guest.filterArgs).Pod
         0     0%   100%    26.33kB 99.27%  (sigs.k8s.io/kube-scheduler-wasm-extension/guest/api.FilterFunc).Filter
         0     0%   100%     0.19kB  0.73%  _start
         0     0%   100%    26.33kB 99.27%  filter
         0     0%   100%     5.96kB 22.48%  interface:{UnmarshalVT:func:{slice:basic:uint8}{named:error}}.UnmarshalVT$invoke
         0     0%   100%    26.33kB 99.27%  main.nameEqualsPodSpec
         0     0%   100%     2.75kB 10.37%  runtime.hashmapMake
         0     0%   100%     0.70kB  2.64%  runtime.hashmapSet
         0     0%   100%     1.22kB  4.61%  runtime.hashmapStringSet
         0     0%   100%     0.61kB  2.31%  runtime.sliceAppend
         0     0%   100%     6.15kB 23.19%  runtime.stringFromBytes
         0     0%   100%     7.69kB 28.99%  sigs.k8s.io/kube-scheduler-wasm-extension/guest/internal/imports.getBytes

Does this PR introduce a user-facing change?

NONE

What are the benchmark results of this change?

N/A tooling only

codefromthecrypt commented 11 months ago

cc @achille-roussel I was hoping to make this actually run an embedded pprof server, but figured something more manual is a good step one. Feel free to push commits if it isn't that hard to do it.

codefromthecrypt commented 11 months ago

updated the PR desc as this has the latest wzprof which has less warnings in the output. Also the syntax is nicer thanks to @pelletier and @achille-roussel for this great tool!

k8s-ci-robot commented 11 months ago

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: codefromthecrypt, kerthcet, sanposhiho

The full list of commands accepted by this bot can be found here.

The pull request process is described here

Needs approval from an approver in each of these files: - ~~[OWNERS](https://github.com/kubernetes-sigs/kube-scheduler-wasm-extension/blob/main/OWNERS)~~ [kerthcet,sanposhiho] Approvers can indicate their approval by writing `/approve` in a comment Approvers can cancel approval by writing `/approve cancel` in a comment