diff --git a/Gemfile b/Gemfile index 8aaef71..df7efe6 100644 --- a/Gemfile +++ b/Gemfile @@ -28,6 +28,8 @@ gem 'rollbar', '~> 2.5.0' gem 'gcm' gem 'newrelic_rpm' +gem 'puma' +gem "rack-timeout" # Use ActiveModel has_secure_password # gem 'bcrypt', '~> 3.1.7' diff --git a/Gemfile.lock b/Gemfile.lock index c9adc09..3a806be 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -141,9 +141,11 @@ GEM pg (0.18.2) polyamorous (1.2.0) activerecord (>= 3.0) + puma (2.16.0) rack (1.6.4) rack-test (0.6.3) rack (>= 1.0) + rack-timeout (0.3.2) rails (4.2.4) actionmailer (= 4.2.4) actionpack (= 4.2.4) @@ -259,6 +261,8 @@ DEPENDENCIES jquery-rails newrelic_rpm pg + puma + rack-timeout rails (= 4.2.4) rollbar (~> 2.5.0) rspec-rails @@ -272,4 +276,4 @@ DEPENDENCIES web-console (~> 2.0) BUNDLED WITH - 1.10.6 + 1.11.2 diff --git a/Procfile b/Procfile new file mode 100644 index 0000000..528ca4b --- /dev/null +++ b/Procfile @@ -0,0 +1 @@ +web: bundle exec puma -C config/puma.rb \ No newline at end of file diff --git a/config/initializers/timeout.rb b/config/initializers/timeout.rb new file mode 100644 index 0000000..96f2461 --- /dev/null +++ b/config/initializers/timeout.rb @@ -0,0 +1 @@ +Rack::Timeout.timeout = 20 # seconds diff --git a/config/puma.rb b/config/puma.rb new file mode 100644 index 0000000..9fb4298 --- /dev/null +++ b/config/puma.rb @@ -0,0 +1,23 @@ +#Please read the following before making any changes +#1. https://devcenter.heroku.com/articles/deploying-rails-applications-with-the-puma-web-server +#2. https://devcenter.heroku.com/articles/concurrency-and-database-connections#threaded-servers + +workers Integer(ENV['WEB_CONCURRENCY'] || 2) +threads_count = Integer(ENV['MAX_THREADS'] || 1) +threads threads_count, threads_count + +preload_app! + +rackup DefaultRackup +port ENV['PORT'] || 3000 +environment ENV['RACK_ENV'] || 'development' + +on_worker_boot do + # Valid on Rails up to 4.1 the initializer method of setting `pool` size + ActiveSupport.on_load(:active_record) do + config = ActiveRecord::Base.configurations[Rails.env] || + Rails.application.config.database_configuration[Rails.env] + config['pool'] = ENV['DB_POOL'] || 5 + ActiveRecord::Base.establish_connection(config) + end +end