Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Keep Heroku Free!

Keep Heroku Free!

Heroku makes it easy to spin up a free new Rails application. The hard part is keeping it free! Here are a few tips and tricks to help you keep Heroku free for as long as possible.

Steve Richert

August 04, 2014
Tweet

More Decks by Steve Richert

Other Decks in Programming

Transcript

  1. collectiveidea.com # config/unicorn.rb ! worker_processes Integer(ENV["WEB_CONCURRENCY"] || 3) timeout 15

    preload_app true ! before_fork do |server, worker| Signal.trap "TERM" do puts "Unicorn master receiving TERM and sending QUIT instead" Process.kill "QUIT", Process.pid end ! if defined? ActiveRecord::Base ActiveRecord::Base.connection.disconnect! end end ! after_fork do |server, worker| Signal.trap "TERM" do puts "Unicorn worker receiving TERM but waiting for master to send QUIT" end ! if defined? ActiveRecord::Base ActiveRecord::Base.establish_connection end end
  2. collectiveidea.com # config/puma.rb ! workers Integer(ENV["PUMA_WORKERS"] || 3) threads Integer(ENV["MIN_THREADS"]

    || 1), Integer(ENV["MAX_THREADS"] || 16) ! preload_app! ! rackup DefaultRackup port ENV["PORT"] || 3000 environment ENV["RACK_ENV"] || "development" ! on_worker_boot do ActiveSupport.on_load(:active_record) do config = ActiveRecord::Base.configurations[Rails.env] || Rails.application.config.database_configuration[Rails.env] config["pool"] = ENV["MAX_THREADS"] || 16 ActiveRecord::Base.establish_connection(config) end end
  3. collectiveidea.com # app/controllers/users_controller.rb ! def create @user = User.new(params[:user]) !

    if @user.save Notifier.welcome(@user).deliver redirect_to @user else render :new end end
  4. collectiveidea.com # app/controllers/users_controller.rb ! def create @user = User.new(params[:user]) !

    if @user.save WelcomeJob.new.async.perform(@user) redirect_to @user else render :new end end
  5. collectiveidea.com Links • bit.ly/free-heroku-slides • bit.ly/free-heroku-blog-post • bit.ly/free-heroku-unicorn • bit.ly/free-heroku-puma

    • bit.ly/free-heroku-sucker-punch • bit.ly/free-heroku-cloudfront • mandrill.com • newrelic.com