LoginSignup
2

More than 5 years have passed since last update.

posted at

HerokuのデプロイしたRailsアプリにPumaを導入してみる

Pumaとは

スレッドベースで動作することにより並列処理を行ってくれるWebサーバです。

Pumaのインストール

Gemfile
gem 'puma'

Procfile

Procfile
web: bundle exec puma -C config/puma.rb

pumaの設定

config/puma.rb
workers Integer(ENV['WEB_CONCURRENCY'] || 2)
threads_count = Integer(ENV['RAILS_MAX_THREADS'] || 5)
threads threads_count, threads_count

preload_app!

rackup      DefaultRackup
port        ENV['PORT']     || 3000
environment ENV['RACK_ENV'] || 'development'

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

Worker数

dynoの一つにつきworkerを増やせるかはメモリ使用量によるがfree, hobby,standard-1xのプランだと2-4が目安とのこと。
可能なメモリの上限を超えた時に生じるR14 errorsを監視して設定することをオススメします。

Threads数

thread数の上限と下限を設定できるが、heroku的には同じ値を設定するのがお勧めとのこと。

参考サイト

Deploying Rails Applications with the Puma Web Server

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
What you can do with signing up
2