Expand description
AutoscaleController - Connects autoscaling decisions to container scaling
This module provides an AutoscaleController that bridges the scheduler’s
autoscaling logic with the agent’s ServiceManager to automatically scale
services based on resource utilization.
§Architecture
┌────────────────────────────────────────────────────────────────────┐
│ AutoscaleController │
│ ┌─────────────────┐ ┌────────────┐ ┌──────────────────┐ │
│ │ CgroupsMetrics │ │ Autoscaler │ │ ServiceManager │ │
│ │ Source │──│ │──│ (scaling) │ │
│ └─────────────────┘ └────────────┘ └──────────────────┘ │
└────────────────────────────────────────────────────────────────────┘§Example
ⓘ
use zlayer_agent::autoscale_controller::AutoscaleController;
use zlayer_agent::{ServiceManager, RuntimeConfig, create_runtime};
use std::sync::Arc;
use std::time::Duration;
// Create runtime and service manager
let runtime = create_runtime(RuntimeConfig::Mock).await?;
let manager = Arc::new(ServiceManager::new(runtime.clone()));
// Create autoscale controller
let controller = AutoscaleController::new(
manager.clone(),
runtime.clone(),
Duration::from_secs(10),
);
// Register services with adaptive scaling
controller.register_service("api", &scale_spec, 2).await;
// Run the autoscaling loop (in background)
let handle = tokio::spawn(async move {
controller.run_loop().await
});
// Later, shutdown
controller.shutdown();Structs§
- Autoscale
Controller - Controller that connects autoscaling decisions to actual container scaling
Constants§
- DEFAULT_
AUTOSCALE_ INTERVAL - Default autoscaling evaluation interval
Functions§
- has_
adaptive_ scaling - Check if any service in a deployment has adaptive scaling