fetch_ml/internal/config/resources.go
Jeremie Fraeys 420de879ff
feat(api): integrate scheduler protocol and WebSocket enhancements
Update API layer for scheduler integration:
- WebSocket handlers with scheduler protocol support
- Jobs WebSocket endpoint with priority queue integration
- Validation middleware for scheduler messages
- Server configuration with security hardening
- Protocol definitions for worker-scheduler communication
- Dataset handlers with tenant isolation checks
- Response helpers with audit context
- OpenAPI spec updates for new endpoints
2026-02-26 12:05:57 -05:00

40 lines
1.2 KiB
Go

package config
// ResourceConfig centralizes pacing and resource optimization knobs.
type ResourceConfig struct {
PodmanCPUs string `yaml:"podman_cpus" toml:"podman_cpus"`
PodmanMemory string `yaml:"podman_memory" toml:"podman_memory"`
MaxWorkers int `yaml:"max_workers" toml:"max_workers"`
DesiredRPSPerWorker int `yaml:"desired_rps_per_worker" toml:"desired_rps_per_worker"`
RequestsPerSec int `yaml:"requests_per_sec" toml:"requests_per_sec"`
RequestBurstOverride int `yaml:"request_burst" toml:"request_burst"`
}
// ApplyDefaults ensures sane values without requiring every field to be set.
func (r *ResourceConfig) ApplyDefaults() {
if r.MaxWorkers < 1 {
r.MaxWorkers = 1
}
if r.DesiredRPSPerWorker < 1 {
r.DesiredRPSPerWorker = DefaultDesiredRPSPerWorker
}
if r.PodmanCPUs == "" {
r.PodmanCPUs = DefaultPodmanCPUs
}
if r.PodmanMemory == "" {
r.PodmanMemory = DefaultPodmanMemory
}
}
// EffectiveRequestsPerSec returns an auto-derived value when not explicitly set.
func (r ResourceConfig) EffectiveRequestsPerSec() int {
if r.RequestsPerSec > 0 {
return r.RequestsPerSec
}
rps := r.MaxWorkers * r.DesiredRPSPerWorker
if rps < 1 {
return 1
}
return rps
}