mri_puma.rb 982 B

12345678910111213141516171819202122232425262728
  1. require_relative 'auto_tune'
  2. # FWBM only... use the puma_auto_tune gem in production!
  3. num_workers, num_threads = auto_tune
  4. workers num_workers
  5. threads num_threads, num_threads
  6. preload_app!
  7. # If you are preloading your application and using Active Record, it's
  8. # recommended that you close any connections to the database before workers
  9. # are forked to prevent connection leakage.
  10. #
  11. before_fork do
  12. ActiveRecord::Base.connection_pool.disconnect! if defined?(ActiveRecord)
  13. end
  14. # The code in the `on_worker_boot` will be called if you are using
  15. # clustered mode by specifying a number of `workers`. After each worker
  16. # process is booted, this block will be run. If you are using the `preload_app!`
  17. # option, you will want to use this block to reconnect to any threads
  18. # or connections that may have been created at application boot, as Ruby
  19. # cannot share connections between processes.
  20. #
  21. on_worker_boot do
  22. ActiveRecord::Base.establish_connection if defined?(ActiveRecord)
  23. end