为什么puma没有像Unicorn这样的`before_fork`方法?

时间:2015-09-12 00:20:12

标签: ruby-on-rails fork unicorn puma

我刚接触Puma,之前曾在Unicorn工作过。

Unicorn配置有一个before_forkafter_fork方法断开连接,然后在fork之后重新建立它。

然而,彪马没有那个。它只有on_worker_boot,在概念上类似于after_fork方法。

Puma是否也利用工人流程的分支?在像Unicorn这样的分叉之前是否需要断开连接?

谢谢!

示例文件

配置/ 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

配置/ 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

1 个答案:

答案 0 :(得分:3)

事实上,它现在具有此功能:https://github.com/puma/puma/pull/754