Expand description
Copyright © 2025-2026 Wenze Wei. All Rights Reserved.
This file is part of Ri. The Ri project belongs to the Dunimd Team.
Licensed under the Apache License, Version 2.0 (the “License”); You may not use this file except in compliance with the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an “AS IS” BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
§Resource Pool Management
This file implements resource pool management for the Ri framework, providing a way to group similar devices together for efficient resource allocation and management. It includes both single resource pools and a resource pool manager for handling multiple pools.
§Key Components
- RiResourcePool: Manages a pool of similar devices
- RiResourcePoolConfig: Configuration for resource pools
- RiResourcePoolStatistics: Statistics for monitoring resource pools
- RiResourcePoolManager: Manages multiple resource pools
§Design Principles
- Resource Grouping: Groups similar devices together for efficient management
- Capacity Tracking: Tracks total, available, and allocated capacity
- Statistics Collection: Collects comprehensive statistics for monitoring
- Device Filtering: Filters devices by availability and allocation status
- Health Monitoring: Monitors pool health based on available devices
- Utilization Tracking: Tracks resource utilization rates
- Multi-Pool Management: Supports managing multiple pools through a central manager
- Device Type Segregation: Each pool contains devices of a single type
- Arc-Based Sharing: Uses Arc for safe concurrent access to devices
- Serialization Support: All structures support serialization/deserialization
- Builder Pattern: Configurable through RiResourcePoolConfig
- Resource Optimization: Calculates total compute, memory, storage, and bandwidth
§Usage
use ri::device::{RiResourcePoolManager, RiResourcePoolConfig, RiDeviceType};
use ri::core::RiResult;
fn example() -> RiResult<()> {
// Create a resource pool manager
let mut manager = RiResourcePoolManager::new();
// Create a resource pool configuration
let config = RiResourcePoolConfig {
name: "cpu-pool-1".to_string(),
device_type: RiDeviceType::CPU,
max_concurrent_allocations: 10,
allocation_timeout_secs: 60,
health_check_interval_secs: 30,
};
// Create a resource pool
let pool = manager.create_pool(config);
// Get pool statistics
let stats = pool.get_statistics();
println!("Pool has {} devices, utilization: {:.2}%",
stats.total_devices, stats.utilization_rate * 100.0);
// Get all pools by device type
let cpu_pools = manager.get_pools_by_type(RiDeviceType::CPU);
println!("Found {} CPU pools", cpu_pools.len());
// Get overall statistics
let overall_stats = manager.get_overall_statistics();
println!("Total devices across all pools: {}", overall_stats.total_devices);
Ok(())
}Structs§
- RiConnection
Health Metrics - Connection health metrics
- RiConnection
Info - Connection information for tracking individual connections
- RiConnection
Pool - Connection pool for managing device connections with lifecycle and health monitoring
- RiConnection
Pool Statistics - Connection pool statistics
- RiResource
Pool - Resource pool for managing multiple similar devices
- RiResource
Pool Config - Configuration for a resource pool
- RiResource
Pool Manager - Resource pool manager for managing multiple resource pools
- RiResource
Pool Statistics - Resource pool statistics structure
Enums§
- RiConnection
State - Connection state enumeration