scaling

package
v0.9.0 Latest Latest
Warning

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

Go to latest
Published: May 2, 2026 License: MIT Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type ActionType

type ActionType string

ActionType categorizes scaling actions

const (
	ActionScaleUp   ActionType = "scale_up"
	ActionScaleDown ActionType = "scale_down"
	ActionScaleOut  ActionType = "scale_out"
	ActionScaleIn   ActionType = "scale_in"
	ActionOptimize  ActionType = "optimize"
	ActionThrottle  ActionType = "throttle"
)

type AllocationStatus

type AllocationStatus string

AllocationStatus tracks allocation state

const (
	AllocationActive    AllocationStatus = "active"
	AllocationReleased  AllocationStatus = "released"
	AllocationExpired   AllocationStatus = "expired"
	AllocationReclaimed AllocationStatus = "reclaimed"
)

type AutoScaler

type AutoScaler struct {
	// contains filtered or unexported fields
}

AutoScaler handles automatic scaling operations

func NewAutoScaler

func NewAutoScaler() *AutoScaler

NewAutoScaler creates an auto scaler

func (*AutoScaler) ScaleDown

func (as *AutoScaler) ScaleDown(target string, value interface{}) error

ScaleDown decreases resource capacity

func (*AutoScaler) ScaleIn

func (as *AutoScaler) ScaleIn(target string, value interface{}) error

ScaleIn removes instances

func (*AutoScaler) ScaleOut

func (as *AutoScaler) ScaleOut(target string, value interface{}) error

ScaleOut adds more instances

func (*AutoScaler) ScaleUp

func (as *AutoScaler) ScaleUp(target string, value interface{}) error

ScaleUp increases resource capacity

type CPUCollector

type CPUCollector struct{}

Metric collector implementations

func (*CPUCollector) Collect

func (c *CPUCollector) Collect() (string, float64)

type CPUOptimizationStrategy

type CPUOptimizationStrategy struct{}

func (*CPUOptimizationStrategy) Optimize

func (c *CPUOptimizationStrategy) Optimize(target string, metrics map[string]float64) error

type ComparisonOperator

type ComparisonOperator string

ComparisonOperator for threshold comparison

const (
	OpGreaterThan    ComparisonOperator = ">"
	OpLessThan       ComparisonOperator = "<"
	OpGreaterOrEqual ComparisonOperator = ">="
	OpLessOrEqual    ComparisonOperator = "<="
	OpEqual          ComparisonOperator = "=="
)

type ConstraintType

type ConstraintType string

ConstraintType categorizes constraints

const (
	ConstraintMinInstances ConstraintType = "min_instances"
	ConstraintMaxInstances ConstraintType = "max_instances"
	ConstraintMaxScaleRate ConstraintType = "max_scale_rate"
	ConstraintBudget       ConstraintType = "budget"
	ConstraintTimeWindow   ConstraintType = "time_window"
)

type ExponentialPredictor

type ExponentialPredictor struct{}

func (*ExponentialPredictor) Predict

func (ep *ExponentialPredictor) Predict(history []MetricPoint, horizon time.Duration) float64

type GoroutineCollector

type GoroutineCollector struct{}

func (*GoroutineCollector) Collect

func (g *GoroutineCollector) Collect() (string, float64)

type InstanceStatus

type InstanceStatus string

InstanceStatus represents instance state

const (
	InstanceActive   InstanceStatus = "active"
	InstanceScaling  InstanceStatus = "scaling"
	InstanceDraining InstanceStatus = "draining"
	InstanceStopped  InstanceStatus = "stopped"
)

type LinearPredictor

type LinearPredictor struct{}

Prediction model implementations

func (*LinearPredictor) Predict

func (lp *LinearPredictor) Predict(history []MetricPoint, horizon time.Duration) float64

type MemoryCollector

type MemoryCollector struct{}

func (*MemoryCollector) Collect

func (m *MemoryCollector) Collect() (string, float64)

type MemoryOptimizationStrategy

type MemoryOptimizationStrategy struct{}

Optimization strategy implementations

func (*MemoryOptimizationStrategy) Optimize

func (m *MemoryOptimizationStrategy) Optimize(target string, metrics map[string]float64) error

type MetricCollector

type MetricCollector interface {
	Collect() (string, float64)
}

MetricCollector collects specific metrics

type MetricHistory

type MetricHistory struct {
	// contains filtered or unexported fields
}

MetricHistory stores historical metrics

func NewMetricHistory

func NewMetricHistory(maxPoints int) *MetricHistory

Metric history implementation

func (*MetricHistory) Record

func (mh *MetricHistory) Record(metric string, value float64)

type MetricPoint

type MetricPoint struct {
	Value     float64
	Timestamp time.Time
}

MetricPoint represents a metric at a point in time

type OptimizationStrategy

type OptimizationStrategy interface {
	Optimize(target string, metrics map[string]float64) error
}

OptimizationStrategy defines optimization approach

type PolicyType

type PolicyType string

PolicyType categorizes scaling policies

const (
	PolicyReactive   PolicyType = "reactive"
	PolicyPredictive PolicyType = "predictive"
	PolicyScheduled  PolicyType = "scheduled"
	PolicyEmergency  PolicyType = "emergency"
)

type PredictionModel

type PredictionModel interface {
	Predict(history []MetricPoint, horizon time.Duration) float64
}

PredictionModel predicts resource usage

type RateLimiter

type RateLimiter struct {
	// contains filtered or unexported fields
}

RateLimiter implements rate limiting

type RequestType

type RequestType string

RequestType categorizes resource requests

const (
	RequestAttack   RequestType = "attack"
	RequestScan     RequestType = "scan"
	RequestAnalysis RequestType = "analysis"
	RequestTraining RequestType = "training"
)

type ResourceAllocation

type ResourceAllocation struct {
	ID              string
	RequestID       string
	AllocatedCPU    float64
	AllocatedMemory int64
	Goroutines      []int
	Connections     []string
	StartTime       time.Time
	ExpiryTime      time.Time
	Status          AllocationStatus
}

ResourceAllocation represents allocated resources

type ResourceAllocator

type ResourceAllocator struct {
	// contains filtered or unexported fields
}

ResourceAllocator manages resource allocation

func NewResourceAllocator

func NewResourceAllocator() *ResourceAllocator

NewResourceAllocator creates an allocator

func (*ResourceAllocator) Allocate

Allocate reserves resources

func (*ResourceAllocator) Release

func (ra *ResourceAllocator) Release(allocationID string) error

Release frees allocated resources

type ResourceConfig

type ResourceConfig struct {
	MaxCPU            float64
	MaxMemory         int64
	MaxGoroutines     int
	MaxConnections    int
	ScalingEnabled    bool
	PredictiveScaling bool
	ResourceLimits    ResourceLimits
	ScalingThresholds ScalingThresholds
}

ResourceConfig configures resource management

type ResourceLimiter

type ResourceLimiter struct {
	// contains filtered or unexported fields
}

ResourceLimiter enforces resource limits

func NewResourceLimiter

func NewResourceLimiter(limits ResourceLimits) *ResourceLimiter

NewResourceLimiter creates a resource limiter

func (*ResourceLimiter) CheckLimits

func (rl *ResourceLimiter) CheckLimits(request ResourceRequest) error

CheckLimits verifies resource availability

func (*ResourceLimiter) Throttle

func (rl *ResourceLimiter) Throttle(target string, value interface{}) error

Throttle reduces resource usage

type ResourceLimits

type ResourceLimits struct {
	CPULimit         float64
	MemoryLimit      int64
	GoroutineLimit   int
	ConnectionLimit  int
	RequestRateLimit float64
	BandwidthLimit   int64
}

ResourceLimits defines resource boundaries

type ResourceManager

type ResourceManager struct {
	// contains filtered or unexported fields
}

ResourceManager manages system resources and scaling

func NewResourceManager

func NewResourceManager(config ResourceConfig) *ResourceManager

NewResourceManager creates a resource manager

func (*ResourceManager) AllocateResources

func (rm *ResourceManager) AllocateResources(ctx context.Context, request ResourceRequest) (*ResourceAllocation, error)

AllocateResources allocates resources for a task

func (*ResourceManager) RegisterPolicy

func (rm *ResourceManager) RegisterPolicy(policy *ScalingPolicy)

RegisterPolicy adds a scaling policy

type ResourceMonitor

type ResourceMonitor struct {
	// contains filtered or unexported fields
}

ResourceMonitor monitors resource usage

func NewResourceMonitor

func NewResourceMonitor() *ResourceMonitor

NewResourceMonitor creates a monitor

func (*ResourceMonitor) CollectMetrics

func (rm *ResourceMonitor) CollectMetrics() map[string]float64

CollectMetrics gathers current metrics

func (*ResourceMonitor) RegisterCollector

func (rm *ResourceMonitor) RegisterCollector(name string, collector MetricCollector)

RegisterCollector adds a metric collector

type ResourcePool

type ResourcePool struct {
	Type        string
	TotalSize   int64
	Available   int64
	Allocations map[string]int64
}

ResourcePool manages pooled resources

type ResourcePredictor

type ResourcePredictor struct {
	// contains filtered or unexported fields
}

ResourcePredictor predicts future resource usage

func NewResourcePredictor

func NewResourcePredictor() *ResourcePredictor

NewResourcePredictor creates a predictor

func (*ResourcePredictor) PredictUsage

func (rp *ResourcePredictor) PredictUsage(current map[string]float64, horizon time.Duration) map[string]float64

PredictUsage predicts future usage

type ResourceRequest

type ResourceRequest struct {
	ID          string
	Type        RequestType
	CPU         float64
	Memory      int64
	Goroutines  int
	Connections int
	Duration    time.Duration
	Priority    int
}

ResourceRequest defines resource requirements

type ResourceState

type ResourceState struct {
	CPUUsage          float64
	MemoryUsage       int64
	GoroutineCount    int
	ConnectionCount   int
	RequestRate       float64
	Bandwidth         int64
	LastScaleAction   time.Time
	ScalingInProgress bool
	// contains filtered or unexported fields
}

ResourceState tracks current resource usage

type ResourceUsage

type ResourceUsage struct {
	CPU         float64
	Memory      int64
	Goroutines  int32
	Connections int32
	RequestRate float64
	Bandwidth   int64
}

ResourceUsage tracks current usage

type ScalableInstance

type ScalableInstance struct {
	ID          string
	Type        string
	Capacity    float64
	CurrentLoad float64
	Status      InstanceStatus
	LastScaled  time.Time
}

ScalableInstance represents a scalable resource

type ScalingAction

type ScalingAction struct {
	Type       ActionType
	Target     string
	Value      interface{}
	Parameters map[string]interface{}
}

ScalingAction defines scaling operation

type ScalingConstraint

type ScalingConstraint struct {
	Type  ConstraintType
	Value interface{}
}

ScalingConstraint limits scaling behavior

type ScalingGroup

type ScalingGroup struct {
	ID           string
	Name         string
	Instances    []string
	MinInstances int
	MaxInstances int
	TargetMetric string
	TargetValue  float64
}

ScalingGroup manages a group of instances

type ScalingOptimizer

type ScalingOptimizer struct {
	// contains filtered or unexported fields
}

ScalingOptimizer optimizes scaling decisions

func NewScalingOptimizer

func NewScalingOptimizer() *ScalingOptimizer

NewScalingOptimizer creates an optimizer

func (*ScalingOptimizer) Optimize

func (so *ScalingOptimizer) Optimize(target string) error

Optimize applies optimization

type ScalingPolicy

type ScalingPolicy struct {
	ID          string
	Name        string
	Type        PolicyType
	Triggers    []ScalingTrigger
	Actions     []ScalingAction
	Constraints []ScalingConstraint
	Priority    int
	Enabled     bool
}

ScalingPolicy defines scaling behavior

type ScalingThresholds

type ScalingThresholds struct {
	ScaleUpCPU       float64
	ScaleUpMemory    float64
	ScaleUpLatency   time.Duration
	ScaleDownCPU     float64
	ScaleDownMemory  float64
	ScaleDownLatency time.Duration
	CooldownPeriod   time.Duration
}

ScalingThresholds triggers scaling actions

type ScalingTrigger

type ScalingTrigger struct {
	Type      TriggerType
	Metric    string
	Threshold float64
	Duration  time.Duration
	Operator  ComparisonOperator
}

ScalingTrigger defines when to scale

type TriggerType

type TriggerType string

TriggerType categorizes triggers

const (
	TriggerMetric    TriggerType = "metric"
	TriggerSchedule  TriggerType = "schedule"
	TriggerEvent     TriggerType = "event"
	TriggerPredicted TriggerType = "predicted"
)

Jump to

Keyboard shortcuts

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