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

Use wire-type compatible source in TinyGo #17

Merged
merged 1 commit into from
May 28, 2023

Conversation

codefromthecrypt
Copy link
Contributor

What type of PR is this?

/kind feature

What this PR does / why we need it:

Before, we had incompatible types, which among other things, made the POC difficult to reason with from a performance point of view. We were manually converting fields, which would never work in practice as the model is quite large.

This uses the real protos k8s does, just generating TinyGo compatible guest code from them. This now serializes the v1.Pod directly from the input type in a way TinyGo can get it. To eliminate a performance hit from filters that don't access the current pod, this extracts a FilterArgs type. Doing so gives us flexibility in implementation, especially as we add more parameters later.

Which issue(s) this PR fixes:

Fixes #13

Special notes for your reviewer:

This change slows down execution, but that's good because it is more realistic. Before we manually copied a single field, so the after is a better baseline. Note: this still doesn't use realistic data, but at least we can generate it now!

$ cd plugin
$ go test -run='^$' -bench '^BenchmarkFilter$' . -count=6 > old.txt
$ go test -run='^$' -bench '^BenchmarkFilter$' . -count=6 > new.txt
$ benchstat old.txt new.txt
goos: darwin
goarch: arm64
pkg: sigs.k8s.io/kube-scheduler-wasm-extension/plugin
                                                    │   old.txt   │              new.txt               │
                                                    │   sec/op    │   sec/op     vs base               │
Filter/success:_node_is_match_with_spec.NodeName-12   12.62µ ± 0%   19.14µ ± 1%  +51.73% (p=0.002 n=6)

@k8s-ci-robot k8s-ci-robot added do-not-merge/invalid-commit-message Indicates that a PR should not merge because it has an invalid commit message. kind/feature Categorizes issue or PR as related to a new feature. cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. labels May 27, 2023
@k8s-ci-robot k8s-ci-robot added the size/XXL Denotes a PR that changes 1000+ lines, ignoring generated files. label May 27, 2023
Copy link
Contributor Author

@codefromthecrypt codefromthecrypt left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

note: using realistic protos increases the base wasm binary size in tinygo to 756KB. Future work may be able to optimize this back without losing features, but it is worth saying this part now.

@codefromthecrypt
Copy link
Contributor Author

ps here is the output from the makefile. Note there are warnings about schema not being in use, but as they are _ imported you would have to change the source to exclude it.

$ make update-kubernetes-proto
cd ./kubernetes/proto/tools; \
	cat tools.go | grep "_" | awk -F'"' '{print $2}' | xargs -tI % go install %
go install github.com/knqyf263/go-plugin/cmd/protoc-gen-go-plugin
go install google.golang.org/protobuf/cmd/protoc-gen-go
echo "Regenerate the Go protobuf code."
Regenerate the Go protobuf code.
cd kubernetes/kubernetes/staging/src/; \
	protoc ./k8s.io/apimachinery/pkg/api/resource/generated.proto --go-plugin_out=../../../proto \
		--go-plugin_opt=Mk8s.io/apimachinery/pkg/api/resource/generated.proto=./resource; \
	protoc ./k8s.io/apimachinery/pkg/runtime/generated.proto --go-plugin_out=../../../proto \
		--go-plugin_opt=Mk8s.io/apimachinery/pkg/runtime/generated.proto=./runtime; \
	protoc ./k8s.io/apimachinery/pkg/runtime/schema/generated.proto --go-plugin_out=../../../proto \
		--go-plugin_opt=Mk8s.io/apimachinery/pkg/runtime/schema/generated.proto=./schema; \
	protoc ./k8s.io/apimachinery/pkg/apis/meta/v1/generated.proto --go-plugin_out=../../../proto \
		--go-plugin_opt=Mk8s.io/apimachinery/pkg/apis/meta/v1/generated.proto=./meta \
		--go-plugin_opt=Mk8s.io/apimachinery/pkg/runtime/generated.proto=sigs.k8s.io/kube-scheduler-wasm-extension/kubernetes/proto/runtime \
		--go-plugin_opt=Mk8s.io/apimachinery/pkg/runtime/schema/generated.proto=sigs.k8s.io/kube-scheduler-wasm-extension/kubernetes/proto/schema; \
	protoc ./k8s.io/apimachinery/pkg/util/intstr/generated.proto --go-plugin_out=../../../proto \
		--go-plugin_opt=Mk8s.io/apimachinery/pkg/util/intstr/generated.proto=./instr; \
	protoc ./k8s.io/api/core/v1/generated.proto --go-plugin_out=../../../proto \
		--go-plugin_opt=Mk8s.io/api/core/v1/generated.proto=./api \
		--go-plugin_opt=Mk8s.io/apimachinery/pkg/api/resource/generated.proto=sigs.k8s.io/kube-scheduler-wasm-extension/kubernetes/proto/resource \
		--go-plugin_opt=Mk8s.io/apimachinery/pkg/apis/meta/v1/generated.proto=sigs.k8s.io/kube-scheduler-wasm-extension/kubernetes/proto/meta \
		--go-plugin_opt=Mk8s.io/apimachinery/pkg/runtime/generated.proto=sigs.k8s.io/kube-scheduler-wasm-extension/kubernetes/proto/runtime \
		--go-plugin_opt=Mk8s.io/apimachinery/pkg/runtime/schema/generated.proto=sigs.k8s.io/kube-scheduler-wasm-extension/kubernetes/proto/schema \
		--go-plugin_opt=Mk8s.io/apimachinery/pkg/util/intstr/generated.proto=sigs.k8s.io/kube-scheduler-wasm-extension/kubernetes/proto/instr;
