Documentation
¶
Index ¶
- Constants
- func ConvertImpact(impact *ResourceImpact) *decision.ResourceImpact
- type AllStats
- type Engine
- func (e *Engine) ActiveWorkers() int
- func (e *Engine) GetStats() *AllStats
- func (e *Engine) GetTaskStats(task string) *TaskStats
- func (e *Engine) Model() Model
- func (e *Engine) NotifyTaskStart(task string, complexity int)
- func (e *Engine) PendingCount() int
- func (e *Engine) Predict(task string, complexity int) *ResourceImpact
- func (e *Engine) Stop()
- func (e *Engine) StopWithTimeout(timeout time.Duration)
- type Model
- type ModelAdapter
- func (a *ModelAdapter) GetStats() *AllStats
- func (a *ModelAdapter) GetTaskStats(task string) *TaskStats
- func (a *ModelAdapter) LoadStats(stats *AllStats)
- func (a *ModelAdapter) Name() string
- func (a *ModelAdapter) Observe(task string, complexity int, impact *ResourceImpact)
- func (a *ModelAdapter) Predict(task string, complexity int) *ResourceImpact
- func (a *ModelAdapter) SetObserver(observer StatsObserver)
- func (a *ModelAdapter) Underlying() model.PredictionModel
- type MovingAverageModel
- func (m *MovingAverageModel) GetStats() *AllStats
- func (m *MovingAverageModel) GetTaskStats(task string) *TaskStats
- func (m *MovingAverageModel) LoadStats(stats *AllStats)
- func (m *MovingAverageModel) Name() string
- func (m *MovingAverageModel) Observe(task string, complexity int, impact *ResourceImpact)
- func (m *MovingAverageModel) Predict(task string, complexity int) *ResourceImpact
- func (m *MovingAverageModel) SetObserver(observer StatsObserver)
- type ResourceImpact
- type StatsObserver
- type TaskRecord
- type TaskStartRequest
- type TaskStartResponse
- type TaskStats
Constants ¶
const (
// DefaultMaxWorkers is the default number of concurrent observation workers.
DefaultMaxWorkers = 100
)
Variables ¶
This section is empty.
Functions ¶
func ConvertImpact ¶
func ConvertImpact(impact *ResourceImpact) *decision.ResourceImpact
ConvertImpact converts learning.ResourceImpact to decision.ResourceImpact.
Types ¶
type AllStats ¶
type AllStats struct {
Tasks map[string]*TaskStats `json:"tasks"`
TotalTasks int64 `json:"total_tasks"`
}
AllStats holds statistics for all task types.
type Engine ¶
type Engine struct {
// contains filtered or unexported fields
}
Engine coordinates learning from task executions.
func NewEngine ¶
func NewEngine(model Model, aggregator *monitor.Aggregator, observationDelay time.Duration, logger *slog.Logger) *Engine
NewEngine creates a new learning engine.
func NewEngineWithWorkers ¶
func NewEngineWithWorkers(model Model, aggregator *monitor.Aggregator, observationDelay time.Duration, logger *slog.Logger, maxWorkers int) *Engine
NewEngineWithWorkers creates a new learning engine with custom worker limit.
func (*Engine) ActiveWorkers ¶
ActiveWorkers returns the current number of active observation workers.
func (*Engine) GetTaskStats ¶
GetTaskStats returns statistics for a specific task.
func (*Engine) NotifyTaskStart ¶
NotifyTaskStart records that a task has started. It captures a baseline of system state and schedules an observation.
func (*Engine) PendingCount ¶
PendingCount returns the number of tasks awaiting observation.
func (*Engine) Predict ¶
func (e *Engine) Predict(task string, complexity int) *ResourceImpact
Predict returns predicted resource impact for a task.
func (*Engine) Stop ¶
func (e *Engine) Stop()
Stop gracefully shuts down the engine, waiting for pending observations.
func (*Engine) StopWithTimeout ¶
StopWithTimeout stops the engine with a timeout.
type Model ¶
type Model interface {
// Name returns the model name.
Name() string
// Observe records an observation of task impact.
Observe(task string, complexity int, impact *ResourceImpact)
// Predict returns predicted resource impact for a task.
Predict(task string, complexity int) *ResourceImpact
// GetStats returns statistics for all observed tasks.
GetStats() *AllStats
// GetTaskStats returns statistics for a specific task.
GetTaskStats(task string) *TaskStats
// SetObserver sets a callback that will be called when stats change.
SetObserver(observer StatsObserver)
// LoadStats loads previously saved statistics into the model.
LoadStats(stats *AllStats)
}
Model is the interface for learning models that predict resource impact.
type ModelAdapter ¶
type ModelAdapter struct {
// contains filtered or unexported fields
}
ModelAdapter wraps decision/model.PredictionModel to implement the old learning.Model interface. This allows gradual migration to the new model system.
func NewModelAdapter ¶
func NewModelAdapter(m model.PredictionModel) *ModelAdapter
NewModelAdapter creates a new adapter wrapping a PredictionModel.
func (*ModelAdapter) GetStats ¶
func (a *ModelAdapter) GetStats() *AllStats
GetStats returns statistics for all tasks.
func (*ModelAdapter) GetTaskStats ¶
func (a *ModelAdapter) GetTaskStats(task string) *TaskStats
GetTaskStats returns statistics for a specific task.
func (*ModelAdapter) LoadStats ¶
func (a *ModelAdapter) LoadStats(stats *AllStats)
LoadStats loads previously saved statistics. Note: This is a no-op for the new model system - use model.Load() instead.
func (*ModelAdapter) Observe ¶
func (a *ModelAdapter) Observe(task string, complexity int, impact *ResourceImpact)
Observe records an observation.
func (*ModelAdapter) Predict ¶
func (a *ModelAdapter) Predict(task string, complexity int) *ResourceImpact
Predict returns predicted resource impact.
func (*ModelAdapter) SetObserver ¶
func (a *ModelAdapter) SetObserver(observer StatsObserver)
SetObserver sets a callback for stats changes.
func (*ModelAdapter) Underlying ¶
func (a *ModelAdapter) Underlying() model.PredictionModel
Underlying returns the wrapped PredictionModel.
type MovingAverageModel ¶
type MovingAverageModel struct {
// contains filtered or unexported fields
}
MovingAverageModel implements Model using exponential moving average.
func NewMovingAverageModel ¶
func NewMovingAverageModel(alpha float64) *MovingAverageModel
NewMovingAverageModel creates a new MovingAverageModel. Alpha is the smoothing factor: higher values give more weight to recent observations. Typical values are 0.1-0.3.
func (*MovingAverageModel) GetStats ¶
func (m *MovingAverageModel) GetStats() *AllStats
func (*MovingAverageModel) GetTaskStats ¶
func (m *MovingAverageModel) GetTaskStats(task string) *TaskStats
func (*MovingAverageModel) LoadStats ¶
func (m *MovingAverageModel) LoadStats(stats *AllStats)
func (*MovingAverageModel) Name ¶
func (m *MovingAverageModel) Name() string
func (*MovingAverageModel) Observe ¶
func (m *MovingAverageModel) Observe(task string, complexity int, impact *ResourceImpact)
func (*MovingAverageModel) Predict ¶
func (m *MovingAverageModel) Predict(task string, complexity int) *ResourceImpact
func (*MovingAverageModel) SetObserver ¶
func (m *MovingAverageModel) SetObserver(observer StatsObserver)
type ResourceImpact ¶
type ResourceImpact struct {
CPUDelta float64 `json:"cpu_delta"`
MemoryDelta float64 `json:"memory_delta"`
GPUDelta float64 `json:"gpu_delta,omitempty"`
VRAMDelta float64 `json:"vram_delta,omitempty"`
}
ResourceImpact represents the observed impact of a task on system resources.
func ConvertImpactBack ¶
func ConvertImpactBack(impact *decision.ResourceImpact) *ResourceImpact
ConvertImpactBack converts decision.ResourceImpact to learning.ResourceImpact.
type StatsObserver ¶
StatsObserver is called when task statistics are updated.
type TaskRecord ¶
type TaskRecord struct {
Task string `json:"task"`
Complexity int `json:"complexity,omitempty"`
StartedAt time.Time `json:"started_at"`
Impact *ResourceImpact `json:"impact,omitempty"`
}
TaskRecord represents a single task execution record.
type TaskStartRequest ¶
type TaskStartRequest struct {
Task string `json:"task"`
Complexity int `json:"complexity,omitempty"`
}
TaskStartRequest represents the request body for POST /task/notify.
type TaskStartResponse ¶
TaskStartResponse represents the response for POST /task/notify.
type TaskStats ¶
type TaskStats struct {
Task string `json:"task"`
Count int64 `json:"count"`
AvgCPUDelta float64 `json:"avg_cpu_delta"`
AvgMemDelta float64 `json:"avg_mem_delta"`
AvgGPUDelta float64 `json:"avg_gpu_delta,omitempty"`
AvgVRAMDelta float64 `json:"avg_vram_delta,omitempty"`
}
TaskStats holds aggregated statistics for a specific task type.