Deployment-Agent
Table of Contents
- Features
- System Architecture
- Key Concepts
- Monitoring and Scaling
- WebSocket Communication
- Database Integration
- Dynamic container management with Docker
- Real-time performance monitoring of containers
- Automatic scaling based on load and performance metrics
- WebSocket server for real-time updates
- Redis integration for persistent storage
- Sophisticated load balancing algorithm
- HTTP server for stats and management endpoints
The system consists of several interconnected modules:
- Main Application (
main.rs
) - Container Management (
container.rs
) - Queue Management (
queue.rs
) - Performance Monitoring (
stats.rs
) - WebSocket Server (
socket.rs
) - HTTP Server (
http.rs
) - Database Integration (
db.rs
)
Modules
Main (main.rs
)
- Initializes the system, starts the HTTP server and WebSocket server
- Coordinates all components
Container Management (container.rs
)
Handles Docker container operations.
- Creates, stops, and removes Docker containers
- Manages container lifecycle
- Interacts with Docker API
Queue Management (queue.rs
)
- Manages the queue of active containers and scaling decisions
- Periodically rebuilds the queue based on current system state
Performance Monitoring (stats.rs
)
- Collects CPU, memory, network, and availability metrics
- Calculates performance scores for containers
- Implements sophisticated algorithms for trend analysis and dynamic thresholds
WebSocket Server (socket.rs
)
- Provides real-time updates of the container queue to clients
- Implements WebSocket protocol for bi-directional communication
HTTP Server (http.rs
)
- Exposes endpoints for retrieving container stats
- Implements CORS for cross-origin requests
Database Integration (db.rs
)
- Manages Redis connection
- Provides methods for storing and retrieving configuration values
Container Lifecycle Containers go through several states:
- INIT: Initial state when a container is created
- LU (Low Utilization): Container is underutilized
- MU (Medium Utilization): Container has moderate utilization
- HU (High Utilization): Container is highly utilized
- SUNDOWN: Container is marked for removal
Performance Scoring Each container receives scores based on:
- CPU usage
- Memory usage
- Network usage
- Availability (response time)
These scores are combined into an overall score that determines the container's utilization category.
The system continuously monitors container performance and makes scaling decisions based on:
- Average load across all containers
- Presence of critically loaded containers
- Current number of active containers vs. desired number
- Cooldown periods to prevent rapid scaling events
Scaling operations include:
- Creating new containers when load is high
- Marking containers for removal (SUNDOWN) when load is low
The WebSocket server provides real-time updates of the container queue to clients. This allows for immediate reflection of system changes in client applications.
Redis is used for persistent storage of:
- Container information
- Configuration values
- Performance metrics
This allows for system state recovery in case of restarts.