Ruby Default Web Server

If you don’t specify a Procfile, the default web server will be used. That means bundle exec rackup for Rack and rails server for Rails.

Depending on the version of these libraries you are using and what gems you have in your Gemfile, the WEBrick server may be used to run your production application.

Even if your application does not use WEBrick, it is HIGHLY recommended you do not rely on this implicit behavior and instead explicitly declare how you want your webserver started via a Procfile. If you don’t have a preference we recommend using Puma as a web server (see below).

We don’t recommend to use WEBrick in production.

Install Puma as Web Server

Puma uses ressources efficiently and avoid a lot of bottlenecks while running your Ruby application.

To install start by adding it inside your Gemfile:

gem 'puma'

Set Puma as your web server inside your Procfile :

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

Note: you can also add variables inside the Procfile like -e ${RACK_ENV:-development}

Create a configuration file for Puma at config/puma.rb or at a path of your choosing. For a simple Rails application, we recommend the following basic configuration:

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'] || 'production'

on_worker_boot do
  # Worker specific setup for Rails 4.1+
  ActiveRecord::Base.establish_connection
end

Make sure that your app uses the port 3000 OR update the env variable PORT to the port used by your application inside your app settings page!

You can create an ENV Variable inside your app settings with the WEB_CONCURRENCY and adapts its value depending on your app size. For Free apps we don’t recommend more than 2-4 conccurent threads. Monitor your app ressources usages while increasing this parameter as needed.

The Environment variable RACK_ENV can be added to your app settings to choose between development and production (default to production)

Was this helpful?

0 / 0