【发布时间】:2014-10-02 04:18:35
【问题描述】:
sidekiq docs say you should increase your AR pool size 到大约 25 个连接。
production:
adapter: mysql2
database: foo_production
pool: 25
如果你使用 Heroku,you can't use application.yml。相反,您需要使用unicorn.rb 配置文件(如果您使用的是独角兽):
after_fork do |server, worker|
if defined?(ActiveRecord::Base)
config = ActiveRecord::Base.configurations[Rails.env] ||
Rails.application.config.database_configuration[Rails.env]
config['reaping_frequency'] = ENV['DB_REAP_FREQ'] || 10 # seconds
config['pool'] = ENV['DB_POOL'] || 25
ActiveRecord::Base.establish_connection(config)
end
end
但是每个 Dyno 运行 3 个进程。我有一个网络 Dyno 和一个工人 Dyno。这是否意味着最大池大小为 150? 2 * 3 * 25?
后来,导游说we should include an initializer file。但它几乎与unicorn.rb 文件中的代码相同。除了独角兽文件,我们还需要这个吗?
config = ActiveRecord::Base.configurations[Rails.env] ||
Rails.application.config.database_configuration[Rails.env]
config['reaping_frequency'] = ENV['DB_REAP_FREQ'] || 10 # seconds
config['pool'] = ENV['DB_POOL'] || 5
ActiveRecord::Base.establish_connection(config)
【问题讨论】:
标签: ruby-on-rails ruby activerecord heroku unicorn