【发布时间】:2015-09-12 00:20:11
【问题描述】:
我刚开始与 Puma 合作,之前曾与 Unicorn 合作过。
Unicorn 配置有一个 before_fork 和 after_fork 方法断开连接,然后在分叉后重新建立。
但是,彪马没有。它只有on_worker_boot,在概念上类似于after_fork 方法。
Puma 不也利用工作进程的分叉吗?像 Unicorn 一样分叉前不需要断开连接吗?
谢谢!
示例文件
config/unicorn.rb
before_fork do |server, worker|
# other settings
if defined?(ActiveRecord::Base)
ActiveRecord::Base.connection.disconnect!
end
end
after_fork do |server, worker|
# other settings
if defined?(ActiveRecord::Base)
ActiveRecord::Base.establish_connection
end
end
config/puma.rb
on_worker_boot do
# Worker specific setup for Rails 4.1+
# See: https://devcenter.heroku.com/articles/deploying-rails-applications-with-the-puma-web-server#on-worker-boot
ActiveRecord::Base.establish_connection
end
【问题讨论】:
标签: ruby-on-rails fork unicorn puma