How to Write a Procfile to Use Ruby on Rails 5 on Heroku's Free Tier
I’ll introduce how to write a Procfile to use Ruby on Rails 5 applications on Heroku’s free tier.
This mainly covers the options specified when starting the puma server.
The Procfile configuration for using Ruby on Rails applications on Heroku’s free tier is described in the following official documentation:
Procfile
web: bundle exec puma -t 5:5 -p ${PORT:-3000} -e ${RACK_ENV:-development}
The puma server is started with the bundle exec command using the following options:
Let’s check the content of each option.
The -t (or —threads) option specifies the minimum and maximum number of threads for the puma server to handle parallel request processing.
puma -h
puma
-t, --threads INT min:max threads to use (default 0:16)
In the Heroku official documentation, both minimum and maximum are set to 5 threads, but since only one web dyno is running, it fits within Heroku’s free tier.
The -p (or —port) option uses the PORT environment variable value as the port number if the PORT environment variable is defined.
If there’s no PORT value, it specifies port 3000 for startup.
puma -h
puma
-p, --port PORT Define the TCP port to bind to
The -environment ${RACK_ENV:-development} option starts the puma server in the RACK_ENV mode if the RACK_ENV environment variable is defined.
If there’s no RACK_ENV value, it starts in development mode. By the way, puma’s default behavior is also development mode.
puma -h
puma
-e, --environment ENVIRONMENT The environment to run the Rack app on (default development)
The key point of this article was that 5 threads are running but only one Dyno is started, so it fits within Heroku’s free tier.
That’s all from the Gemba.