为什么 puma 没有像 Unicorn 那样的 `before_fork` 方法?
Why does puma not have a `before_fork` method like Unicorn?
我刚开始与 Puma 合作,之前曾与 Unicorn 合作过。
Unicorn 配置有一个 before_fork
和 after_fork
断开连接然后在分叉后重新建立连接的方法。
但是,Puma 没有。它只有 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
事实上,它现在有这个功能:https://github.com/puma/puma/pull/754
我刚开始与 Puma 合作,之前曾与 Unicorn 合作过。
Unicorn 配置有一个 before_fork
和 after_fork
断开连接然后在分叉后重新建立连接的方法。
但是,Puma 没有。它只有 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
事实上,它现在有这个功能:https://github.com/puma/puma/pull/754