Change web server from WEBrick to Puma
Submitted about 4 years Ago
Why not WEBrick
By default WEBrick is single threaded, single process. This means that if two requests come in at the same time, the second must wait for the first to finish. In production, this will likely cause requests take a long time, even timeout.
Change to Puma
Heroku curently recommend using the Puma web server in production. Puma is a webserver that competes with Unicorn and allow you to process concurrent requests.
Adding Puma to rails application
First, add Puma to Gemfile
Create a file named "Procfile" in the root directory of your Rails application,make sure the
Procfile is properly capitalized and checked into git.Then add the following to the
web: bundle exec puma -C config/puma.rb
config/puma.rb is the path of the config file.
Create a config file for Puma at
config/puma.rb or at the path you set in the
Procfile. Here, I followed Heroku's recommendation for a simple Rails application:
workers Integer(ENV['WEB_CONCURRENCY'] || 2) threads_count = Integer(ENV['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
git add . git commit -am"change webserver from WEBrick to Puma" git push heroku