简体   繁体   English

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

[英]Why does puma not have a `before_fork` method like Unicorn?

I'm new to working with Puma and have previously worked with Unicorn. 我刚接触Puma,之前曾在Unicorn工作过。

The Unicorn config has a before_fork and after_fork method that disconnects the connection and then restablishes it after the fork. Unicorn配置有一个before_forkafter_fork方法断开连接,然后在fork之后重新建立连接。

However, Puma doesn't have that. 然而,彪马没有那个。 It only has on_worker_boot which is conceptually similar to the after_fork method. 它只有on_worker_boot ,它在概念上类似于after_fork方法。

Doesn't Puma utilize forking of worker processes as well? Puma是否也利用工人流程的分支? Doesn't it need to disconnect before forking like Unicorn? 在像Unicorn这样的分叉之前是否需要断开连接?

Thanks! 谢谢!

Example files 示例文件

config/unicorn.rb 配置/ 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 配置/ 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

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM