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

feat(sysadvisor): implement borwein algorithm #307

Merged
merged 3 commits into from
Oct 19, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 10 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -52,10 +52,10 @@ generate:
## --------------------------------------

.PHONY: generate-pb
generate-pb: generate-sys-advisor-cpu-plugin generate-advisor-svc
generate-pb: generate-sys-advisor-cpu-plugin generate-advisor-svc generate-borwein-inference-svc

SysAdvisorCPUPluginPath = $(MakeFilePath)/pkg/agent/qrm-plugins/cpu/dynamicpolicy/cpuadvisor/
.PHONY: generate-sys-advisor-cpu-plugin ## Generate Protocol for cpu resource plugin with sys-advisor
.PHONY: generate-sys-advisor-cpu-plugin ## Generate protocol for cpu resource plugin with sys-advisor
generate-sys-advisor-cpu-plugin:
if [ ! -d $(GOPATH)/src/github.com/kubewharf/kubelet ]; then git clone https://github.com/kubewharf/kubelet.git $(GOPATH)/src/github.com/kubewharf/kubelet; fi
targetTag=`cat $(MakeFilePath)/go.mod | grep kubewharf/kubelet | awk '{print $$4}'` && \
Expand All @@ -72,7 +72,7 @@ generate-sys-advisor-cpu-plugin:
sed "$${sedi[@]}" s,github.com/kubewharf/kubelet,k8s.io/kubelet,g $(SysAdvisorCPUPluginPath)cpu.pb.go

AdvisorSvcPath = $(MakeFilePath)/pkg/agent/qrm-plugins/advisorsvc/
.PHONY: generate-advisor-svc ## Generate Protocol for general qrm-plugin with sys-advisor
.PHONY: generate-advisor-svc ## Generate protocol for general qrm-plugin with sys-advisor
generate-advisor-svc:
if [ ! -d $(GOPATH)/src/github.com/kubewharf/kubelet ]; then git clone https://github.com/kubewharf/kubelet.git $(GOPATH)/src/github.com/kubewharf/kubelet; fi
targetTag=`cat $(MakeFilePath)/go.mod | grep kubewharf/kubelet | awk '{print $$4}'` && \
Expand All @@ -88,6 +88,13 @@ generate-advisor-svc:
if [ `uname` == "Linux" ]; then sedi=(-i); else sedi=(-i ""); fi && \
sed "$${sedi[@]}" s,github.com/kubewharf/kubelet,k8s.io/kubelet,g $(AdvisorSvcPath)advisor_svc.pb.go

BorweinInferenceSvcPath = $(MakeFilePath)/pkg/agent/sysadvisor/plugin/inference/models/borwein/inferencesvc/
.PHONY: generate-borwein-inference-svc ## Generate protocol for borwein inference service
generate-borwein-inference-svc:
protoc -I=$(BorweinInferenceSvcPath) -I=$(GOPATH)/src/ -I=$(GOPATH)/pkg/mod/ --gogo_out=plugins=grpc,paths=source_relative:$(BorweinInferenceSvcPath) $(BorweinInferenceSvcPath)inference_svc.proto && \
cat $(MakeFilePath)/hack/boilerplate.go.txt "$(BorweinInferenceSvcPath)inference_svc.pb.go" > tmpfile && mv tmpfile "$(BorweinInferenceSvcPath)inference_svc.pb.go"