k8s.io/apimachinery/pkg/apis/meta/v1/generated.proto:25:1: warning: Import k8s.io/apimachinery/pkg/runtime/schema/generated.proto is unused.
k8s.io/api/core/v1/generated.proto:27:1: warning: Import k8s.io/apimachinery/pkg/runtime/schema/generated.proto is unused.

Copy link
Member

@sanposhiho sanposhiho left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One nit, leave it to @kerthcet.

/approve

kubernetes/proto/tools/tools.go Show resolved Hide resolved
@k8s-ci-robot
Copy link
Contributor

[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:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@k8s-ci-robot k8s-ci-robot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label May 28, 2023
Copy link
Contributor

@kerthcet kerthcet left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

/lgtm
Thanks @codefromthecrypt Have a great flight!

protoc ./kubernetes/proto/kubernetes.proto \
--go-plugin_out=./kubernetes/proto --go-plugin_opt=Mkubernetes/proto/kubernetes.proto=./api
cd kubernetes/kubernetes/staging/src/; \
protoc ./k8s.io/apimachinery/pkg/api/resource/generated.proto --go-plugin_out=../../../proto \
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I did this same before, it's annoying at this moment, but I prefer to use the native ones.

@k8s-ci-robot k8s-ci-robot added the lgtm "Looks good to me", indicates that a PR is ready to be merged. label May 28, 2023
@kerthcet
Copy link
Contributor

Please squash you commit it said you have invalid commit message.

@k8s-ci-robot k8s-ci-robot removed the lgtm "Looks good to me", indicates that a PR is ready to be merged. label May 28, 2023
Signed-off-by: Adrian Cole <adrian@tetrate.io>
@k8s-ci-robot k8s-ci-robot removed the do-not-merge/invalid-commit-message Indicates that a PR should not merge because it has an invalid commit message. label May 28, 2023
@codefromthecrypt codefromthecrypt changed the title Uses wire-type compatible generated source in TinyGo Use wire-type compatible source in TinyGo May 28, 2023
@codefromthecrypt
Copy link
Contributor Author

ok I tried a different commit message 🤞

@kerthcet
Copy link
Contributor

/lgtm

@k8s-ci-robot k8s-ci-robot added the lgtm "Looks good to me", indicates that a PR is ready to be merged. label May 28, 2023
@k8s-ci-robot k8s-ci-robot merged commit b4544a1 into kubernetes-sigs:main May 28, 2023
2 checks passed
@codefromthecrypt codefromthecrypt deleted the real-proto branch May 28, 2023 04:37
@codefromthecrypt
Copy link
Contributor Author

Thanks for the fast feedback. now we are unlocked to do more modeling and performance work!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
approved Indicates a PR has been approved by an approver from all required OWNERS files. cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. kind/feature Categorizes issue or PR as related to a new feature. lgtm "Looks good to me", indicates that a PR is ready to be merged. size/XXL Denotes a PR that changes 1000+ lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Generate go source from the same protos used by the scheduler framework
4 participants