Skip to content

Commit

Permalink
Improve benchmark performance of nodenumber wasm plugin
Browse files Browse the repository at this point in the history
  • Loading branch information
jgiannuzzi committed Nov 10, 2024
1 parent 7f60212 commit fc247bf
Show file tree
Hide file tree
Showing 6 changed files with 20 additions and 5 deletions.
3 changes: 3 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@ golangci_lint := github.com/golangci/golangci-lint/cmd/[email protected]
examples/advanced/main.wasm: examples/advanced/main.go
@(cd $(@D); tinygo build -o main.wasm -gc=custom -tags=custommalloc -scheduler=none --no-debug -target=wasi .)

internal/e2e/scheduler_perf/wasm/nodenumber/main.wasm: internal/e2e/scheduler_perf/wasm/nodenumber/main.go
@(cd $(@D); tinygo build -o main.wasm -gc=custom -tags=custommalloc -scheduler=none --no-debug -target=wasi .)

%/main.wasm: %/main.go
@(cd $(@D); tinygo build -o main.wasm -scheduler=none --no-debug -target=wasi .)

Expand Down
2 changes: 2 additions & 0 deletions internal/e2e/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ require (
github.com/labstack/echo v3.3.10+incompatible
github.com/stealthrocket/wzprof v0.1.5
github.com/tetratelabs/wazero v1.7.2
github.com/wasilibs/nottinygc v0.7.1
go.uber.org/zap v1.19.0
k8s.io/api v0.27.3
k8s.io/apimachinery v0.27.3
Expand Down Expand Up @@ -108,6 +109,7 @@ require (
github.com/josharian/intern v1.0.0 // indirect
github.com/json-iterator/go v1.1.12 // indirect
github.com/labstack/gommon v0.4.0 // indirect
github.com/magefile/mage v1.14.0 // indirect
github.com/mailru/easyjson v0.7.7 // indirect
github.com/mattn/go-colorable v0.1.11 // indirect
github.com/mattn/go-isatty v0.0.14 // indirect
Expand Down
4 changes: 4 additions & 0 deletions internal/e2e/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -304,6 +304,8 @@ github.com/labstack/echo v3.3.10+incompatible h1:pGRcYk231ExFAyoAjAfD85kQzRJCRI8
github.com/labstack/echo v3.3.10+incompatible/go.mod h1:0INS7j/VjnFxD4E2wkz67b8cVwCLbBmJyDaka6Cmk1s=
github.com/labstack/gommon v0.4.0 h1:y7cvthEAEbU0yHOf4axH8ZG2NH8knB9iNSoTO8dyIk8=
github.com/labstack/gommon v0.4.0/go.mod h1:uW6kP17uPlLJsD3ijUYn3/M5bAxtlZhMI6m3MFxTMTM=
github.com/magefile/mage v1.14.0 h1:6QDX3g6z1YvJ4olPhT1wksUcSa/V0a1B+pJb73fBjyo=
github.com/magefile/mage v1.14.0/go.mod h1:z5UZb/iS3GoOSn0JgWuiw7dxlurVYTu+/jHXqQg881A=
github.com/mailru/easyjson v0.7.7 h1:UGYAvKxe3sBsEDzO8ZeWOSlIQfWFlxbzLZe7hwFURr0=
github.com/mailru/easyjson v0.7.7/go.mod h1:xzfreul335JAWq5oZzymOObrkdz5UnU4kGfJJLY9Nlc=
github.com/mattn/go-colorable v0.1.11 h1:nQ+aFkoE2TMGc0b68U2OKSexC+eq46+XwZzWXHRmPYs=
Expand Down Expand Up @@ -417,6 +419,8 @@ github.com/valyala/fasttemplate v1.2.2 h1:lxLXG0uE3Qnshl9QyaK6XJxMXlQZELvChBOCmQ
github.com/valyala/fasttemplate v1.2.2/go.mod h1:KHLXt3tVN2HBp8eijSv/kGJopbvo7S+qRAEEKiv+SiQ=
github.com/vmware/govmomi v0.30.0 h1:Fm8ugPnnlMSTSceDKY9goGvjmqc6eQLPUSUeNXdpeXA=
github.com/vmware/govmomi v0.30.0/go.mod h1:F7adsVewLNHsW/IIm7ziFURaXDaHEwcc+ym4r3INMdY=
github.com/wasilibs/nottinygc v0.7.1 h1:rKu19+SFniRNuSo5NX7/wxpSpXmMUmkcyt/YiWLJg8w=
github.com/wasilibs/nottinygc v0.7.1/go.mod h1:oDcIotskuYNMpqMF23l7Z8uzD4TC0WXHK8jetlB3HIo=
github.com/xiang90/probing v0.0.0-20190116061207-43a291ad63a2 h1:eY9dn8+vbi4tKz5Qo6v2eYzo7kUS51QINcR5jNpbZS8=
github.com/yuin/goldmark v1.1.25/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74=
github.com/yuin/goldmark v1.1.27/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74=
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ profiles:
pluginConfig:
- name: wasm
args:
guestURL: "file://../../../examples/nodenumber/main.wasm"
guestURL: "file://./wasm/nodenumber/main.wasm"
extenders:
- urlPrefix: "http://localhost:8080/"
prioritizeVerb: "priorities"
Expand Down
14 changes: 10 additions & 4 deletions internal/e2e/scheduler_perf/wasm/nodenumber/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,16 @@ import (
"encoding/json"
"fmt"

_ "github.com/wasilibs/nottinygc"

"sigs.k8s.io/kube-scheduler-wasm-extension/guest/api"
"sigs.k8s.io/kube-scheduler-wasm-extension/guest/api/proto"
"sigs.k8s.io/kube-scheduler-wasm-extension/guest/config"
"sigs.k8s.io/kube-scheduler-wasm-extension/guest/enqueue"
"sigs.k8s.io/kube-scheduler-wasm-extension/guest/klog"
klogapi "sigs.k8s.io/kube-scheduler-wasm-extension/guest/klog/api"
"sigs.k8s.io/kube-scheduler-wasm-extension/guest/plugin"
"sigs.k8s.io/kube-scheduler-wasm-extension/guest/prescore"
"sigs.k8s.io/kube-scheduler-wasm-extension/guest/score"
)

// main is compiled to a WebAssembly function named "_start", called by the
Expand All @@ -37,10 +41,12 @@ func main() {
if err != nil {
panic(err)
}
plugin.Set(p)
enqueue.SetPlugin(p)
prescore.SetPlugin(p)
score.SetPlugin(p)
}

func New(klog klogapi.Klog, jsonConfig []byte) (api.Plugin, error) {
func New(klog klogapi.Klog, jsonConfig []byte) (*NodeNumber, error) {
var args nodeNumberArgs
if jsonConfig != nil {
if err := json.Unmarshal(jsonConfig, &args); err != nil {
Expand Down Expand Up @@ -90,7 +96,7 @@ func (pl *NodeNumber) EventsToRegister() []api.ClusterEvent {
}

// PreScore implements api.PreScorePlugin
func (pl *NodeNumber) PreScore(state api.CycleState, pod proto.Pod, _ proto.NodeList) *api.Status {
func (pl *NodeNumber) PreScore(state api.CycleState, pod proto.Pod, _ api.NodeInfoList) *api.Status {
podnum, ok := lastNumber(pod.Spec().GetNodeName())
if !ok {
return nil // return success even if its suffix is non-number.
Expand Down
Binary file modified internal/e2e/scheduler_perf/wasm/nodenumber/main.wasm
100755 → 100644
Binary file not shown.

0 comments on commit fc247bf

Please sign in to comment.