prediction

package
v1.4.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Feb 26, 2024 License: Apache-2.0 Imports: 25 Imported by: 0

Documentation

Index

Constants

View Source
const (
	DefaultNodeID        = "__node__"
	DefaultNodeItemIDFmt = "__node-%s__"
	SystemItemID         = "sys"      // node item ID for the system overhead which is not counted in any pod
	AllPodsItemID        = "all-pods" // not stored for now, just used for calculating the sys
)
View Source
const (
	TmpFileSuffix = ".tmp"
)

Variables

View Source
var (
	// MinSampleWeight is the minimal weight of any sample (prior to including decaying factor)
	MinSampleWeight = 0.1

	// DefaultHistogramBucketSizeGrowth is the default value for histogramBucketSizeGrowth.
	DefaultHistogramBucketSizeGrowth = 0.05
)

Functions

func NewFileCheckpointer

func NewFileCheckpointer(path string) *fileCheckpointer

NewFileCheckpointer creates a new file-based checkpointer with the specified directory.

Types

type Checkpointer

type Checkpointer interface {
	Save(checkpoint ModelCheckpoint) error
	Remove(UID UIDType) error
	Restore() ([]*ModelCheckpoint, error)
}

Checkpointer is an interface for saving and restoring model checkpoints.

type Config

type Config struct {
	CheckpointFilepath           string
	ColdStartDuration            time.Duration
	SafetyMarginPercent          int
	MemoryHistogramDecayHalfLife time.Duration
	CPUHistogramDecayHalfLife    time.Duration
	TrainingInterval             time.Duration
	ModelExpirationDuration      time.Duration
	ModelCheckpointInterval      time.Duration
	ModelCheckpointMaxPerStep    int
}

func NewDefaultConfig

func NewDefaultConfig() *Config

func (*Config) InitFlags

func (c *Config) InitFlags(fs *flag.FlagSet)

type Informer

type Informer interface {
	HasSynced() bool
	ListPods() []*v1.Pod
	GetNode() *v1.Node
}

FIXME This is used for the agent's dependence on the basic data structure, and the basic data structure will be reconstructed later to better support testing.

func NewInformer

func NewInformer(statesInformer statesinformer.StatesInformer) Informer

type MetricDesc

type MetricDesc struct {
	UID UIDType
}

type MetricKey

type MetricKey int
const (
	CPUUsage MetricKey = iota
	MemoryUsage
)

type MetricServer

type MetricServer interface {
	GetPodMetric(desc MetricDesc, m MetricKey) (float64, error)
	GetNodeMetric(desc MetricDesc, m MetricKey) (float64, error)
}

func NewMetricServer

func NewMetricServer(metricCache metriccache.MetricCache, dataInterval time.Duration) MetricServer

type ModelCheckpoint

type ModelCheckpoint struct {
	UID         UIDType
	CPU         *histogram.HistogramCheckpoint
	Memory      *histogram.HistogramCheckpoint
	LastUpdated metav1.Time

	Error error `json:"-,omitempty"`
}

ModelCheckpoint represents a checkpoint for a model.

type NodeItemsUsage

type NodeItemsUsage struct {
	// MetricMap maps an item to its predict metric.
	// e.g.
	//      PriorityProd -> {6.2 cores, 20 GiB}
	//      sys          -> {0.1 cores, 4 GiB}
	MetricMap map[string]*PredictMetric
}

func NewNodeItemUsage

func NewNodeItemUsage() *NodeItemsUsage

func (*NodeItemsUsage) AddMetric

func (m *NodeItemsUsage) AddMetric(itemID string, cpuUsage, memoryUsage float64)

func (*NodeItemsUsage) GetMetric

func (m *NodeItemsUsage) GetMetric(itemID string) (*PredictMetric, bool)

type Options

type Options struct {
	Filepath string
}

type PredictMetric

type PredictMetric struct {
	LastCPUUsage    float64
	LastMemoryUsage float64
}

type PredictModel

type PredictModel struct {
	CPU    histogram.Histogram
	Memory histogram.Histogram

	LastUpdated      time.Time
	LastCheckpointed time.Time
	Lock             sync.Mutex
}

type PredictServer

type PredictServer interface {
	Setup(statesinformer.StatesInformer, metriccache.MetricCache) error
	Run(stopCh <-chan struct{}) error
	HasSynced() bool
	GetPrediction(MetricDesc) (Result, error)
}

PredictServer is responsible for fetching data from MetricCache, training prediction results according to predefined models, and providing an interface for obtaining prediction results.

It is important to note that the prediction results made by PredictServer based on the captured data are only related to the data it sees. For example, when we need to deal with cold starts, this business logic should be processed when using the predicted data instead of being coupled to the predictive model.

The predictive model currently provides histogram-based statistics with exponentially decaying weights over time periods. PredictServer is responsible for storing the intermediate results of the model and recovering when the process restarts.

func NewPeakPredictServer

func NewPeakPredictServer(cfg *Config) PredictServer

type Predictor

type Predictor interface {
	GetPredictorName() string
	AddPod(pod *v1.Pod) error
	GetResult() (v1.ResourceList, error)
}

type PredictorFactory

type PredictorFactory interface {
	New(PredictorType) Predictor
}

PredictorFactory is an interface for creating predictors of different types.

func NewEmptyPredictorFactory

func NewEmptyPredictorFactory() PredictorFactory

func NewPredictorFactory

func NewPredictorFactory(predictServer PredictServer, coldStartDuration time.Duration, safetyMarginPercent int) PredictorFactory

NewPredictorFactory creates a new instance of PredictorFactory.

type PredictorType

type PredictorType int

PredictorType defines constants for different types of predictors.

const (
	// ProdReclaimablePredictor represents the type of a reclaimable production predictor.
	ProdReclaimablePredictor PredictorType = iota
)

type Result

type Result struct {
	// Use different quantile type as key, currently support "p60", "p90", "p95" "p98", "max".
	Data map[string]v1.ResourceList
}

type UIDGenerator

type UIDGenerator interface {
	Pod(pod *v1.Pod) UIDType
	Node() UIDType
	NodeItem(itemID string) UIDType // generate a UID for the item supposed to unique on the node
}

type UIDType

type UIDType string

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL