Documentation
¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
var (
ErrInvalidConfig = errors.New("invalid configuration")
)
Functions ¶
func NewQuotaController ¶
func NewQuotaController(deviceController framework.DeviceController) framework.QuotaController
Types ¶
type Controller ¶
type Controller struct {
// contains filtered or unexported fields
}
func (*Controller) GetWorkerQuotaStatus ¶
func (c *Controller) GetWorkerQuotaStatus(workerUID string) error
func (*Controller) SetQuota ¶
func (c *Controller) SetQuota(workerUID string) error
func (*Controller) StartSoftQuotaLimiter ¶
func (c *Controller) StartSoftQuotaLimiter() error
func (*Controller) StopSoftQuotaLimiter ¶
func (c *Controller) StopSoftQuotaLimiter() error
type DeviceBackend ¶
type DeviceBackend interface {
ReadTokenState(device int) (*TokenState, error)
WriteTokenState(device int, state *TokenState) error
ReadQuota(device int) (*DeviceQuota, error)
WriteRefillRate(device int, refillRate float64) error
WriteCapacity(device int, capacity float64) error
FetchSubTokens(device int, cost float64) (float64, error)
FetchAddTokens(device int, amount float64) (float64, error)
}
DeviceBackend defines the interface for device token/quota operations
type DeviceController ¶
type DeviceController struct {
// contains filtered or unexported fields
}
DeviceController is a PID-based controller that dynamically adjusts token refill rates
func NewDeviceController ¶
func NewDeviceController(backend DeviceBackend, device int, cfg DeviceControllerConfig) (*DeviceController, error)
NewDeviceController creates a new device controller
func (*DeviceController) State ¶
func (dc *DeviceController) State() DeviceControllerState
State returns the current controller state
func (*DeviceController) Update ¶
func (dc *DeviceController) Update(utilization float64, deltaTime float64) (*DeviceControllerState, error)
Update updates controller with new utilization measurement and explicit delta time
func (*DeviceController) UpdateWithTimestamp ¶
func (dc *DeviceController) UpdateWithTimestamp(utilization float64, timestampMicros uint64) (*DeviceControllerState, error)
UpdateWithTimestamp updates controller with timestamp (calculates delta automatically)
type DeviceControllerConfig ¶
type DeviceControllerConfig struct {
// Target GPU utilization (0.0 to 1.0, e.g., 0.5 = 50%)
TargetUtilization float64
// Minimum refill rate (tokens/second) - prevents rate from dropping to zero
RateMin float64
// Maximum refill rate (tokens/second)
RateMax float64
// PID proportional gain - how aggressively to respond to error
Kp float64
// PID integral gain - how quickly to eliminate steady-state error
Ki float64
// PID derivative gain - how much to dampen oscillations
Kd float64
// Low-pass filter coefficient for smoothing utilization (0.0 to 1.0)
// Higher values = less filtering (more responsive, more noise)
FilterAlpha float64
// Burst window in seconds - capacity = refill_rate × burst_window
BurstWindow float64
// Minimum capacity (tokens)
CapacityMin float64
// Maximum capacity (tokens) - prevents unbounded growth
CapacityMax float64
// Minimum time between updates (seconds)
MinDeltaTime float64
// Integral decay factor (0.0 to 1.0) for exponential decay of integral term
// Higher values (closer to 1.0) = slower decay, retains more history
// Lower values = faster decay, responds more quickly to changes
// Default 0.95 means ~20 update cycles for integral to decay to ~35.8% of original value
IntegralDecayFactor float64
}
DeviceControllerConfig holds configuration for the PID-based device controller
func DefaultDeviceControllerConfig ¶
func DefaultDeviceControllerConfig() DeviceControllerConfig
DefaultDeviceControllerConfig returns a default configuration
type DeviceControllerState ¶
type DeviceControllerState struct {
TargetUtilization float64
SmoothedUtilization float64
CurrentRate float64
CurrentCapacity float64
TokenDrainRate float64
}
DeviceControllerState is a snapshot of controller state after an update
type DeviceQuota ¶
DeviceQuota represents device quota configuration
type TokenState ¶
TokenState represents the current token bucket state