Class: Tasker::Orchestration::ConnectionPoolIntelligence
- Inherits:
-
Object
- Object
- Tasker::Orchestration::ConnectionPoolIntelligence
- Defined in:
- lib/tasker/orchestration/connection_pool_intelligence.rb
Overview
Rails-Framework-Aligned Connection Management
Provides intelligent assessment of database connection pool health and recommends safe concurrency levels that work WITH Rails connection pool rather than around it.
Key Design Principles:
- CONSTANTS: Ruby/Rails optimization characteristics (safety thresholds, precision)
- CONFIGURABLE: Environment-dependent pressure response factors
- Conservative safety margins to prevent connection exhaustion
- Comprehensive structured logging for observability
Constant Summary collapse
- CONNECTION_UTILIZATION_PRECISION =
Decimal places for utilization calculation (based on Rails pool stat precision)
3
- PRESSURE_ASSESSMENT_THRESHOLDS =
Pressure assessment thresholds (based on Rails connection pool characteristics)
{ low: 0.0..0.5, moderate: 0.5..0.7, high: 0.7..0.85, critical: 0.85..Float::INFINITY }.freeze
- MAX_SAFE_CONNECTION_PERCENTAGE =
Conservative safety patterns (based on Rails connection pool behavior) Never use more than 60% of pool to prevent connection exhaustion
0.6
- EMERGENCY_FALLBACK_CONCURRENCY =
Absolute minimum for system stability (based on Tasker orchestration needs)
3
Class Method Summary collapse
-
.assess_connection_health ⇒ Hash
Assess current database connection pool health.
-
.intelligent_concurrency_for_step_executor ⇒ Integer
Calculate intelligent concurrency for StepExecutor integration.
Class Method Details
.assess_connection_health ⇒ Hash
Assess current database connection pool health
Provides comprehensive analysis of Rails connection pool state including utilization metrics, pressure assessment, and concurrency recommendations.
59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 |
# File 'lib/tasker/orchestration/connection_pool_intelligence.rb', line 59 def self.assess_connection_health pool = ActiveRecord::Base.connection_pool pool_stat = pool.stat { pool_utilization: calculate_utilization(pool_stat), connection_pressure: assess_pressure(pool_stat), recommended_concurrency: recommend_concurrency(pool_stat), rails_pool_stats: pool_stat, health_status: determine_health_status(pool_stat), assessment_timestamp: Time.current } rescue StandardError => e Rails.logger.error("ConnectionPoolIntelligence: Health assessment failed - #{e.class.name}: #{e.}") # Return safe fallback assessment { pool_utilization: 0.0, connection_pressure: :unknown, recommended_concurrency: EMERGENCY_FALLBACK_CONCURRENCY, rails_pool_stats: {}, health_status: :unknown, assessment_timestamp: Time.current, assessment_error: e. } end |
.intelligent_concurrency_for_step_executor ⇒ Integer
Calculate intelligent concurrency for StepExecutor integration
Provides Rails-aware concurrency calculation that respects connection pool limits while applying configurable safety margins and pressure factors.
92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 |
# File 'lib/tasker/orchestration/connection_pool_intelligence.rb', line 92 def self.intelligent_concurrency_for_step_executor health_data = assess_connection_health config = Tasker::Configuration.configuration.execution # Get base recommendation from Rails pool analysis base_recommendation = health_data[:recommended_concurrency] safe_concurrency = apply_tasker_safety_margins(base_recommendation, health_data, config) Rails.logger.debug do "ConnectionPoolIntelligence: Dynamic concurrency=#{safe_concurrency}, " \ "pressure=#{health_data[:connection_pressure]}, " \ "pool_size=#{ActiveRecord::Base.connection_pool.size}, " \ "available=#{health_data[:rails_pool_stats][:available]}" end safe_concurrency rescue StandardError => e Rails.logger.error( "ConnectionPoolIntelligence: Concurrency calculation failed - #{e.class.name}: #{e.}, " \ "using fallback=#{EMERGENCY_FALLBACK_CONCURRENCY}" ) EMERGENCY_FALLBACK_CONCURRENCY end |