Class: ActivePostgres::PerformanceTuner

Inherits:
Object
  • Object
show all
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

Instance Method Summary collapse

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

#configObject (readonly)

Returns the value of attribute config.



5
6
7
# File 'lib/active_postgres/performance_tuner.rb', line 5

def config
  @config
end

#loggerObject (readonly)

Returns the value of attribute logger.



5
6
7
# File 'lib/active_postgres/performance_tuner.rb', line 5

def logger
  @logger
end

#ssh_executorObject (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