use mod_interface::mod_interface;
mod private
{
use serde::{ Serialize, Deserialize };
#[ derive( Debug, Clone, Serialize, Deserialize ) ]
pub struct ConnectionPerformanceReport
{
pub efficiency_metrics : crate::connection_manager::ConnectionEfficiencyMetrics,
pub pool_stats : Vec< crate::connection_manager::PoolStatistics >,
pub analysis : PerformanceAnalysis,
}
#[ derive( Debug, Clone, Serialize, Deserialize ) ]
pub struct PerformanceAnalysis
{
pub grade : String,
pub kpis : Vec< String >,
pub recommendations : Vec< String >,
pub issues : Vec< String >,
}
#[ derive( Debug, Clone, Serialize, Deserialize ) ]
pub struct UnifiedPerformanceDashboard
{
pub overall_performance_score : f64,
pub connection_performance : ConnectionPerformanceReport,
#[ cfg( feature = "caching" ) ]
pub cache_performance : Option< crate::response_cache::CacheStatistics >,
#[ cfg( not( feature = "caching" ) ) ]
pub cache_performance : Option< () >,
pub metrics_summary : Option< crate::metrics_framework::MetricsSnapshot >,
pub recommendations : Vec< String >,
}
#[ must_use ]
#[ inline ]
pub fn analyze_performance(
efficiency : &crate::connection_manager::ConnectionEfficiencyMetrics,
pools : &[ crate::connection_manager::PoolStatistics ],
) -> PerformanceAnalysis
{
let mut kpis = Vec::new();
let mut recommendations = Vec::new();
let mut issues = Vec::new();
let grade = match efficiency.efficiency_score
{
s if s >= 0.9 => "A",
s if s >= 0.8 => "B",
s if s >= 0.7 => "C",
s if s >= 0.6 => "D",
_ => "F",
};
kpis.push( format!( "Efficiency Score : {:.1}%", efficiency.efficiency_score * 100.0 ) );
kpis.push( format!( "Connection Reuse Ratio : {:.1}", efficiency.connection_reuse_ratio ) );
kpis.push( format!( "Average Pool Utilization : {:.1}%", efficiency.average_pool_utilization * 100.0 ) );
if efficiency.connection_reuse_ratio < 5.0
{
issues.push( "Low connection reuse - connections are not being reused efficiently".to_string() );
recommendations.push( "Increase connection pool size or check for connection leaks".to_string() );
}
else if efficiency.connection_reuse_ratio > 100.0
{
issues.push( "Extremely high connection reuse - may indicate connection starvation".to_string() );
recommendations.push( "Increase maximum connections per host".to_string() );
}
if efficiency.average_pool_utilization < 0.3
{
recommendations.push( "Pool utilization is low - consider reducing minimum connections".to_string() );
}
else if efficiency.average_pool_utilization > 0.9
{
issues.push( "High pool utilization - may cause connection wait times".to_string() );
recommendations.push( "Increase maximum connections per host".to_string() );
}
for pool in pools
{
if pool.current_utilization > 0.95
{
issues.push( format!( "Pool for {} is overutilized ({:.1}%)", pool.host, pool.current_utilization * 100.0 ) );
}
if pool.total_connections_created > pool.total_requests_served
{
issues.push( format!( "Pool for {} has poor connection reuse", pool.host ) );
}
}
if efficiency.efficiency_score < 0.8
{
recommendations.push( "Consider tuning connection pool parameters".to_string() );
recommendations.push( "Monitor connection health and cleanup intervals".to_string() );
}
PerformanceAnalysis
{
grade : grade.to_string(),
kpis,
recommendations,
issues,
}
}
}
mod_interface!
{
exposed use
{
ConnectionPerformanceReport,
PerformanceAnalysis,
UnifiedPerformanceDashboard,
analyze_performance,
};
}