我刚接触Puma,之前曾在Unicorn工作过。
Unicorn配置有一个before_fork
和after_fork
方法断开连接,然后在fork之后重新建立它。
然而,彪马没有那个。它只有on_worker_boot
,在概念上类似于after_fork
方法。
Puma是否也利用工人流程的分支?在像Unicorn这样的分叉之前是否需要断开连接?
谢谢!
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
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