Skip to main content

Module pool

Module pool 

Source
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.0

Unless 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

  1. Resource Grouping: Groups similar devices together for efficient management
  2. Capacity Tracking: Tracks total, available, and allocated capacity
  3. Statistics Collection: Collects comprehensive statistics for monitoring
  4. Device Filtering: Filters devices by availability and allocation status
  5. Health Monitoring: Monitors pool health based on available devices
  6. Utilization Tracking: Tracks resource utilization rates
  7. Multi-Pool Management: Supports managing multiple pools through a central manager
  8. Device Type Segregation: Each pool contains devices of a single type
  9. Arc-Based Sharing: Uses Arc for safe concurrent access to devices
  10. Serialization Support: All structures support serialization/deserialization
  11. Builder Pattern: Configurable through RiResourcePoolConfig
  12. 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§

RiConnectionHealthMetrics
Connection health metrics
RiConnectionInfo
Connection information for tracking individual connections
RiConnectionPool
Connection pool for managing device connections with lifecycle and health monitoring
RiConnectionPoolStatistics
Connection pool statistics
RiResourcePool
Resource pool for managing multiple similar devices
RiResourcePoolConfig
Configuration for a resource pool
RiResourcePoolManager
Resource pool manager for managing multiple resource pools
RiResourcePoolStatistics
Resource pool statistics structure

Enums§

RiConnectionState
Connection state enumeration