I'm new to working with Puma and have previously worked with Unicorn.
The Unicorn config has a before_fork
and after_fork
method that disconnects the connection and then restablishes it after the fork.
However, Puma doesn't have that. It only has on_worker_boot
which is conceptually similar to the after_fork
method.
Doesn't Puma utilize forking of worker processes as well? Doesn't it need to disconnect before forking like Unicorn?
Thanks!
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
In fact, it now has this feature: https://github.com/puma/puma/pull/754
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With