Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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!

Example files

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
like image 263
user2490003 Avatar asked Oct 20 '22 02:10

user2490003


1 Answers

In fact, it now has this feature: https://github.com/puma/puma/pull/754

like image 149
michael Avatar answered Oct 21 '22 22:10

michael