kubernetes-sigs / kube-scheduler-wasm-extension

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

Run codec benchmarks in wasm #61

Closed codefromthecrypt closed 9 months ago

codefromthecrypt commented 9 months ago

What type of PR is this?

/kind cleanup

What this PR does / why we need it:

This changes the guest codec benchmarks to actually run in wasm. By using TinyGo with wazero, we can see performance of unmarshal realistically. Before, the benchmarks were run in normal go, even if they used the same library as the guest used.

When you run make bench, tinygo compiles the benchmarks to wasm, and then runs that wasm with wazero. So, the console output is coming from wasm functions compiled from Go benchmarks.

Our makefile ensures that the wazero version is the same as what the scheduler plugin uses (via go.mod). Since the wazero command configures the module to use real clocks, the performance report should be accurate.

Which issue(s) this PR fixes:

NONE

Special notes for your reviewer:

This doesn't solve for real data yet because I can't get the yaml to proto converter to work in TinyGo. We may want to check in serialized protos as they aren't that big.

Does this PR introduce a user-facing change?

NONE

What are the benchmark results of this change?

$ make bench-guest
BenchmarkUnmarshalVT/node:_small             1588876           761.6 ns/op
BenchmarkUnmarshalVT/node:_small             1553385           756.4 ns/op
BenchmarkUnmarshalVT/node:_small             1608015           779.7 ns/op
BenchmarkUnmarshalVT/node:_small             1602940           750.1 ns/op
BenchmarkUnmarshalVT/node:_small             1573089           774.9 ns/op
BenchmarkUnmarshalVT/node:_small             1599826           750.2 ns/op
BenchmarkUnmarshalVT/pod:_small               475982          2544 ns/op
BenchmarkUnmarshalVT/pod:_small               476852          2552 ns/op
BenchmarkUnmarshalVT/pod:_small               478239          2610 ns/op
BenchmarkUnmarshalVT/pod:_small               438692          2533 ns/op
BenchmarkUnmarshalVT/pod:_small               480537          2503 ns/op
BenchmarkUnmarshalVT/pod:_small               484261          2521 ns/op
PASS
ok      sigs.k8s.io/kube-scheduler-wasm-extension/internal/e2e/guest    20.972s
codefromthecrypt commented 9 months ago

cc @anuraaga pretty cool nottinygc runs inside the benchmark runner. So, we can get a realistic performance view (since our main code use nottinygc running bench without it wouldn't be relevant)

k8s-ci-robot commented 9 months ago

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: codefromthecrypt, 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)~~ [codefromthecrypt,sanposhiho] Approvers can indicate their approval by writing `/approve` in a comment Approvers can cancel approval by writing `/approve cancel` in a comment