Class: ActivePostgres::PerformanceTuner
- Inherits:
-
Object
- Object
- ActivePostgres::PerformanceTuner
- Defined in:
- lib/active_postgres/performance_tuner.rb
Overview
Automatic PostgreSQL performance tuning based on hardware specs Following best practices from PGTune and PostgreSQL documentation
Instance Attribute Summary collapse
-
#config ⇒ Object
readonly
Returns the value of attribute config.
-
#logger ⇒ Object
readonly
Returns the value of attribute logger.
-
#ssh_executor ⇒ Object
readonly
Returns the value of attribute ssh_executor.
Instance Method Summary collapse
-
#initialize(config, ssh_executor, logger = Logger.new) ⇒ PerformanceTuner
constructor
A new instance of PerformanceTuner.
- #tune_for_host(host, db_type: 'web') ⇒ Object
Constructor Details
#initialize(config, ssh_executor, logger = Logger.new) ⇒ PerformanceTuner
Returns a new instance of PerformanceTuner.
7 8 9 10 11 |
# File 'lib/active_postgres/performance_tuner.rb', line 7 def initialize(config, ssh_executor, logger = Logger.new) @config = config @ssh_executor = ssh_executor @logger = logger end |
Instance Attribute Details
#config ⇒ Object (readonly)
Returns the value of attribute config.
5 6 7 |
# File 'lib/active_postgres/performance_tuner.rb', line 5 def config @config end |
#logger ⇒ Object (readonly)
Returns the value of attribute logger.
5 6 7 |
# File 'lib/active_postgres/performance_tuner.rb', line 5 def logger @logger end |
#ssh_executor ⇒ Object (readonly)
Returns the value of attribute ssh_executor.
5 6 7 |
# File 'lib/active_postgres/performance_tuner.rb', line 5 def ssh_executor @ssh_executor end |
Instance Method Details
#tune_for_host(host, db_type: 'web') ⇒ Object
13 14 15 16 17 18 19 20 21 22 23 24 25 |
# File 'lib/active_postgres/performance_tuner.rb', line 13 def tune_for_host(host, db_type: 'web') @logger.info 'Analyzing hardware for optimal PostgreSQL configuration...' hardware = analyze_hardware(host) settings = calculate_optimal_settings(hardware, db_type) @logger.info 'Hardware detected:' @logger.info " CPU Cores: #{hardware[:cpu_cores]}" @logger.info " RAM: #{format_bytes(hardware[:total_memory])}" @logger.info " Storage: #{hardware[:storage_type]}" settings end |