## --------------------------------------
## Cleanup / Verification
## --------------------------------------
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
/*
Copyright 2022 The Katalyst Authors.

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

package inference

import (
"time"

cliflag "k8s.io/component-base/cli/flag"

"github.com/kubewharf/katalyst-core/pkg/config/agent/sysadvisor/inference"
)

const (
defaultInferenceSyncPeriod = 5 * time.Second
)

// InferencePluginOptions holds the configurations for inference plugin.
type InferencePluginOptions struct {
SyncPeriod time.Duration
}

// NewInferencePluginOptions creates a new Options with a default config.
func NewInferencePluginOptions() *InferencePluginOptions {
return &InferencePluginOptions{
SyncPeriod: defaultInferenceSyncPeriod,
}
}

// AddFlags adds flags to the specified FlagSet.
func (o *InferencePluginOptions) AddFlags(fss *cliflag.NamedFlagSets) {
fs := fss.FlagSet("inference_plugin")

fs.DurationVar(&o.SyncPeriod, "inference-sync-period", o.SyncPeriod, "Period for inference plugin to sync")
}

// ApplyTo fills up config with options
func (o *InferencePluginOptions) ApplyTo(c *inference.InferencePluginConfiguration) error {
c.SyncPeriod = o.SyncPeriod
return nil
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
/*
Copyright 2022 The Katalyst Authors.

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

package borwein

import (
"github.com/spf13/pflag"

"github.com/kubewharf/katalyst-core/pkg/config/agent/sysadvisor/qosaware/model/borwein"
)

type BorweinOptions struct {
InferenceServiceSocketAbsPath string
}

func NewBorweinOptions() *BorweinOptions {
return &BorweinOptions{}
}

// AddFlags adds flags to the specified FlagSet.
func (o *BorweinOptions) AddFlags(fs *pflag.FlagSet) {
fs.StringVar(&o.InferenceServiceSocketAbsPath, "borwein-inference-svc-socket-path", o.InferenceServiceSocketAbsPath,
"socket path which borwein inference server listens at")
}

// ApplyTo fills up config with options
func (o *BorweinOptions) ApplyTo(c *borwein.BorweinConfiguration) error {
// todo: currently BorweinParameters, NodeFeatureNames, ContainerFeatureNames are defined statically without options
c.InferenceServiceSocketAbsPath = o.InferenceServiceSocketAbsPath
return nil
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
/*
Copyright 2022 The Katalyst Authors.

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

package model

import (
"github.com/spf13/pflag"
"k8s.io/apimachinery/pkg/util/errors"

"github.com/kubewharf/katalyst-core/cmd/katalyst-agent/app/options/sysadvisor/qosaware/model/borwein"
"github.com/kubewharf/katalyst-core/pkg/config/agent/sysadvisor/qosaware/model"
)

// ModelConfiguration holds options of models used in qos aware plugin
type ModelOptions struct {
*borwein.BorweinOptions
}

// NewModelOptions creates new Options with default config
func NewModelOptions() *ModelOptions {
return &ModelOptions{
BorweinOptions: borwein.NewBorweinOptions(),
}
}

// AddFlags adds flags to the specified FlagSet.
func (o *ModelOptions) AddFlags(fs *pflag.FlagSet) {
o.BorweinOptions.AddFlags(fs)
}

// ApplyTo fills up config with options
func (o *ModelOptions) ApplyTo(c *model.ModelConfiguration) error {

var errList []error
errList = append(errList, o.BorweinOptions.ApplyTo(c.BorweinConfiguration))

return errors.NewAggregate(errList)
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import (
"k8s.io/apimachinery/pkg/util/errors"
cliflag "k8s.io/component-base/cli/flag"

"github.com/kubewharf/katalyst-core/cmd/katalyst-agent/app/options/sysadvisor/qosaware/model"
"github.com/kubewharf/katalyst-core/cmd/katalyst-agent/app/options/sysadvisor/qosaware/reporter"
"github.com/kubewharf/katalyst-core/cmd/katalyst-agent/app/options/sysadvisor/qosaware/resource"
"github.com/kubewharf/katalyst-core/cmd/katalyst-agent/app/options/sysadvisor/qosaware/server"
Expand All @@ -39,6 +40,7 @@ type QoSAwarePluginOptions struct {
*resource.ResourceAdvisorOptions
*server.QRMServerOptions
*reporter.HeadroomReporterOptions
*model.ModelOptions
}

// NewQoSAwarePluginOptions creates a new Options with a default config.
Expand All @@ -48,6 +50,7 @@ func NewQoSAwarePluginOptions() *QoSAwarePluginOptions {
ResourceAdvisorOptions: resource.NewResourceAdvisorOptions(),
QRMServerOptions: server.NewQRMServerOptions(),
HeadroomReporterOptions: reporter.NewHeadroomReporterOptions(),
ModelOptions: model.NewModelOptions(),
}
}

Expand All @@ -60,6 +63,7 @@ func (o *QoSAwarePluginOptions) AddFlags(fss *cliflag.NamedFlagSets) {
o.ResourceAdvisorOptions.AddFlags(fs)
o.QRMServerOptions.AddFlags(fs)
o.HeadroomReporterOptions.AddFlags(fs)
o.ModelOptions.AddFlags(fs)
}

// ApplyTo fills up config with options
Expand All @@ -70,6 +74,7 @@ func (o *QoSAwarePluginOptions) ApplyTo(c *qosaware.QoSAwarePluginConfiguration)
errList = append(errList, o.ResourceAdvisorOptions.ApplyTo(c.ResourceAdvisorConfiguration))
errList = append(errList, o.QRMServerOptions.ApplyTo(c.QRMServerConfiguration))
errList = append(errList, o.HeadroomReporterOptions.ApplyTo(c.HeadroomReporterConfiguration))
errList = append(errList, o.ModelOptions.ApplyTo(c.ModelConfiguration))

return errors.NewAggregate(errList)
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import (
"k8s.io/apimachinery/pkg/util/errors"

"github.com/kubewharf/katalyst-core/cmd/katalyst-agent/app/options/sysadvisor/qosaware/resource/cpu/headroom"
"github.com/kubewharf/katalyst-core/cmd/katalyst-agent/app/options/sysadvisor/qosaware/resource/cpu/provision"
"github.com/kubewharf/katalyst-core/pkg/agent/sysadvisor/types"
"github.com/kubewharf/katalyst-core/pkg/config/agent/sysadvisor/qosaware/resource/cpu"
)
Expand All @@ -36,6 +37,7 @@ type CPUAdvisorOptions struct {

*headroom.CPUHeadroomPolicyOptions
*CPUIsolationOptions
*provision.CPUProvisionPolicyOptions
}

// NewCPUAdvisorOptions creates a new Options with a default config
Expand All @@ -51,10 +53,11 @@ func NewCPUAdvisorOptions() *CPUAdvisorOptions {
string(types.QoSRegionTypeIsolation): string(types.CPUHeadroomPolicyCanonical),
string(types.QoSRegionTypeDedicatedNumaExclusive): string(types.CPUHeadroomPolicyCanonical),
},
CPUProvisionAssembler: string(types.CPUProvisionAssemblerCommon),
CPUHeadroomAssembler: string(types.CPUHeadroomAssemblerCommon),
CPUHeadroomPolicyOptions: headroom.NewCPUHeadroomPolicyOptions(),
CPUIsolationOptions: NewCPUIsolationOptions(),
CPUProvisionAssembler: string(types.CPUProvisionAssemblerCommon),
CPUHeadroomAssembler: string(types.CPUHeadroomAssemblerCommon),
CPUHeadroomPolicyOptions: headroom.NewCPUHeadroomPolicyOptions(),
CPUIsolationOptions: NewCPUIsolationOptions(),
CPUProvisionPolicyOptions: provision.NewCPUProvisionPolicyOptions(),
}
}

Expand All @@ -73,6 +76,7 @@ func (o *CPUAdvisorOptions) AddFlags(fs *pflag.FlagSet) {

o.CPUHeadroomPolicyOptions.AddFlags(fs)
o.CPUIsolationOptions.AddFlags(fs)
o.CPUProvisionPolicyOptions.AddFlags(fs)
}

// ApplyTo fills up config with options
Expand All @@ -99,6 +103,6 @@ func (o *CPUAdvisorOptions) ApplyTo(c *cpu.CPUAdvisorConfiguration) error {
var errList []error
errList = append(errList, o.CPUHeadroomPolicyOptions.ApplyTo(c.CPUHeadroomPolicyConfiguration))
errList = append(errList, o.CPUIsolationOptions.ApplyTo(c.CPUIsolationConfiguration))

errList = append(errList, o.CPUProvisionPolicyOptions.ApplyTo(c.CPUProvisionPolicyConfiguration))
return errors.NewAggregate(errList)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
/*
Copyright 2022 The Katalyst Authors.

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

package provision

import (
"github.com/spf13/pflag"
"k8s.io/apimachinery/pkg/util/errors"

provisionconfig "github.com/kubewharf/katalyst-core/pkg/config/agent/sysadvisor/qosaware/resource/cpu/provision"
)

type CPUProvisionPolicyOptions struct {
PolicyRama *PolicyRamaOptions
}

func NewCPUProvisionPolicyOptions() *CPUProvisionPolicyOptions {
return &CPUProvisionPolicyOptions{
PolicyRama: NewPolicyRamaOptions(),
}
}

// ApplyTo fills up config with options
func (o *CPUProvisionPolicyOptions) ApplyTo(c *provisionconfig.CPUProvisionPolicyConfiguration) error {
var errList []error
errList = append(errList, o.PolicyRama.ApplyTo(c.PolicyRama))
return errors.NewAggregate(errList)
}

// AddFlags adds flags to the specified FlagSet.
func (o *CPUProvisionPolicyOptions) AddFlags(fs *pflag.FlagSet) {
o.PolicyRama.AddFlags(fs)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
/*
Copyright 2022 The Katalyst Authors.

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

package provision

import (
"github.com/spf13/pflag"

provisionconfig "github.com/kubewharf/katalyst-core/pkg/config/agent/sysadvisor/qosaware/resource/cpu/provision"
)

type PolicyRamaOptions struct {
EnableBorwein bool
}

func NewPolicyRamaOptions() *PolicyRamaOptions {
return &PolicyRamaOptions{}
}

// AddFlags adds flags to the specified FlagSet.
func (o *PolicyRamaOptions) AddFlags(fs *pflag.FlagSet) {
fs.BoolVar(&o.EnableBorwein, "enable-borwein-in-rama", o.EnableBorwein,
"if set as true, enable borwein model to adjust target indicator offset in rama policy")
}

// ApplyTo fills up config with options
func (o *PolicyRamaOptions) ApplyTo(c *provisionconfig.PolicyRamaConfiguration) error {
c.EnableBorwein = o.EnableBorwein
return nil
}
Loading
Loading